Jump to content
  • Advertisement
Sign in to follow this  
shodanjr_gr

Problem Shadow Mapping texture transform in GLSL

This topic is 3804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
First of, do you go back to glMatrixMode(GL_MODELVIEW) after you get done uploading the data to the texture matrix?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!