Original Post
I am trying to do some shadow mapping in GLSL. Ive done the light pass, writing the Z value of each fragment as the gl_FragColor and it looks fine. The issue is that i cant seem to be able to get the texture matrix generation right. This is what i am doing: Application code:
//setting up the shadow map texture matrix
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, shadow_map_texture);
glUniform1i(shadowmapLoc, 1);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5,0.5,0.5); //bias
glScalef(0.5,0.5,0.5);
glMultMatrixf(light_projection);
glMultMatrixf(light_modelview);
glMatrixMdode(GL_MODELVIEW);
///generate geometry/////
light_projection and light_modelview obviously contain the projection and modelview matrices for the light source The Vertex shader is
varying vec4 shadowMapCoords;
void main()
{
shadowMapCoords = gl_TextureMatrix[1] * gl_Vertex;
shadowMapCoords = shadowMapCoords / shadowMapCoords.w;
}
and the pixel shader is
uniform sampler2DShadow shadowMap;
varying vec4 shadowMapCoords;
float shadowMapLookup(vec4 in_coords)
{
float value = shadow2DProj(shadowMap, in_coords).x;
return value != 1.0 ? 0.20 : 1.0;
}
void main()
{
gl_FragColor = shadowMapLookup(shadowMapCoords);
}
The end result is that the shadow texture seems to be "camera dependent", meaning that when i rotate the camera, the way the shadow maps on objects rotates with it... What am i doing wrong? [Edited by - shodanjr_gr on July 8, 2008 2:02:37 PM]