• Create Account

## Cascaded Shadow Mapping lookup problem gl_FragCoord.z

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1frna  Members

162
Like
0Likes
Like

Posted 04 May 2012 - 02:41 PM

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

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;
}

}


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.

### #2frna  Members

162
Like
0Likes
Like

Posted 05 May 2012 - 06:52 PM

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
.

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

### #3frna  Members

162
Like
0Likes
Like

Posted 19 May 2012 - 06:20 AM

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?

### #4sumingnan  Members

103
Like
0Likes
Like

Posted 29 January 2013 - 03:01 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.