I'd like to retrieve the depth buffer from my camera view for a 3D filtering application. Currently, I'm using glReadPixels to get the depth component. Instead of the [0,1] values, I need the true values for the depth buffer, or true distance to the camera in world coordinates.
I tried to transform the depth values by the GL_DEPTH_BIAS and GL_DEPTH_SCALE, but that didn't work.
glReadPixels(0, 0, width_, height_, GL_DEPTH_COMPONENT, GL_FLOAT, depth_buffer);
glGetDoublev(GL_DEPTH_BIAS, &depth_bias); // Returns 0.0
glGetDoublev(GL_DEPTH_SCALE, &depth_scale); // Returns 1.0
I realize this is similar to Getting the true z value from the depth buffer, but I'd like to get the depth values into main memory, not in a shader.