world space z-coords from depth buffer...

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!

use glReadPixels and gluUnProject

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…

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 (this link is also present in another of my postings).

Hope it helps !

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

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.

But how do you determine Zb? it seemed not the depth value stored in the depth buffer.

Originally posted by SuperTomate:
[b]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 (this link is also present in another of my postings).

Hope it helps !

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