• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

# Deferred shadow mapping using the hw-depth?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1lipsryme  Members

Posted 17 November 2012 - 05:12 PM

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 ..too bad

Edited by lipsryme, 20 November 2012 - 08:24 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.