View Full Version : How to get the real depth value

03-16-2007, 08:26 AM
I was now working on an IBR altorithm. I need to read out depth value of all pixels of the display window. I have tried glReadPixels function. But the depth values are limited to 0.0-1.0. What I need is the real z value in the 3D coordinate space. Is anyone that who have use something like this? I appreciate your help very much.

03-16-2007, 10:55 AM
You could write vertex and fragment shaders which calculate any value you like and write that into a separate floating point buffer by using multiple render targets or a multipass algorithm.

Thor Henning Amdahl
03-16-2007, 11:11 AM
This is what you need:


For more discussions on how the z is calculated I recomend this document: http://sjbaker.org/steve/omniv/love_your_z_buffer.html

Thor Henning Amdahl

03-16-2007, 01:13 PM
Relic, you're a funny guy.

03-17-2007, 12:45 AM
Thank you for all of your helps.

Now I have another question for the equation posted by Thor Henning Amdahl. What does zbuffer[ii][iii] represent? Can I simply treat it as z-buffer value directly read from depth buffer whose value is from 0.0-1.0?

I am looking forward to your reply! :)

Thor Henning Amdahl
03-17-2007, 05:40 AM
You are right. You can simply insert the values 0-1 read from the depth buffer.

From the code:

GLfloat zbuffer[XRES][YRES];


03-17-2007, 10:26 PM
I tried it in your approach, and it works very well. I appreciate your help very much.

Thank you so much, Thor Henning Amdahl :)