How it is possible to get rid of spurious artifacts of Shadow Mapping?

Spurious artifacts in case of creation of shadows through shadow mapping.hahaha

I can't understand why many shadows are drawn, and from where they originate? example: example

Upvotes: 0

Views: 194

Answers (3)

agnu17
agnu17

Reputation: 398

Make sure that the farplane of the shadow camera is high enough!

Upvotes: 0

user3529622
user3529622

Reputation:

It looks like your shadow map is covering only a fraction of the scene, and is being tiled (repeated) to cover the rest. Change the wrapping mode for the shadow map to GL_CLAMP_TO_BORDER:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

And set your border color to 1.0f or 0.0f, depending on whether you want things outside the shadow map to be lit or unlit:

GLfloat borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);

Upvotes: 2

agnu17
agnu17

Reputation: 398

I think you mean shadow acne. when you are rendering a litten surface, you calculate the surface point's distance from the light, and compare it with the distance read from the shadow map. Now ideally these should be equal if the surface is lit, but due to float precision errors there may be slight inaccuracies resulting in shadows where there shouldnt be any.

Solution is to apply an offset, so add a small number like 0.001 to the distance you read from the shadow map. The actual offset should be dependant on the world's scale.

Upvotes: 0

Related Questions