• Advertisement
Sign in to follow this  

Linearized shadow map depth (solved)

This topic is 4088 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

Hi! I've recently implemented uniform shadow mapping and of course I've run into the kind of aliasing problems that you would expect. I don't think I'm ready for PSM yet, so I'm trying to overcome these problems (to some degree) with "conventional" methods. One thing that seems to make a lot of sense is to linearize the z-value when computing the light depth map, but I can't get it to work. From what I understand, it works like this:
Depth = Position.z * Position.w / FarClippingPlane;
Assuming that Position is the vertex position multiplied by the light's ViewProjection matrix and that the near clipping plane is at 0.0. I would then do the depth comparison like this
ShadowMapDepth = SampleFromShadowMap();
FragmentInLightSpace = FragmentPosition * LightViewProjection;
FragmentDepth = FragmentInLightSpace.z * FragmentInLightSpace.w / FarClippingPlane;
// Do the regular shadow test here
This gives me very weird results though where geometry appears in shadow when it should actually be fully lit. So could someone please enlighten me as how to do this properly? Thanks a lot in advance! [Edited by - Harry Hunt on December 12, 2006 2:49:59 AM]

Share this post


Link to post
Share on other sites
Advertisement
The easiest way to compute linear depth (IMHO) is something like:

VS:
...
float3 PosView = mul(Position, g_WorldViewMatrix).xyz;
...

PS:
...
float Depth = length(PosView);
...


Works quite well in my experience and is very high precision.

Share this post


Link to post
Share on other sites
Well the calculated depth is going to be in unit cube space (ie. [-1,1]) so you need to scale and bias that value to get it into [0,1] range.

For instance to get the value written to the depth buffer from the interpolator 'Position' you would:

float Depth = (Position.z / Position.w) * 0.5f + 0.5f;


Cheers,
Tom.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement