This topic is 4703 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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 on other sites
Here's a link you might find interesting: http://www.mvps.org/directx/articles/linear_z/linearz.htm

Cheers, Altair

##### 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 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 on other sites
Quote:
 Original post by BlackBoxRaises 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 on other sites
Quote:
Original post by Jason Z
Quote:
 Original post by BlackBoxRaises 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! :)

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 12
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632989
• Total Posts
3009743
• ### Who's Online (See full list)

There are no registered users currently online

×