• Create Account

Banner advertising on our site currently available from just \$5!

### #ActualKaiserJohan

Posted 14 April 2014 - 05:06 AM

Doing cascaded shadow mapping, and I need some confirmation I am doing the right thing. The shadow mapping works (mostly) but on a few angles the shadows vanish.

The sampler is setup like this:

GLCALL(glGenSamplers(1, &mTextureSampler));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));
GLCALL(glBindSampler(OpenGLTexture::TEXTURE_UNIT_SHADOW_DIRECTIONAL, mTextureSampler));

I do depth comparison rather than distance comparison; my depth textures thus contain depth values.

vec4 projCoords = UnifDirLightPass.mVPMatrix[index] * vec4(worldPos, 1.0);
projCoords.w    = projCoords.z - DEPTH_BIAS;
projCoords.z    = float(index);

float angleNormal = clamp(dot(normal, UnifDirLightPass.mLightDir.xyz), 0, 1);

fragColor = vec4(diffuse, 1.0) * visibilty * angleNormal * UnifDirLightPass.mLightColor;                                    

"unifShadowTexture" is of type "sampler2DarrayShadow", and "UnifDirLightPass.mVPMatrix[]" contains the bias * lightProj * lightView matrix for each split.

1. By having MIN/MAG filtering to GL_LINEAR, shouldn't I also have visibility = 0.5 for some samples? All I see is either 0.0 or 1.0.

2. Is the comparison in texture() valid? I believe I read somewhere that depth values aren't stored linearly, does this create a problem when I try to compare it against bias * lightProj * lightView * worldPosition?

3. For what reason would you use distance comparison (= writing the squared distance to the depth texture) over depth comparison for shadow mapping? It just seems like extra computations?

4. I am using shadow samplers, which gives me 0.0 or 1.0 values. How can I accomplish soft shadows with this for directional and point lights with such binary values to work with?

5. Why would you not use shadow samplers over normal samplers in shadow mapping?

Thanks

### #2KaiserJohan

Posted 14 April 2014 - 05:06 AM

Doing cascaded shadow mapping, and I need some confirmation I am doing the right thing. The shadow mapping works (mostly) but on a few angles the shadows vanish.

The sampler is setup like this:

GLCALL(glGenSamplers(1, &mTextureSampler));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));
GLCALL(glBindSampler(OpenGLTexture::TEXTURE_UNIT_SHADOW_DIRECTIONAL, mTextureSampler));

I do depth comparison rather than distance comparison; my depth textures thus contain depth values.

vec4 projCoords = UnifDirLightPass.mVPMatrix[index] * vec4(worldPos, 1.0);
projCoords.w    = projCoords.z - DEPTH_BIAS;
projCoords.z    = float(index);

float angleNormal = clamp(dot(normal, UnifDirLightPass.mLightDir.xyz), 0, 1);

fragColor = vec4(diffuse, 1.0) * visibilty * angleNormal * UnifDirLightPass.mLightColor;                                    

"unifShadowTexture" is of type "sampler2DarrayShadow", and "UnifDirLightPass.mVPMatrix[]" contains the bias * lightProj * lightView matrix for each split.

1. By having MIN/MAG filtering to GL_LINEAR, shouldn't I also have visibility = 0.5 for some samples? All I see is either 0.0 or 1.0.

2. Is the comparison in texture() valid? I believe I read somewhere that depth values aren't stored linearly, does this create a problem when I try to compare it against bias * lightProj * lightView * worldPosition?

3. For what reason would you use distance comparison (= writing the squared distance to the depth texture) over depth comparison for shadow mapping? It just seems like extra computations?

4. I am using shadow samplers, which gives me 0.0 or 1.0 values. How can I accomplish soft shadows with this for directional and point lights with such binary values to work with?

Thanks

### #1KaiserJohan

Posted 14 April 2014 - 04:59 AM

Doing cascaded shadow mapping, and I need some confirmation I am doing the right thing. The shadow mapping works (mostly) but on a few angles the shadows vanish.

The sampler is setup like this:

GLCALL(glGenSamplers(1, &mTextureSampler));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));
GLCALL(glBindSampler(OpenGLTexture::TEXTURE_UNIT_SHADOW_DIRECTIONAL, mTextureSampler));

I do depth comparison rather than distance comparison; my depth textures thus contain depth values.

vec4 projCoords = UnifDirLightPass.mVPMatrix[index] * vec4(worldPos, 1.0);
projCoords.w    = projCoords.z - DEPTH_BIAS;
projCoords.z    = float(index);

float angleNormal = clamp(dot(normal, UnifDirLightPass.mLightDir.xyz), 0, 1);

fragColor = vec4(diffuse, 1.0) * visibilty * angleNormal * UnifDirLightPass.mLightColor;                                    

"unifShadowTexture" is of type "sampler2DarrayShadow", and "UnifDirLightPass.mVPMatrix[]" contains the bias * lightProj * lightView matrix for each split.

1. By having MIN/MAG filtering to GL_LINEAR, shouldn't I also have visibility = 0.5 for some samples? All I see is either 0.0 or 1.0.

2. Is the comparison in texture() valid? I believe I read somewhere that depth values aren't stored linearly, does this create a problem when I try to compare it against bias * lightProj * lightView * worldPosition?

3. For what reason would you use distance comparison (= writing the squared distance to the depth texture) over depth comparison for shadow mapping? It just seems like extra computations?

4. I am using shadow samplers, which gives me 0.0 or 1.0 values. How can I accomplish soft shadows with this for directional and point lights with such binary values?

Thanks

PARTNERS