Jump to content
  • Advertisement
Sign in to follow this  
DraganO

shadow mapping for directional lights, strange artefacts

This topic is 3690 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

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. Screenshot 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.

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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:

Screenshot

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by DraganO
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...
No problem - the same thing happened to me about a week ago :)

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!