I am just implementing shadow mapping in my project, and I am having a weird problem: With a depth buffer FBO setup for shadow mapping (see below) nothing seems to get rendered to the shadowmap. When rendering the scene to an FBO with a regular depth buffer (color write masked off) and a color buffer, the depth buffer looks ok. I have changed the output so that the shadowmap gets rendered to the screen. Here’s what it looks like with the regular FBO:
When rendering the shadowmap depth texture, the entire output window is white (i.e. the shadowmap only contains 1.0, or what?)
Here’s the code for the shadowmap depth buffer:
GLuint hFBO, hDepth; glGenFramebuffersEXT (1, &hFBO); glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, hFBO); glActiveTexture (nTMU); glEnable (GL_TEXTURE_2D); glGenTextures (1, &hDepth); glBindTexture (GL_TEXTURE_2D, hDepth); // setup the depth texture glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, nWidth, nHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, hDepth, 0);
When rendering the depth buffer to screen I simply render it as a quad over the entire output window. Since it works for the regular depth buffer (24+8 bits depth+stencil), I guess it should work similary for the shadow texture.
Now the question is: Since the off screen renderer seems to work for a regular FBO render target, and the depth buffer looks fine there, why doesn’t it for the shadow texture? Is there something wrong in the way I am setting the shadow texture up?