Skip to main content
gamedev.net
🔒 Locked

Shadow map / GLSL question

Started by Icebraker Jul 5, 2006 at 10:44 AM 3 replies 550+ views
Original Post
Icebraker
Icebraker
Hello, I have a question concerning shadow maps and GLSL. I have setup my shadow maps and want to use them in my shader. To hand them over as a uniform variable I have used glUniform1f(glGetUniformLocation(progID,"shadowMap1"),shadowMap1->shadowDepthMap); glUniform1f(glGetUniformLocation(progID,"shadowMap2"),shadowMap2->shadowDepthMap); The shadowMap is created in a separate class using: glGenTextures(1, &shadowDepthMap); glBindTexture(GL_TEXTURE_2D, shadowDepthMap); ..... I know my shadowMap is computed correctly because I can use it without a shader, but I somehow can't access the map in my shader.. here is my shader code: uniform sampler2DShadow shadowMap1; uniform sampler2DShadow shadowMap2; varying vec4 ProjShadow; float calcValue1() { // gives a float that is 0 if the object is in shadow in 1 if it is not in shadow. float depth=shadow2DProj(shadowMap1, ProjShadow).r; // return coefficient for shadow if(depth !=1.0) { return 0.5; } else { return 1.0; } } This method always returns 0.5, so my guess is that the shadow map is not handed over correctly in the sahder... Any suggestions what I am doing wrong? THX
nts
nts
Few things, first you can't use 'glUniform1f' to set samplers, you are only allowed to use 'glUniform1i'. Secondly I think with shadows (like regular textures) instead of setting the texture id you need to bind the texture to a unit and send the unit number instead.

Also you can save the uniform locations (they don't change) instead of getting them each time (faster).

Hope that helps
Icebraker
Icebraker
Thx,

I have now changed the program to

glUniform1i(glGetUniformLocation(progID,"shadowMap1"),0);
glUniform1i(glGetUniformLocation(progID,"shadowMap2"),1);

and bound the texture units with

glActiveTextureARB(GL_TEXTURE0_ARB);
glActiveTextureARB(GL_TEXTURE1_ARB);

but I still can't access them...

Any further suggestions?

thx a lot
_the_phantom_
_the_phantom_
can we see the texuture and texture unit setup code please..
Icebraker
Icebraker
Here you are:

//! I want to store the map in the first texture unit
glActiveTextureARB(GL_TEXTURE0_ARB);

glGenTextures(1, &shadowDepthMap);
glBindTexture(GL_TEXTURE_2D, shadowDepthMap);

//! Shadow-Map has size of mapSizeX times mapSizeY
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, mapSizeX, mapSizeY, 0);

//! Use nearest neighbour interpolation
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

Topic Locked

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

Sign in to reply to this topic.