PDA

View Full Version : world space z-coords from depth buffer...



pixelate
01-10-2004, 12:59 AM
Hi!

is it possible to derive the world space z-coordinate of a point from its z value in the depth buffer? meaning that after rendering the scene, i wan to noe the value of the 3d coords of each point on the screen....

or for that matter, it doesnt have to be from the zbuffer. i anyway will do as long as i can have the z-values of the final image output somewhere...

thanks!

mw
01-10-2004, 10:07 AM
use glReadPixels and gluUnProject

pixelate
01-11-2004, 05:55 PM
hmm.... but are those depth values i get back from glReadPixels quantized to the precision of the zbuffer? cuz for some purpose i need the exact 3d coords of points in the final image...

SuperTomate
01-14-2004, 08:05 AM
Well, I'd say you can. Here's a formula for it :

Z = B / ((Zb / C) + A)

where :
A = -F / (F - N)
B = N * A
C = 2^M where M is the number of bits for your z-buffer (typically 24)
Zb = is the value (between 0 and C-1) in the z-buffer
N = near clip plane z-value
F = far clip plane z-value

Check it though cuz I'm not 100% sure. I derived it from here : learning to love your z-buffer (http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html) (this link is also present in another of my postings).

Hope it helps !


[This message has been edited by SuperTomate (edited 01-14-2004).]

jwatte
01-14-2004, 09:33 AM
Yes, you'll get quantized by the Z buffer.

No, there's no way to get better resolution what what got quantized into the framebuffer. If you need that, then run a ray through your scene and use analytic geometry to find the intersection point.

fqf
01-19-2004, 11:23 AM
But how do you determine Zb? it seemed not the depth value stored in the depth buffer.


Originally posted by SuperTomate:
Well, I'd say you can. Here's a formula for it :

Z = B / ((Zb / C) + A)

where :
A = -F / (F - N)
B = N * A
C = 2^M where M is the number of bits for your z-buffer (typically 24)
Zb = is the value (between 0 and C-1) in the z-buffer
N = near clip plane z-value
F = far clip plane z-value

Check it though cuz I'm not 100% sure. I derived it from here : learning to love your z-buffer (http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html) (this link is also present in another of my postings).

Hope it helps !


[This message has been edited by SuperTomate (edited 01-14-2004).]