View Full Version : Perspective Depth Buffer?

David Doria

02-24-2009, 10:59 AM

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.

http://rpi.edu/~doriad/cubes.jpg

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?

Thanks,

Dave

sharp_pixel

02-24-2009, 11:51 AM

Hi

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(u*u+v*v+w*w) where w is the depth value. You need to multiply those coordinates by some scalar to have the correct result.

David Doria

02-24-2009, 01:04 PM

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

sharp_pixel

02-24-2009, 05:10 PM

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

Abdallah DIB

02-25-2009, 09:08 AM

can u post here the values you get along a vertical line to verify .

second:

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 : P*M*V.

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,

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.