Cascaded Shadow Mapping lookup problem gl_FragCoord.z

Started by
2 comments, last by sumingnan 11 years, 2 months ago
I implemented cascaded shadow mapping with 4 splits but my problem is, I only get shadows from the split for the smallest frustum.
Here's a screenshot demonstrating it:


I've checked my farBound values and they all seem correct. So I'm guessing gl_FragCoord.z doesn't do its job or maybe I'm using it wrong (I'm using it as in the nvidia code though).
I always end up in the first if, judging from the color sad.png

Here's the shadow part of my fragment shader:

SCHDO.png




vec4 getShadow()
{
vec4 sm_coord_c = texmat_3*vecPos;
float shadow = texture2D(smap_3, sm_coord_c.xy).x;
float s = (shadow < sm_coord_c.z) ? 0.0 : 1.0;

vec4 shadow_c = vec4(1.0, 1.0, 1.0, 1.0) * s;

if(gl_FragCoord.z < vecFarbound.x)
{
vec4 sm_coord_c = texmat_0*vecPos;
float shadow = texture2D(smap_0, sm_coord_c.xy).x;
float s = (shadow < sm_coord_c.z) ? 0.0 : 1.0;

shadow_c = vec4(0.7, 0.7, 1.0, 1.0) * s;
}
else if(gl_FragCoord.z < vecFarbound.y)
{
vec4 sm_coord_c = texmat_1*vecPos;
float shadow = texture2D(smap_1, sm_coord_c.xy).x;
float s = (shadow < sm_coord_c.z) ? 0.0 : 1.0;

shadow_c = vec4(0.7, 1.0, 0.7, 1.0) * s;
}
else if(gl_FragCoord.z < vecFarbound.z)
{
vec4 sm_coord_c = texmat_2*vecPos;
float shadow = texture2D(smap_2, sm_coord_c.xy).x;
float s = (shadow < sm_coord_c.z) ? 0.0 : 1.0;

shadow_c = vec4(1.0, 0.7, 0.7, 1.0) * s;
}

return shadow_c;
}


vertex shader:


varying vec3 vecLight;
varying vec3 vecEye;
varying vec3 vecNormal;
varying vec4 vecPos;
varying vec4 fragCoord;
void main(void)
{
vecPos = gl_Vertex;
vecNormal = normalize(gl_NormalMatrix * gl_Normal);
vecLight = normalize(gl_LightSource[0].position.xyz);
vecEye = normalize(-vecPos.xyz);

gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}



And here my farbound calculation (as in the nvidia sample for csm, it prints out very similar numbers):


farBound = 0.5f*(-frustumArray.zFar*camProj[10] + camProj[14])/frustumArray.zFar + 0.5f;



Any ideas?
Advertisement
[color=#a9a9a9]Turns out it was indeed my shader's fault. I've accessed values for split 3 and 4 while only having set 2 splits up.
New problem arose though, see changed OP please.
Sorry for bumping but I still have this problem. I've tried adjusting the projection matrix but it didn't help.
It sort of works of I use view space distance by doing: dist = dot(eye.xyz, eye.xyz) however the resulting regions arent as big as the frustum splits and they're only decently sized when I'm close to the ground.

Any ideas?

Hello, you solve the problem? Now I also encountered the same problem, I'm currently in OpenGL ES 2 CSM algorithm under, however some details remained unresolved, can tell. Thank you.

This topic is closed to new replies.

Advertisement