Jump to content
  • Advertisement
Sign in to follow this  

projecting shadow map, with deferred depth reconstruction.

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


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

//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;

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.

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

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

float4 lightingPosition = mul(position3D, LightsWorldViewProjection);

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!