// setting up the shadowmap frame buffer object
glGenFramebuffersEXT(1, &shadow_map_buffer_object);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, shadow_map_buffer_object);
glGenRenderbuffersEXT(1, &shadow_map_depth_buffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, shadow_map_buffer_object);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, 800, 800);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, shadow_map_depth_buffer);
//attaching a texture to the depthbuffer
glGenTextures(1, &shadow_map_texture);
glBindTexture(GL_TEXTURE_2D, shadow_map_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 800,800, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
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_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow_map_texture, 0);
if ( glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT ) std::cout<<"New framebuffer created!"<<"\n";
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
Using a GL_DEPTH_COMPONENT texture in a shader
I am implementing a shadowmapping algorithm, using Framebuffer Objects in order to render-to-texture.
My initialization code for the FBO with a DB texture is this:
which works OK and gives no errors.
However i am stuck in how i am supposed to read a GL_DEPTH_COMPONENT texture inside a fragment program (my ultimate goal for the moment is to be able to visualize the depth buffer). Any ideas?
If you are using
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
then you need to use the sampler2DShadow and if you use
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
then you use sampler2D
then just get the red component of the texture
float depth = texture2D(depthMap, textureCoord.xyz).r;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
then you need to use the sampler2DShadow and if you use
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
then you use sampler2D
then just get the red component of the texture
float depth = texture2D(depthMap, textureCoord.xyz).r;
assuming you binded the texture correctly on the GL side, using tex2Dproj will tell the GPU to automatically do a 2x2 PCF and return the shadow result.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement