Sign in to follow this  

Cascaded Shadow Mapping lookup problem gl_FragCoord.z

This topic is 1781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]

Here's the shadow part of my fragment shader:

[img]http://i.imgur.com/SCHDO.png[/img]



[CODE]
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;
}
[/CODE]

vertex shader:

[CODE]
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();
}
[/CODE]


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

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


Any ideas? Edited by frna

Share this post


Link to post
Share on other sites
[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[/color]. Edited by frna

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

This topic is 1781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this