• Advertisement
Sign in to follow this  

Render the Depth Buffer

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