Jump to content
  • Advertisement
Sign in to follow this  
Icebraker

Shadow map / GLSL question

This topic is 4488 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

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

Share this post


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

Share this post


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

Share this post


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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!