Sign in to follow this  
Jason Z

Linearizing Shadow Map Depth???

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this