Sign in to follow this  
Forceflow

Render the Depth Buffer

Recommended Posts

Forceflow    101
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[i]){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
whiterook6    124
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this