hey guys,
yeah, jan2000, that’s actually the tutorial i’m working off now. however, i just can’t get my code to work correctly. for example, here is my scene:
http://www.graphics.cornell.edu/~letteh/ogl/Unshadowed.jpg
here’s the scene w/ shadow volumes (just so you see roughly what it should look like):
http://www.graphics.cornell.edu/~letteh/ogl/ShadowVolume.jpg
here’s the depth map for shadow mapping:
http://www.graphics.cornell.edu/~letteh/ogl/DepthMap.jpg
and here’s my final image when i try using shadow mapping:
http://www.graphics.cornell.edu/~letteh/ogl/ShadowMapped.jpg
so clearly something is wrong
here’s some of my code:
glPushAttrib(GL_ENABLE_BIT);
double textureMatrix [16];
double tempMatrix [16];
double biasMatrix = {0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0};
matrixMultiply(biasMatrix, lightProjMatrix, tempMatrix);
matrixMultiply(tempMatrix, lightViewMatrix, textureMatrix);
double vec1 = {textureMatrix[0], textureMatrix[4], textureMatrix[8], textureMatrix[12]};
double vec2 = {textureMatrix[1], textureMatrix[5], textureMatrix[9], textureMatrix[13]};
double vec3 = {textureMatrix[2], textureMatrix[6], textureMatrix[10], textureMatrix[14]};
double vec4 = {textureMatrix[3], textureMatrix[7], textureMatrix[11], textureMatrix[15]};
//--------------------------------------------------------------
// CONFIGURE THE EYE PLANES
//--------------------------------------------------------------
glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni (GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni (GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGendv (GL_S, GL_EYE_PLANE, vec1);
glTexGendv (GL_T, GL_EYE_PLANE, vec2);
glTexGendv (GL_R, GL_EYE_PLANE, vec3);
glTexGendv (GL_Q, GL_EYE_PLANE, vec4);
glEnable (GL_TEXTURE_GEN_S);
glEnable (GL_TEXTURE_GEN_T);
glEnable (GL_TEXTURE_GEN_R);
glEnable (GL_TEXTURE_GEN_Q);
//--------------------------------------------------------------
//--------------------------------------------------------------
// BIND, ENABLE, AND CONFIG SHADOW MAP TEXTURE
//--------------------------------------------------------------
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, shadowMapTexID);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE); // Enable shadow comparison
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); // Shadow comparison should be true (ie not in shadow) if r<=texture
glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY); // Shadow comparison should generate an INTENSITY result
//--------------------------------------------------------------
//--------------------------------------------------------------
// ENABLE THE ALPHA TEST TO DISCARD FALSE COMPARISONS
//--------------------------------------------------------------
glAlphaFunc (GL_GEQUAL, 0.50f);
glEnable (GL_ALPHA_TEST);
//--------------------------------------------------------------
//---------------------------------------
// Render captured geometry
//---------------------------------------
renderCapturedGeometry(0, true, LIGHTS_ENABLED, true);
//---------------------------------------
//---------------------------------------
// Render MDL file meshes
//---------------------------------------
for (int i=0; i < (int)ssMeshes.size(); ++i)
ssMeshes[i].renderMesh(true, LIGHTS_ENABLED);
//---------------------------------------
glPopAttrib();
there are a few things i’m unsure of (and they may be the cause of my troubles).
A) the vectors i’m passing in to the eye planes might not be correct
B) i don’t really understand what exactly GL_INTENSITY sets (and the registry page doesn’t explain it very well at all).
C) i don’t understand how in shadow mapping you need to re-render your scene w/ the alpha test enabled and using GL_TEXTURE_COMPARE_FUNC_ARB with the depth texture – what if your scene has textures in it? when i call the render functions for my objects, they would traditionally (though not in this case), need to bind their own textures for rendering. but then the depth texture is no longer bound. so how can this be? how can this depth texture comparison be done if you need to change to a different texture to render the object? maybe i’m missing something vital here.
thanks.