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

Here's the shadow part of my fragment shader:

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[i] = 0.5f*(-frustumArray[i].zFar*camProj[10] + camProj[14])/frustumArray[i].zFar + 0.5f;

Any ideas?

**Edited by frna, 19 May 2012 - 06:21 AM.**