Viewing the depth buffer with max efficiency
Viewing the depth buffer with max efficiency
Has anyone managed to render a texture or FBO with the scene´s depth buffer by temporarily switching off the texture compare mode?
I´m trying to find the most efficient way of viewing the depth buffer in an intensity z-modified blue, without moving pixels, and processed by the GPU.
Adding a shader to a texture is easy, but is it possible to add a shader or something to the FBO renderer, so that it draws pixels not based on color but depth?
I´m trying to find the most efficient way of viewing the depth buffer in an intensity z-modified blue, without moving pixels, and processed by the GPU.
Adding a shader to a texture is easy, but is it possible to add a shader or something to the FBO renderer, so that it draws pixels not based on color but depth?
Re: Viewing the depth buffer with max efficiency
You can do that in GL (attaching the depth as a texture), but not in irr currently. Other ways include saving the depth when rendering it.
Re: Viewing the depth buffer with max efficiency
Do you know which function calls that would be? I could have a go at implementing both methods to see the speed difference.
Re: Viewing the depth buffer with max efficiency
I found this code snippet, wondered if it could be adapted for zbuffer rendering:-
Code: Select all
glBindTexture(GL_TEXTURE_2D, mTexIdShadowDepthRender);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE); // Turn off compare mode to draw.
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2d(0,1);
çglVertex2d(x, y);
glTexCoord2d(0,0);
glVertex2d(x,y+size);
glTexCoord2d(1,1);
glVertex2d(x+size, y);
glTexCoord2d(1,0);
glVertex2d(x+size, y+size);
glEnd();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB); // Reinstate compare mode.
Re: Viewing the depth buffer with max efficiency
To save the depth, just write gl_FragCoord.z to another buffer. You'll need either a float buffer, or to use some clever packing with a 8-bit one.
Re: Viewing the depth buffer with max efficiency
Okay, thanks, this is going to be fun! Any good references on GLSL programming would be welcome!
The aim is to reformat the FBO to show the rendered scene image on the left half of the screen, and show the depth buffer as a grey scale (white nearest to viewer) on the right side. I guess its going to be a good exercise in GLSL... I can use the split window examples + shader to achive this, I hope!
The aim is to reformat the FBO to show the rendered scene image on the left half of the screen, and show the depth buffer as a grey scale (white nearest to viewer) on the right side. I guess its going to be a good exercise in GLSL... I can use the split window examples + shader to achive this, I hope!
Last edited by robmar on Fri Apr 06, 2012 10:02 pm, edited 1 time in total.
Re: Viewing the depth buffer with max efficiency
Don't forget to normalize the depth for visualization, showing it as-is would show just one color 
Re: Viewing the depth buffer with max efficiency
I thought the depth buffer was stored as floats from 0.0 to 1.0?
Re: Viewing the depth buffer with max efficiency
Yes, but in a typical scene, the depth difference of one object and another is small enough to be within 1/256 of each other.
Re: Viewing the depth buffer with max efficiency
But if I calculate the intensity based on the direct z-buffer value, then it will just scale, i.e the pixels will be half intensity when z == 0.5.
Am I missing the point?
Am I missing the point?
Re: Viewing the depth buffer with max efficiency
Yes, because all of your pixels will be 0.5 (for example) unless you normalize 
Re: Viewing the depth buffer with max efficiency
and if I adjust the near and far distance to scale across the required view depth rather than to the far distance?
Re: Viewing the depth buffer with max efficiency
It may or may not work, I don't know.