Shadows in D3D in too many complicated steps

Started by
7 comments, last by Gowerlypuff 19 years, 6 months ago
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.
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.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
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.
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.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Quote:Original post by Gowerlypuff
[edit] there's no bb code.

GDNet formatting tags are here: GDNet Forums FAQ
You need the [source][/source] tags.

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 OFFpDev->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );pDev->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );pDev->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );//lighting OFFpDev->SetRenderState( D3DRS_LIGHTING, FALSE );//depth buffer ON (write+test)pDev->SetRenderState( D3DRS_ZENABLE, TRUE );pDev->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );//stencil buffer OFFpDev->SetRenderState( D3DRS_STENCILENABLE, FALSE );//FIRST PASS: render scene to the depth bufferfor ( 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?
it just means "draw your meshes here."
_______________________________________________________________________Hoo-rah.
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.
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.

This topic is closed to new replies.

Advertisement