Jump to content
  • Advertisement
Sign in to follow this  
wavetable

Porting XNA Shadow Mapping Example to C++ and DX10

This topic is 3633 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

hi all, i succesfully ported this example: http://creators.xna.com/en-US/sample/shadowmapping1 but i had to change the shadowTexCoord like this to get the same results as in the original version: shadowTexCoord -= 0.5f / SHADOWMAP_SIZE; but i don't understand why this is needed. i thought it may have to do with the texel/pixel alignment changes from DX9/10 and that maybe when rendering to a rendertarget and then using the rendertarget's texture as input to another shader there might be need for the halfPixel thing, but as i understand it (and the tests showed) there is no need for that in DX10 at all. i am completely confused, and would be very happy with any input. thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
You were correct, it's the texel/pixel alignment issue. I don't believe that sample accounts for the half-pixel offset, so the results are actually off by half a texel. For you to get the same exact results in DX10, you need to add the half-texel offset.

Share this post


Link to post
Share on other sites
thanks for your reply, but i still don't understand.

when rendering the shadow map: if the world position A goes into the shadow map
texel[0,0]

and then rendering the scene: the same world position A should be found at texel[0,0] again

but it is at texel[-halfShadowMapTexel.x, -halfShadowMapTexel.y]

is my understanding correct until here?
and if so where in these steps is the need for the halfTexel coming from?
because when i do this:

1) render a texture to rendertarget1
2) render rendertarget1 to screen

then i do not have to use halfTexel, so the writing and reading to/from rendertarget1 is aligned but writing/reading to shadow map is not?

sorry for being a pain, but this is making me crazy...


Share this post


Link to post
Share on other sites
Sorry I was mistaken, that sample does account for the half-texel offset. I'm not sure why you need the offset in your code then...

Share this post


Link to post
Share on other sites
Quote:
Original post by undead
http://msdn.microsoft.com/en-us/library/bb219690(VS.85).aspx

This should be helpful ;)


He's using DX10 though, where texels and screen coordinates aren't a half-unit apart.

Share this post


Link to post
Share on other sites
thanks, undead. i know this one but my working solution for DX10 looks like what this document says DX9 should look like. and the DX9 XNA example looks like DX10 but works with DX9...???

Share this post


Link to post
Share on other sites
Quote:
Original post by wavetable
where does the sample do it? i looked for it over and over again but found nothing.


Wow I must be having a bad morning...I was right the first time.

Okay so here's what happens:

-XNA shadow sample is wrong, it doesn't account for the half-texel offset.
-You make your implementation in DX10 without the offset, the results are correct but don't match the incorrect results of the XNA sample
-Adding the opposite offset to your DX10 implementation gives you the same (incorrect) results as the XNA sample.

Whew!

Share this post


Link to post
Share on other sites
hehe, good morning!

that's somehow good news, but the results from XNA look sooo correct and my DX10 results (the correct ones, as you said, without halfTexel) look soooo incorrect?

btw. i changed the XNA example so that it renders the gridModel into the shadow map, too.



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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!