Original Post
I am trying to get shadow mapping to work in my GLSL application. Everything looks fine except that the torus does not render right. The ground is fine. If I don't use shaders and use tex gen everything is perfect. So the problem must be in how I am generating the proj coords. Here is the GLSL shaders I am using...
// VERTEX SHADER
varying vec4 projCoord;
varying vec4 color;
uniform vec4 lightPos;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 pos = gl_ModelViewMatrix * gl_Vertex;
vec3 lightVect = normalize(lightPos.xyz - pos.xyz);
vec3 n = gl_NormalMatrix * gl_Normal;
projCoord = gl_TextureMatrix[0] * gl_Vertex;
color = gl_Color * max(dot(n, lightVect), 0);
}
// FRAGMENT SHADER
uniform sampler2D shadowMap;
varying vec4 projCoord;
varying vec4 color;
const vec4 ambient = vec4(0.13);
void main()
{
vec3 projectiveBiased = (projCoord.xyz / projCoord.w);
float shadowValue = projectiveBiased.z < 0 ? 0 : shadow2D(shadowMap, projectiveBiased).r;
gl_FragColor = ambient + color * shadowValue;
}
Any help would be apreciated.