Jump to content
  • Advertisement
Sign in to follow this  
L. Spiro

Shadow Mapping Woes

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

http://www.paulsprojects.net/tutorials/smt/smt.html http://dalab.se.sjtu.edu.cn/~jietan/shadowMappingTutorial.html They both put the depth texture into texture unit 0, enable automatic UV generation for that unit, etc., then go on to render the scene.
Pseudo-code in Pass 3:
matrix44 textureMatrix = biasMatrix * shadowLightProjectionMatrix * shadowLightViewMatrix;
              //Set up texture coordinate generation.
         glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix[0]);
         glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix[1]);
         glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix[2]);
         glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix[3]);
         ////Bind & enable shadow map texture
         glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
         //Shadow comparison should be true (ie not in shadow) if r<=texture
         //Shadow comparison should generate an INTENSITY result
         //Set alpha test to discard false comparisons
         glAlphaFunc(GL_GEQUAL, 0.99f);
I think the question(s) this begs should be pretty obvious: #1: But, uh, I have textures on my models, and they are going into texture unit 0 as they should be (this is quite standard). So won't the depth texture get removed from unit 0 once I set one of my model textures to unit 0? And all those calls to glTexParameteri() are going to affect my model textures in unit 0. #2: So if the depth texture and my model textures are going to clash, what happens if I set the depth texture to a unit other than 0? Particularly the last unit. It is going to process all the texture units in order from 0 to X. By the time it gets to X, hasn't it already done the depth compare? So it is too late to perform a depth compare using the depth texture. Isn't it? L. Spiro

Share this post

Link to post
Share on other sites
use multitexture, theres no doubt tutorials at the links youve supplied

glActiveTexture( GL_TEXTURE1 );
bind depth
glActiveTexture( GL_TEXTURE0 );
bind color texture

Share this post

Link to post
Share on other sites
So that answers my #2.
So you can set the depth texture into any unit and it will still work.

But may I ask for a bit more detail as to what will happen under the scenes?
I know how multi-texturing works (generally) and how the texture units are processed, so my question is not about that.

I mean the depth comparison comes from the texture, which is in a texture unit.
When that unit is 0, as is always shown in tutorials, there is no question as to what is happening. But if I move it to any other unit, how does the depth comparison get picked up? If it processes all the texture units in order, it would get all the colors and compile the fragment up to the Nth texture unit (where the depth texture would be), and then upon reaching the depth texture it would finally do the (delayed) depth comparison, and then throw everything away and move on (upon failure)?
This would cause a performance loss I imagine.

Or does setting depth comparison on any unit automatically make OpenGL jump directly to that comparison in place of its default depth comparison?

Last question.
I thought my book—Beginning OpenGL Game Programming, By Dave Astle and Kevin Hawkins—mentioned this but from the small preview I could find online (I left the actual book at home) I could not find it. The texture units do not have to be contiguous right? As long as a texture unit is not set up to reference a texture unit that is not active. I should be able to set my regular textures in the first X available slots, and always put the depth texture in the last slot, even if slots 1 and 2 have not been enabled.

Thank you,
L. Spiro

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!