Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Member Since 19 Dec 2011
Offline Last Active Sep 08 2012 02:43 PM

Topics I've Started

Cascaded Shadow Mapping lookup problem gl_FragCoord.z

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 Posted Image

Here's the shadow part of my fragment shader:

Posted Image

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?

Black specs in normal mapping on nvidia

21 April 2012 - 08:45 AM


I'm having a problem with my normal mapping on nvidia cards that I just can't seem to fix and hope you guys could help me out.
Here are some pictures showing the problem, the last one shows the same scene on ATI but from a different place in the model.


ati: http://i.imgur.com/5Oa5b.png (works as intended)

I found out that the problem is my shininess float value that I send into the shader. If it's 0.0f it seems like the shader on nvidia thinks its undefined or some other weird value. If I hardcode 0.0 as shininess into the specular component it works just fine.

Any idea how this could happen?