# shadow mapping for directional lights, strange artefacts

This topic is 3756 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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);
}


void VShaderDirectional(in VertexShaderIn In, out VertexShaderOut1 Out)
{
Out.Position = mul(In.Position, WorldViewProjMatrix);

// transforming lightdirection to tangentspace

Out.Tex0 = In.Tex0;
}

{

float4 Color = (float4)0;

{
// 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.

##### Share on other sites
Just looks like a biasing problem to me. As you already noted adding a bias should help. You can also try rendering only back-faces into the shadow map, that should help with biasing.

##### Share on other sites
Thanks for the quick reply. But adding enough bias to make the stripes completely disappear will result in a shadow looking like this:

Geometry to close to the floor won't cast shadows anymore. Drawing only backfaces into the shadowmap will even worsen the problem since they are generally closer to the floor.

The strange thing is, even without any bias at all there is no z-fighting or shadow acne, just clear stripes on the floor.

##### Share on other sites
Check your shadow-buffer depth - if you have fallen back to an 8-bit buffer, these stripes can occur.

##### Share on other sites
Thank you so much. You just made my day!
I was using an 24 Bit depth-buffer, but didn't consider that I store the depth in one of the textures 8-Bit color channels...

##### Share on other sites
Quote:
 Original post by DraganOThank you so much. You just made my day!I was using an 24 Bit depth-buffer, but didn't consider that I store the depth in one of the textures 8-Bit color channels...
No problem - the same thing happened to me about a week ago :)

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 12
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632991
• Total Posts
3009752
• ### Who's Online (See full list)

There are no registered users currently online

×