PDA

View Full Version : How to get the real depth value



hawaii
03-16-2007, 07: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.

Relic
03-16-2007, 09: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, 10:11 AM
This is what you need:

dist = (NEAR_PLANE*FAR_PLANE/(NEAR_PLANE-FAR_PLANE))/(zbuffer[ii][iii]-FAR_PLANE/(FAR_PLANE-NEAR_PLANE));


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

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

hawaii
03-16-2007, 11:45 PM
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, 04: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];

glReadPixels(0,0,XRES,YRES,GL_DEPTH_COMPONENT,GL_F LOAT,zbuffer);

hawaii
03-17-2007, 09: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 :)

Hawaii