# SOLVED: Shadow Mapping and Texture Units

## Recommended Posts

Quote:
 Hmm... I figured it out... Apparently, using glClientActiveTextures breaks it, and in addition I had some memory errors that I neglected that kept me from noticing it (causing the artifacts). Thanks for your replies, I appreciate your time.p
Hi, I'm having a similar problem in programming a shadow map system to this person here: http://www.gamedev.net/community/forums/topic.asp?topic_id=483134 I am using Paul's tutorial, which apparently is a bit outdated, but it seems to be one of the few resources available to beginning programmers on shadow mapping. I can render shadows properly, but I cannot render a texture on the shadowed objects. When I try, The scene appears fully-lit. I assume this is because when I bind the texture, I test the newly bound texture instead of the depth texture. Simply adding glClientActiveTexture() and changing the texture unit for rendering my mesh does not work, I guess because it's trying to process the new texture unit with the shadow comparison. I am rendering the mesh with a vertex buffer object, but I do not think this makes any difference. Thanks for reading; if anyone wants I can post source, but I do not think it's necessary since this is a more conceptual problem. [Edited by - othello on July 6, 2008 12:38:23 AM]

##### Share on other sites
GLSL or no? If its fixed function you might have to add a modulate or so in there.

//pseudo code
glActiveTex(...unit0);
glTexParamete(GL_COMPARE_R_TO_TEXTURE)

glActiveTex(...unit1);
bind(texture)

Draw();

##### Share on other sites
Thanks for the reply. I tried adding GL_MODULATE, but it doesn't seem to change anything:

This is my function for binding the shadow texture:

// Bind and enable the shadow map texture + change the tex unit to 1glClientActiveTexture( GL_TEXTURE1 );glEnable( GL_TEXTURE_2D );glBindTexture( GL_TEXTURE_2D, mTempShadowMapTex );glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );	// Enable shadow comparisonglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,					GL_COMPARE_R_TO_TEXTURE );// Shadow comparison should be true ( not in shadow ) if r <= textureglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );// Generate an intensityglTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY );//Set alpha test to discard false comparisonsglAlphaFunc( GL_GEQUAL, 0.99f );glEnable( GL_ALPHA_TEST );// Disable textures and texgen//glDisable( GL_TEXTURE_2D );

This is the function for my texture class that binds the texture:
glClientActiveTexture( GL_TEXTURE0 );glEnable( GL_TEXTURE_2D );glBindTexture( GL_TEXTURE_2D, mTexID );glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

Adding the glTexEnv* with GL_MODULATE does not change anything. I'm not surprised because from what I understand, GL_MODULATE is the default mode. Am I missing something here (where it would be used in another function)?

##### Share on other sites
UPDATE:

It still doesn't work. I am using SDL, and I know I have to enable the use of the stencil buffer if I want to use it. Do I have to do anything similar for multitexturing to allow this to work?

##### Share on other sites
Why do you need a stencil buffer for shadowmapping? And if the VBO version didn't work immediate mode isn't going to work either.

##### Share on other sites
Quote:
 Original post by MARS_999Why do you need a stencil buffer for shadowmapping? And if the VBO version didn't work immediate mode isn't going to work either.

I was just giving the stencil buffer as an example. Interestingly, I did manage to get it working properly without VBOs. However when I try to use VBOs, the texture does not display properly (I'm assuming because I am using glActiveTexture instead of glClientActiveTexture). When I change to glClientActiveTexture, the shadowmap does not display.

##### Share on other sites
Hmm... I figured it out... Apparently, using glClientActiveTextures breaks it, and in addition I had some memory errors that I neglected that kept me from noticing it (causing the artifacts).

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628336
• Total Posts
2982156

• 9
• 24
• 9
• 9
• 13