Conversion Between OpenGL Depth-Buffer Z and Actual Screen-Space Depth
Kenneth E. Hoff III
(adapted from notes from Bill Mark)

OpenGL depth values are normalized values in [0,1] that represent the range between the near and far planes. The actual screen-space depth is the distance from the eye-plane through Z=0. The near and far planes are at Z=Zn and Z=Zf respectively. Basically, the center-of-projection - or eye - is at the origin and the viewing direction is down the positive Z axis.

Given the screen-space depth Z and the distance to the near and far planes (Zn and Zf), we can compute the OpenGL normalized depth value as follows: by solving for Z, we can determine the inverse conversion: