QGLViewer - Depthbuffer z distance



  • Hi, I'm to use Depthbuffer to retrieve the Z distance of objets in my OpenGl scene using QglViewer.
    I'm using the following code:
    glReadPixels(nStartX, nStartY, nWidth, nHeight, GL_DEPTH_COMPONENT, GL_FLOAT, f_Depth);
    This retrieves the Depth Component.
    BUT I'm reading on http://www.opengl.org/resources/faq/technical/depthbuffer.htm
    "The depth buffer precision in eye coordinates is strongly affected by the ratio of zFar to zNear, the zFar clipping plane, and how far an object is from the zNear clipping plane."
    So, this make that my Depth Value are not linear. So I can't use theses values the have a real Z matrix of the scene.
    This cause many problem since I can't set a "unit" to these value.

    My usage is to use these Depth Matrix to use the technology SLAM(Simultaneous localization and mapping )
    So I need real distance in the matrix, not perspective value that mean nothing.

    If anyone have any idea to retrieve the good Z value of the pixel, I would be so happy.

    The first link I gave explain in some way how the calcul is done, but I'm not able to understand the functions given and how to retrieve the REAL Z distance...

    Thanks!!!!



  • I finally found the answers after a couple of hours of googling:
    bufferToCamera[zb_, near_, far_] := far * near / (zb * (far - near) - far);
    where zb = z from buffer
    bufferToCamera= z from camera
    http://olivers.posterous.com/linear-depth-in-glsl-for-real


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.