   gl_FragCoord.z and arriving at it.
  I'm having some weird artifacts with my shadow mapper, and decided that gl_FragCoord.z is too mysterious and undecidable.  In my current implementation, I calculate in the depthmapper, from the light's point of view.gl_FragColor.r = gl_FragCoord.z;gl_FragColor.g = gl_FragCoord.z;gl_FragColor.b = gl_FragCoord.z;gl_FragColor.a = 1.0;Then, somewhere along, I compare this value to do shadow mapping using the following. This is from the camera's point of view. lightViewMatrix is the view matrix of the camera, invCameraView matrix is the inverse view matrix of the camera.vec4 shadowCoord = lightViewMatrix * invCameraViewMatrix * vertexPosition;vec3 shadowProj = vec3 (shadowCoord/shadowCoord.w) * 0.5 + 0.5;return shadowProj;vertexPosition is gl_Vertex multiplied by the modelview matrix. Then shadowProj.z is the depth.  This works, but I'm getting weird issues on some occluders, so I decided not to use the fixed function depth value in the shadow mapper:float depth = shadowPosition.z/shadowPosition.w * 0.5 + 0.5;shadowPosition is calculated in the vertex shader like so:varying vec4 shadowPosition;...shadowPosition = gl_ModelViewMatrix * gl_Vertex;I'd expect this to work, since this is what I'm doing originally.  However, this produces unexpected and wrong results.What am I doing wrong?  If you can't answer that, then simply "How does one arrive at gl_FragCoord.z using the view, model, and projection matrices?" will do.   
  I've been reading around and it seems that it might be a better idea to find the distance to the near plane and then simply just normalize it based on the distance to the far plane from [0, 1].I think I'll do that and see what happens.   