give this a try:

 

   // read pixel from the depth buffer

   GLfloat depth;

   glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);

 

   // retrieve depth range

   GLfloat depthRange[2];

   glGetFloatv(GL_DEPTH_RANGE, depthRange);

   float nRange = depthRange[0];

   float fRange = depthRange[1];

 

   // perspective projection parameters

   const float nearClip = 1.0, farClip = 10000.0;

 

   // compute range based on the resulting

   // depth and the near and far clipping planes

   const float depthRange = fRange - nRange;

   const float clipRange = farClip - nearClip;

 

   const float f1 = float(fabs((farClip * nearClip

       * depthRange) / clipRange));

 

   // figure range in Data Base Units

   float rangeDbu = float(fabs(f1 / (depth

       - (((nearClip + farClip) * depthRange)

           / (2.0f * clipRange))

       - ((fRange + nRange) / 2.0f))));

 

 Jeff



[EMAIL PROTECTED] wrote:

Hi,

Can someone provide me with the algorithm to convert the value of the depth buffer pixels to ranges?
Thanks

This is an e-mail from General Dynamics Land Systems. It is for the intended recipient only and may contain confidential and privileged information. No one else may read, print, store, copy, forward or act in reliance on it or its attachments. If you are not the intended recipient, please return this message to the sender and delete the message and any attachments from your computer. Your cooperation is appreciated.

_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to