Jump to content
  • Advertisement
Sign in to follow this  
Forceflow

Render the Depth Buffer

This topic is 3023 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

Hello everybody, I currently render the depth buffer in my application by copying it to a texture, clearing the screen and drawing a fullsize quad to display it. (2 passes) Somehow, this strikes me as an ugly way to go about and do it. Is it possible to just access the depth buffer in a GLSL shader and change the fragment color to it? This would allow me to do all this in one pass.
	
// draw the mesh to fill the depth buffer
glDisable(GL_LIGHTING);
for (unsigned int i = 0; i < meshes.size(); i++)
{
	if (!visible){continue;}
	//setup_lighting(i);
	draw_mesh(i);
}
// copy depth buffer to texture
glBindTexture(GL_TEXTURE_2D, depthTexture);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512, 512);

// clear screen
cls();
// enable texturing and bind the depth texture
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, depthTexture);
// overlay texture to fullsizequad
drawFullsizeQuad();

Share this post


Link to post
Share on other sites
Advertisement
Yeah
In the pixel shader you can use gl_FragCoord as an input, and if it's in screenspace then the z coord should be depth. Then draw that as a color output?

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!