Re: glReadPixels
Rémi Arnaud (remi++at++remi.asd.sgi.com)
Tue, 14 Jan 1997 16:21:27 -0800 (PST)
WILLIAM_MARINELLI++at++ntsc.navy.mil wrote:
>
> I'm posting this to both groups because it's a vega app but seems
> applicable to both in the context of a post draw callback.
>
> Opinions about using glReadPixels to approximte the distance an object
> is away from the eyepoint (simulate a laser range finder)?
>
> I use
>
> glReadPixels(640,512,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,f);
should be ................................................&f
>
> ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^
> middle 1 z buffer value
> of pixel
> screen
>
>
> then try to scale it appropriately with the near and far clip planes.
>
> f returns with a float value between 0 and one. I suppose that the
> Ifinite Reality Floating point z buffer has been accounted for when
> this float is spit out.
>
> At this point the returned depth buffer value is scaled quite large;
> ie, you pitch down to the ground and the returned value is still quite
> high (.4).
If you use a perspective matrix, you have to apply the inverse of the
matrix tu find z (a simple scale is not enough )
z = 2*far*near / (far+near - (far - near) * (2. * f -1.));
_ / _ _
|_) _ ._ _ o /\ |_)|\ | /\ | || \
| \(/_| | || /--\| \| \|/--\|_||_/
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
Submissions: info-performer++at++sgi.com
Admin. requests: info-performer-request++at++sgi.com
This archive was generated by hypermail 2.0b2
on Mon Aug 10 1998 - 17:54:20 PDT