   Linearizing Shadow Map Depth???
  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!   
  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.   ;  Here's a link you might find interesting: http://www.mvps.org/directx/articles/linear_z/linearz.htmCheers, Altair;  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!   ;  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…;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.;Quote:Original post by Jason ZQuote: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! :)   