View Full Version : ShadowMapping artifacts

10-22-2013, 10:59 AM
Hello everyone,
I'm trying to implement shadowmapping in my project, however it causes weird artifacts. This is how it looks:

( I cannot post full link, cause of forum rules...sorry)

I'm using ortographic projection with projection matrix boundaries set to (-50, 50, -40, 40, -40, 40) and depth texture is 2048x1200 pixels large.

This is part of fragment shader that handles shadows:

float theta = clamp(dot(normalize(lightVector), normalize(vertNormal)), 0, 1);
float bias = 0.005*tan(acos(theta));
float visibility = 1.0;
if ( shadow2D(shadowTex, shadowCoord).z < shadowCoord.z - bias){
visibility = 0.5;
color = vec4(color.xyz * visibility, 1);

Dark Photon
10-22-2013, 07:04 PM
Which ones. The apparent shadows cast by the grid points/lines? If so, don't cast those into the shadow map. If you're not casting those, than you might a different bias.

10-23-2013, 02:50 AM
Yea, I mean those shadows between grid lines. They're in the same height level, so it shouldn't cast any shadows. I've tried changing bias, but it disappears only if it's too high - close to 1, which makes whole shadowmapping useless.
EDIT: when I use texture2D with sampler2D, there are no artifacts

10-23-2013, 12:49 PM
if ( shadow2D(shadowTex, shadowCoord).z < shadowCoord.z - bias){

When using a shadow sampler, the implementation compares the depth value in the texture against the third component of the texture coordinate, and returns the result of the comparison.

The result of shadow2D() is 0 or 1 depending upon whether the comparison passes or fails (an implementation may use filtering, performing the comparison for a 2x2 texel neighbourhood and returning a value between 0 and 1 if the test passes for some of the samples and fails for others).

If you want to perform the depth comparison yourself, you should use a sampler2D rather than a sampler2DShadow, and texture2D() (or just texture()) rather than shadow2D(). Also, GL_TEXTURE_COMPARE_MODE needs to be GL_NONE. Then, the result of texture2D() will be the actual depth value from the texture.