Michael Jones (mtj++at++babar)
Tue, 27 Dec 1994 16:42:10 -0800
:I am attempting to write a range-finding routine as a post-pfdraw function
:in performer based upon the values contained in the Z-Buffer after pfdraw
:has completed. The values my routine is returning are inconsistent and
:non-intuitive. I expect to see values appoaching farplane +nearplane at their
:largest and nearplane at their smallest, but am not getting anything like
this.
:When I'm looking at things far away, the range values seem to make sense.
:However, when I'm looking at things up close, the values still remain large
:(close to the value of farplane).
If you have a RealityEngine system in its deluxe anti-aliasing mode
(MultiSample mode) then there is no Z-value available to be read.
Once you disable MultiSampling (or if you lack it to start with) then it
reduces to a problem of decoding the Z-buffer contents after you read
them back. It will save you time if you consult the little equation below.
This is how to interpret (decode) the Z-buffer values which you are
seeking. It can be tedious to work out by hand. ;-)
z = value in z buffer after rendering (input)
range = distance to pixel in database units (output)
np = distance to near clipping plane (database units)
fp = distance far clipping plane (database units)
nz = near-clip z value (lsetdepth)
fz = far-clip z value (lsetdepth)
where you (or Performer on your behalf) did:
lsetdepth(nz, fz);
you must evaluate this equation for each Z-buffer value:
fp*np(fz-nz)
------------
fp-np
- range = --------------------------
(fp+np)(fz-nz) fz+nz
z - -------------- - -----
2(fp-np) 2
--Be seeing you, Phone:415.390.1455 Fax:415.390.2658 M/S:8U-590 Michael T. Jones Silicon Graphics, Advanced Graphics Division mtj++at++sgi.com 2011 N. Shoreline Blvd., Mtn. View, CA 94039-7311
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:50:46 PDT