Jump to content
  • Advertisement
Sign in to follow this  
Gowerlypuff

OpenGL Shadows in D3D in too many complicated steps

This topic is 5019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I remember doing shadows in OpenGL and they were reasonably easy to Render, but in D3D they're a nightmare. I'm a relative newbie to the whole D3D coding thing (it's part of my course) and I've made a scene, it's got a cube and a board and some lights and it's all pretty and I was really pleased with myself, so I thought "I know, it looks silly with the light just going THROUGH my mesh onto the thing behind it, I'll add some shadows". 3 days later and my head has exploded. I've had a scout around the internet and looked at things on the mechanics of shadow volumes and stuff, so I know HOW they work, but I don't see how you get them to work in code. It seems that I: Render the scene without lighting. Calculate the projection and/or volume of the shadows using Depth-Pass (or Fail, depending on how masochistic I'm feeling). Re-render the scene with shadows (twice?) I have some code: Here Any pointers (sorry, that was awful) would be much appreciated. [edit] there's no bb code.

Share this post


Link to post
Share on other sites
Advertisement
Have you looked at the ShadowMap and ShadowVolume samples in the Summer Update 2004 SDK? They demonstrate precisely how to do this. Also, make sure you read the whitepapers that come along with the samples - they can be *very* helpful and informative.

Share this post


Link to post
Share on other sites
Thanks, I'll give that another look.
The .cpp that came with the summer update (I haven't got the october update, yet) don't actually compile, which is somewhat unnerving, but I'll look at the stuff that comes with it. The code itself was a little confusing. I tried integrating it with my program, but it died a horrible death. I think most of my problem is that I can't see where the code in the samples would fit with the code I have. Perhaps I shouldn't have used a mesh.

Share this post


Link to post
Share on other sites
What compiler errors are you getting, and which compiler are you using?

It would definetly be helpful to get the latest SDK. For one, the samples themselves are a lot cleaner, and easier to understand. Also, they come along with those whitepapers that I mentioned.

Share this post


Link to post
Share on other sites
Yeah, I saw that a bit too late there, sorry.

So, looking through a bunch of stuff, I found the thing on GameDev.net which seemed to be the most helpful.


//colour buffer OFF
pDev->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pDev->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
pDev->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );
//lighting OFF
pDev->SetRenderState( D3DRS_LIGHTING, FALSE );
//depth buffer ON (write+test)
pDev->SetRenderState( D3DRS_ZENABLE, TRUE );
pDev->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
//stencil buffer OFF
pDev->SetRenderState( D3DRS_STENCILENABLE, FALSE );

//FIRST PASS: render scene to the depth buffer
for ( int i = 0; i < 8; i++ ) {
mshCaster->Render( pDev );
}



Looking at this, obviously I need to change pDev to Device, but it's the pass thing that's confusing me. I understand that I will have to render the entire scene, but obviously my mesh vertices do not have the Render overload in them, as they're just FVF's. What does that bit actually mean?

Share this post


Link to post
Share on other sites
Well, I've had another play and, as I don't think people would appreciate 26k of code surrounded by tags, I'll link to it again.

Source

I'm doing something wrong. I've got precisely the same thing drawn, although this time it's much much slower as it does all these shiny new shadow calculations and then ignores them.

I think what I'm doing wrong involves drawing the front and back faces. In the sample, it had an index to do it. In mine I'm just drawing the whole thing with different culling. I think this may have something to do with it. I'm a bit flummoxed as to what I should put there instead.

Share this post


Link to post
Share on other sites
So, I've been having more of a play. I tried using the 2-sided version so that I only needed one pass, but this didn't help. With that I just got a screen of black, which was nice.

Other than that, I'm still having the same problem. I'm really at a loss as to what it is I'm doing wrong, other than it's in the bit where I'm doing the two-pass rendering.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!