Suppose I use glReadPixels() to read the depth of a pixel from the depth buffer. What are the units of this? Is it the distance from the camera? Or the distance from the near clip plane? And is the distance normalized to clip space, or in real units?

Whatever you want them to be. From the documentation:

Each component is converted to floating point such that the minimum depth value maps to 0 and the maximum value maps to 1. Each component is then multiplied by GL_DEPTH_SCALE, added to GL_DEPTH_BIAS, and finally clamped to the range 0 1.

Beyond the given ranges, it is up to you to interpret the data as whatever "units" you see fit, depending on the data you wrote into the depth buffer in the first place and what it means to you.

• So would a value of 0 be at the near clip plane? And a value of 1 be at the far clip plane? – Karnivaurus Jul 29 '15 at 16:45
• @Karnivaurus Yes, 0 is near, and 1 is far. – Alexandre Desbiens Jul 29 '15 at 17:05
• @Karnivaurus Note though, the depth in the depth-buffer is not linear. – tkausl Jul 29 '15 at 17:28
• Oh, so its not just (depth - near_plane) / (far_plane - near_plane)? – Karnivaurus Jul 29 '15 at 17:30
• No, i don't know the exact equation (its the perspective-matrix which performs it i guess) but its a equation which allows near z-values to be more exact and further values to be less exact. So the first 20% of depth from z-near to z-far already take ~80% of the buffer (values 0.0 to 0.8) to prevent z-fighting and wrong results in near objects, at the expense of inaccurate depth-values for further objects. – tkausl Jul 29 '15 at 17:45