Sign in to follow this  
othello

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 this post


Link to post
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);
bind(shadowMap)
glTexParamete(GL_COMPARE_R_TO_TEXTURE)

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

Draw();

Share this post


Link to post
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 1
glClientActiveTexture( GL_TEXTURE1 );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, mTempShadowMapTex );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

// Enable shadow comparison
glTexParameteri( 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 <= texture
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );

// Generate an intensity
glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY );

//Set alpha test to discard false comparisons
glAlphaFunc( 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 this post


Link to post
Share on other sites
UPDATE:
I rewrote the entire shadow generation using this tutorial: http://www.briandanchilla.com/files/resources/opengl/tutorial_series/6_shadowmap/shadowmap_tutorial.html and using immediate mode instead of VBOs.

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 this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
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.


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 this post


Link to post
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).

Thanks for your replies, I appreciate your time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this