Sign in to follow this  
Harry Hunt

Linearized shadow map depth (solved)

Recommended Posts

Harry Hunt    542
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
AndyTX    806
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
hogwash    139
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

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