Jump to content
  • Advertisement
Sign in to follow this  
shodanjr_gr

Using a GL_DEPTH_COMPONENT texture in a shader

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:


// 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);

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?

Share this post


Link to post
Share on other sites
Advertisement
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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!