Deferred shadow mapping using the hw-depth?

Started by
-1 comments, last by lipsryme 11 years, 5 months ago
I was thinking if I already have a depth buffer of my camera. Is it not possible to transform this depth to the light's projection space somehow ?
Is there a way to do this ? Or do I still need to render the entire geometry again for shadows ?
I imagine I could retrieve the world position of the vertices somehow and then transform them again with my light's view projection matrix...but is there no easier/faster way?

I've tried something like:



float LinearDepth(in float zw)
{
return Projection._43 / (zw - Projection._33) / farClip;
}



VSO VS(VSI input)
{
VSO output = (VSO)0;
output.Position = float4(input.Position.xy, 1.0f, 1.0f);
output.UV = input.UV;
float3 ViewPosition = mul(float4(input.Position.xyz, 1.0f), InvProjection);
output.ViewRay = float3(ViewPosition.xy / ViewPosition.z, 1.0f);
return output;
}

float4 PS(VSO input) : SV_TARGET0
{
float4 output = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 ViewRay = normalize(input.ViewRay);
float depth = DepthBuffer.Sample(PointSampler, input.UV).r;
depth = LinearDepth(depth);
float ViewZDist = dot(CamTarget, ViewRay);
float3 worldPos = CamPosition + ViewRay * (depth / ViewZDist);

// Construct view matrix of light
float4x4 LightViewMatrix = CreateLightViewMatrix();
float4x4 LightProjMatrix = CreateLightProjMatrix();
float4 LightPosition = mul(float4(worldPos, 1.0f), LightViewMatrix);
LightPosition = mul(LightPosition, LightProjMatrix);
return LightPosition.z;
}




update: yea I've figured out that it's not possible to do :P..too bad

This topic is closed to new replies.

Advertisement