Jump to content
  • Advertisement
Sign in to follow this  
Jason Z

Linearizing Shadow Map Depth???

This topic is 4638 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 recently started adding shadow maps to my engine and have finally managed to get a decent sample running. Of course, once a new algorithm is implemented, it is just natural to try to improve what you have done. So I was reading in 'Programming Vertex and Pixel Shaders' by Wolfgang Engel, and he suggests linearizing the depth values in the shadow map by applying the following change to the homogenous projection space z value (this is described on p.293 for those with the book): Zout = (Zin + near)/(far - near) This would be intended to add a smooth distribution of depth values across the depth map range. I tried this and had absolutely no luck at all. The shadow map came out looking like I had not rendered anything at all into it. Does anyone know of a similar technique for linearizing the depth or perhaps a correction to his algorithm? Thanks in advance for any help!

Share this post


Link to post
Share on other sites
Advertisement
Assuming Zin is between Znear and Zfar, wouldn't you want:

Zout = (Zin - Znear) / (Zfar - Znear)?

Otherwise Zout could be > 1, which would get clamped.

Share this post


Link to post
Share on other sites
Here's a link you might find interesting: http://www.mvps.org/directx/articles/linear_z/linearz.htm

Cheers, Altair

Share this post


Link to post
Share on other sites
Thanks for the replies.

AndyTX: Your suggestion was correct, it must have been a misprint in the book.
AltairX: Thanks for the link, that helps firm up what is really going on.

The shadow maps look much better now, and I can actually view them and see the objects so the depth values are certainly linearized. Thanks again!

Share this post


Link to post
Share on other sites
Raises hand…

The depth is linearized only in the vertex shader of the light? Right?

What are zOut and zIn? Are these the z values of the vertex positions before or after multiplying by the modelviewprojectionmatrix (worldviewporjection)?

I’m assuming znear and zfar are the lights parameters…Right?


Thanks…

Share this post


Link to post
Share on other sites
Quote:
Original post by BlackBox
Raises hand…

The depth is linearized only in the vertex shader of the light? Right?

I am doing it in the vertex shader, but I suppose it could be done in the pixel shader as well.
Quote:
What are zOut and zIn? Are these the z values of the vertex positions before or after multiplying by the modelviewprojectionmatrix (worldviewporjection)?
Zin is the z value after transforming into clip (or projection) space, so after the worldviewprojection.

Quote:
I’m assuming znear and zfar are the lights parameters…Right?
Yep, they are the near and far planes of the spot light's frustum. Sorry I wasn't more specific the first time.


Share this post


Link to post
Share on other sites
Quote:
Original post by Jason Z
Quote:
Original post by BlackBox
Raises hand…

The depth is linearized only in the vertex shader of the light? Right?

I am doing it in the vertex shader, but I suppose it could be done in the pixel shader as well.
Quote:
What are zOut and zIn? Are these the z values of the vertex positions before or after multiplying by the modelviewprojectionmatrix (worldviewporjection)?
Zin is the z value after transforming into clip (or projection) space, so after the worldviewprojection.

Quote:
I’m assuming znear and zfar are the lights parameters…Right?
Yep, they are the near and far planes of the spot light's frustum. Sorry I wasn't more specific the first time.


Great thanks. Full marks for you! :)

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!