Hi,
I’m tryng to get shadowmaps working in my application, but i’m not sure if i’m doing this right.
What i’m doing right now, is i render to a texture (rgba) the object that i want, and then i project that texture to the ground, all good here, however if i project the same texture on the object itself, won’t work.
So, instead of rendering to a rgba texture, i’m rendering to a depth texture…,
This are the steps i’m making :
The FBO setup
glGenFramebuffersEXT( 1, &g_BIG_SHADOWframeBuffer );
glGenRenderbuffersEXT( 1, &g_BIG_SHADOWdepthRenderBuffer );
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, g_BIG_SHADOWdepthRenderBuffer );
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, 2048, 2048 );
depth texture setup
glGenTextures(1, &Local_Shadow);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Local_Shadow);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 2048, 2048, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB );
Then, render the objects to the texture :
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, g_BIG_SHADOWframeBuffer );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, Local_Shadow, 0 );
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, g_BIG_SHADOWdepthRenderBuffer );
glViewport( 0, 0, 2048, 2048 );
render objects();
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
glViewport( 0, 0, g_window->init.width, g_window->init.height );
Right now in theory i should have the depth texture.
Now, i will render the objects normally, and then in a 2nd pass with this settings and texture projection enabled :
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
I should get shadow projections, only in the areas where the Z-Buffer is lower or equal by comparing the framebuffer z values with the ones in the depth map, correct ?
However, this is not working, i must be doing something wrong, for a starts my depth map appears all white, no ideia why, it should be grayscale even with a lack of precision.
If anyone can point me in the right direction, i would apreciate.,
thanks,
Bruno