Skip to main content
gamedev.net
🔒 Locked

Linearizing Shadow Map Depth???

Started by Jason Z Dec 3, 2005 at 9:18 PM 5 replies 3.5k views
Original Post
Jason Z
Jason Z
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!
Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
AndyTX
AndyTX
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.
AltairX
AltairX
Here's a link you might find interesting: http://www.mvps.org/directx/articles/linear_z/linearz.htm

Cheers, Altair
Jason Z
Jason Z
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!
Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
BlackBox
BlackBox
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…

---------------------------- ^_^
Jason Z
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.


Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
BlackBox
BlackBox
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! :)
---------------------------- ^_^

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.