Hi,
I have a problem with my shadow mapping for directional lights and just can't find a way to solve it. I've already implemented shadow mapping for spotlights and it works fine, but my directional light causes some very strange artefacts. But they don't seem to be usual shadow acne, but (i guess) some kind of discontinuity in the z-distribution since i can get rid of the black stripes by adding enough offset to the shadowmap. But this pushes the parts between the stripes so far away that geometry very close to the floor doesn't cast any shadow anymore. Also the stripes appear to get broader the further away they are from the lightsource.
I'm setting up the camera and projection matrices by hand but they seem to be correct because creating the matrices using DirectX functions produces the same results. You can also see the shadowmap in the upper left corner of the screenshot and it also seems to be correct. So i assume my shaders for rendering the final scene must be wrong.
Some code:
Shader for rendering to the shadowmap:
void VRenderToShadowmap(in VertexShaderIn In, out VertexShaderOut Out)
{
Out.Position = mul(In.Position, WorldViewProjMatrix);
Out.Depth = Out.Position.z + 0.001f;
}
float4 PShader(float Depth : TEXCOORD0) : COLOR
{
return float4(Depth, Depth, Depth, 1.0f);
}
Shader that render scene (simplified):
void VShaderDirectional(in VertexShaderIn In, out VertexShaderOut1 Out)
{
Out.Position = mul(In.Position, WorldViewProjMatrix);
Out.ShadowMapCoords = mul(In.Position, LightWorldViewProjMatrix);
Out.ShadowMapCoords.xy *= float2(0.5f, -0.5f);
Out.ShadowMapCoords.xy += 0.5f;
// transforming lightdirection to tangentspace
Out.Tex0 = In.Tex0;
}
float4 NormalMappingPShaderDirectional(in VertexShaderOut1 In) : COLOR
{
clip(In.ShadowMapCoords.xyz);
clip(1.0f - In.ShadowMapCoords.xyz);
float Depth = tex2D(Shadowmap, In.ShadowMapCoords.xy).z;
float4 Color = (float4)0;
if(In.ShadowMapCoords.z <= Depth)
{
// lighting...
}
else
{
clip(-1);
}
return Color;
}
I hope someone has encountered a similar/the same problem and can help me.
Thanks in advance for your time and help.