Sign in to follow this  
lipsryme

Deferred shadow mapping using the hw-depth?

Recommended Posts

lipsryme    1522
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:

[CODE]

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;
}
[/CODE]



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

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