basic shadow mapping - removing artifacts
I implemented a basic shadow mapping. I have a scene illuminated by one directional light.
I use an orthographic projection:
(glm::ortho(-70.0f, 70.0f, -50.0f, 90.0f, -50.0f, 100.0f));
which is sufficient to cover the scene from the light point of view. LightViewMatrix looks like this:
glm::lookAt(glm::normalize(glm::vec3(0.0f, 1.0f, 1.0f)), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
Here are parameters for a depth texture:
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
In a shader I use sampler2Dshadow so I get a basic PCF filter.
I removed an ambient light and artifacts are more visible. First I used front face culling during saving depth values. That removed artifacts
from the illuminated part of the object, but then I got many artifacts in the shadow.
Next I set glPolygonOffset(4.0f, 20.0f) during saving depth values instead of the front
face culling and I got better results but some artifacts were still visible in the shadow:
and in the light:
I read that glPolygonOffset gives better results than using a constant bias in the shader because
it takes into account a polygon slope.
1. Is it possible to calculate a dynamic bias in the shader which gives better results than glPolygonOffset ? (How to do it ? )
2. Is something what I can do better to remove artifacts using only the basic shadow mapping concept or the only way is using more advanced techniques such as cascaded shadow mapping etc. ?