Perspective Depth Buffer?

I’m interested in the distance values along each perspective ray. The depth buffer seems to have the orthogonal distance from the object point to the plane orthogonal to the camera “forward” direction.

As you can see there, the depth values along any vertical strip of the cube are identical. I would like the values farther from the center to be higher (because the rays are slightly longer). Is there anyway to get these values?




The depth buffer returns identical values for every point in a plane parallel to the image. It gives you the distance along the depth axis, not the length of the rays.
If you want that, you simply compute the norm of the vector using the image coordinates (u, v) where the center is in (0, 0).
So you basically have something like sqrt(uu+vv+w*w) where w is the depth value. You need to multiply those coordinates by some scalar to have the correct result.

That scalar is tricky right? How do you know the conversion between world (3d) coordinates and image (2d) coordinates?

The transformation from 3D to 2D is explained in the OpenGL specification. It depends on the projection matrix.

can u post here the values you get along a vertical line to verify .
to pass from 3d to 2d coordinates all u have to do . is to query ur Modelview Matrix “M” using glGetFloatv(GL_MODELVIEW_MATRIX,M) and projection matrix “P” glGetFloatv(GL_PROJECTION_MATRIX,P), and multiply ur vertex V(vx,vy,vz,vw) by M than P : PMV.
than normlize ur coordinates(divide x,y,z by w) ( for perspective view only ) than do a mapping to window coordinate ( x->x-1/2; y->y-1/2) , u are now in a 2D space,