Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem Shadow Mapping texture transform in GLSL

Started by shodanjr_gr Jul 8, 2008 at 9:25 AM 2 replies 1.3k views
Original Post
shodanjr_gr
shodanjr_gr
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]
MARS_999
MARS_999
First of, do you go back to glMatrixMode(GL_MODELVIEW) after you get done uploading the data to the texture matrix?
shodanjr_gr
shodanjr_gr
Quote:
Original post by MARS_999
First of, do you go back to glMatrixMode(GL_MODELVIEW) after you get done uploading the data to the texture matrix?


Yup. Sorry, forgot to post that in my code, ill update it now.
shodanjr_gr
shodanjr_gr
Sorry about having to bump this, but i havent figured it out yet.

Any ideas?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.