# Linearized shadow map depth (solved)

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

## 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 on other sites
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 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 on other sites
Thanks a lot you two, seems to work just fine!

##### Share on other sites

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

## 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

• ### Forum Statistics

• Total Topics
628633
• Total Posts
2983957

• 10
• 18
• 20
• 13
• 9