Public Group

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

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

 //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 on other sites
am i doing something too crazy here?

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631777
• Total Posts
3002306
×