Jump to content
  • Advertisement
Sign in to follow this  
lipsryme

Deferred shadow mapping using the hw-depth?

This topic is 2014 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 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 Edited by lipsryme

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!