Richy
2008-06-16 01:43:57 UTC
I have implemented deferred lighting succesfully but I am having an
issue with shadow mapping. In my deferred rendering's material pass I
output the world position xyz and the transformed z/w in the alpha,
and then in my deferred shader that handles the shadows, I read the
world position in for the pixel being processed, transform it to the
light's point of view, and map this to the shadow map texture to get
the depth at that point from the light's point of view. A typical
shadow mapping technique. My shadows appear but there are lots of
visual glitches that I've never had in the past (when I was not using
deferred shading). For example, when I move the camera towards a crate
that is casting a shadow on the ground, the shadow does not stay fixed
but moves, and always stays ahead of the camera. When rotating the
camera's pov, shadows slice in and out. I can't explain why, here is
my code:
float lit;
float4 worldPosition = texDepth.Sample(g_samPoint, input.texcoord);
if(lightCastsShadows)
{
float4 wpc = mul(float4(worldPosition.xyz, 1.0f),
l_viewProjectionMatrix);
// convert screen coordinates to texture coordinates (0 to 1)
wpc.x = 0.5f * (wpc.x/wpc.w) + 0.5f;
wpc.y =-0.5f * (wpc.y/wpc.w) + 0.5f;
float lightDepth = texShadowMap.Sample(g_samShadow, wpc.xy);
float screenDepth = worldPosition.a;
if((saturate(wpc.x)==wpc.x) && (saturate(wpc.y)==wpc.y))
{
if(screenDepth > lightDepth)
{
lit= 0.0f;
}
else
{
lit= 1.0f;
};
}
else
{
lit=0.0f;
};
};
return lit;
Has anybody else encountered an issue like this when combining shadow
mapping with deferred lighting? Any pointers would be appreciated, I'm
getting bogged down on this and it's driving me nuts. Aaarrrggh!
Richy
issue with shadow mapping. In my deferred rendering's material pass I
output the world position xyz and the transformed z/w in the alpha,
and then in my deferred shader that handles the shadows, I read the
world position in for the pixel being processed, transform it to the
light's point of view, and map this to the shadow map texture to get
the depth at that point from the light's point of view. A typical
shadow mapping technique. My shadows appear but there are lots of
visual glitches that I've never had in the past (when I was not using
deferred shading). For example, when I move the camera towards a crate
that is casting a shadow on the ground, the shadow does not stay fixed
but moves, and always stays ahead of the camera. When rotating the
camera's pov, shadows slice in and out. I can't explain why, here is
my code:
float lit;
float4 worldPosition = texDepth.Sample(g_samPoint, input.texcoord);
if(lightCastsShadows)
{
float4 wpc = mul(float4(worldPosition.xyz, 1.0f),
l_viewProjectionMatrix);
// convert screen coordinates to texture coordinates (0 to 1)
wpc.x = 0.5f * (wpc.x/wpc.w) + 0.5f;
wpc.y =-0.5f * (wpc.y/wpc.w) + 0.5f;
float lightDepth = texShadowMap.Sample(g_samShadow, wpc.xy);
float screenDepth = worldPosition.a;
if((saturate(wpc.x)==wpc.x) && (saturate(wpc.y)==wpc.y))
{
if(screenDepth > lightDepth)
{
lit= 0.0f;
}
else
{
lit= 1.0f;
};
}
else
{
lit=0.0f;
};
};
return lit;
Has anybody else encountered an issue like this when combining shadow
mapping with deferred lighting? Any pointers would be appreciated, I'm
getting bogged down on this and it's driving me nuts. Aaarrrggh!
Richy