DemoHut

NDC curve

The z value in NDC (stored in depth buffer) is not linear to the original z value:

z_ndc = -(2*f*n/(f-n)) * (1/z) + (f+n)/(f-n)

where n is the near plane, and f is the far plane.

Camera view

External view

NDC cube

Here I keep the distance between the near plane and the far plane constant at 100. When the near plane is set very small, almost all the z values fall into a narrow range close to 1, and the balls are squashed onto the far plane. In particular, if the near plane is set 0.00001, z-fighting would appear distinctly. A solution to this is using a non-linear (like logarithmic) z buffer. Anyway one should consider setting a reasonable range for the frustum in the first place.

All demos have been tested on Microsoft Edge/macOS.