Sign in to follow this  
winsrp

projecting shadow map, with deferred depth reconstruction.

Recommended Posts

So,

I have my PS, were it takes the depth buffer (z/w), and I'm trying to project a shadow map from a directional light which has an Orthographic projection.

So to reconstruct the positions from the depth buffer I use

[CODE]
//compute screen-space position
float4 position3D;
position3D.x = input.TexCoord.x * 2.0f - 1.0f;
position3D.y = (1.0f - input.TexCoord.x ) * 2.0f - 1.0f;
position3D.z = depthVal;
position3D.w = 1.0f;
//transform to world space
float4 position = mul(position3D, InvertViewProjection);
position /= position.w;
[/CODE]

That's good for the normal camera and other calculations I have in the PS, but now I need to transform the position to the view of the directional light so I can test for shadow projection.

So I figured I would just do this and it would work.

[CODE]
float4 lightingPosition = mul(position3D, InvertLightsWorldViewProjection);
lightingPosition /= lightingPosition.w;
[/CODE]

but then I figured out that since the w is always 1, this would not work as my position3D is still not the real screen space position. But when I transform my position3D into position I'm looking at the view coordinate from my main camera. So my guess is that I need to reverse the view coordinates from my main camera into real screen coordinates so I can perform a normal conversion of coordinates with something like

[CODE]float4 lightingPosition = mul(position3D, LightsWorldViewProjection);[/CODE]

now 2 questions,

#1, am I understanding all this correctly??
#2, how can I achieve what I need?? or a better way to do it.? Edited by winsrp

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