   Help. Shadow maps with glsl
  I have puzzled by a weird problem in shadow maps with glsl for several days.My way of coding is just the same as others. I directly compute the texture matrix in application program:  textureMatrix = biasMatrix * lightProjectionMatrix * lightViewMatrix * cameraViewInvertMatrix;Then I transfer this texture matrix into vertex shader to computer texture coordinate like this:  varying vec4 texCoord;  ...  texCoord = texture * gl_ModelViewMatrix * gl_Vertex;  texCoord = texCoord / texCoord.w    //for homogenueousThen I transfer the texCoord into fragment shader for compareing with the depth in shadow map which is stored by application program:    varying vec4 texCoord;  uniform sampler2DShadow shadowMap;  bool isInShadow()  {    float depth = shadow2DProj(shadowMap, texCoord).r;    if (depth == 1.0)   return false;    else   return true;   }I think my method is right. But unfortunately, I can not draw the right shadow in my program. And the matrices which I use are all right computed.Could anybody tells me which is wrong in my program. Thanks a lot.   
  Your first step to shadow mapping is making sure your projection math works.Give up the shadow and replace with a standard projective texture.If math proves to be correct then the SM is probably incorrectly generated or used.A good way to understand if the SM is correctly generated is to simply use it as a B&W texture on a quad.If everything is correct up to there, then I suppose the depth compare mode may be wrong.   ;  Thank you, Krohm. I have fixed it. The last step, depth comparison function is wrong. When I see the depth map as a normal texture map, and change the shadow2DProj() function to texture2D() function, use  bool isInShadow()  {    float depth = texture2D(shadowMap, texCoord.xy);    if(depth < texCoord.z)  return false;    else  return true;  }the program runs ok. But until now, I havn't know why shadow2DProj() function is wrong.   ;  I suppose you forgot to set texture's TEXTURE_COMPARE_MODE. Take a look at section 3.8.14 of the 2.1 spec.Comparing the depth yourself is WRONG - you need to tell the hardware to do that, this is how PCF works and why Shadow* samplers are used.   