three.jsperspectivedepth-bufferorthographic

What’s the difference between linear depth, perspective depth, and orthographic depth?


Studying the code of three.webgpu.js, I come across the terms "linear depth", "perspective depth", and "orthographic depth". I know there is a visual difference between perspective and orthographic projections, but why would the viewZ value differ amongst the different projections? Also, is linear depth just another name for orthographic depth?

I was inspired to ask this question after studying the functions viewZToOrthographicDepth and viewZToPerspectiveDepth, and noticing there is no viewZToLinearDepth function.

const viewZToOrthographicDepth = (viewZ, near, far) => viewZ.add(near).div(near.sub(far));
const viewZToPerspectiveDepth = (viewZ, near, far) => near.add(viewZ).mul(far).div(far.sub(near).mul(viewZ));

Note: I'm specifically referring to the depth (z) values between each projection type.


Solution

  • n 3D graphics, perspective and orthographic projections handle depth differently, and that’s why the viewz value changes between the two.

    Here’s the simple breakdown: Perspective Projection:

    This is what mimics real-world vision. Things farther away look smaller. The depth (z-values) isn’t linear. Distant objects are squished into a smaller range, so you lose detail as things get farther from the camera. The function viewZToPerspectiveDepth takes care of this compression by adjusting how depth is calculated for far objects. Orthographic Projection:

    Objects stay the same size, no matter how far away they are. Depth is linear here. That means it increases evenly from near to far. The function viewZToOrthographicDepth handles this linear mapping because there's no depth compression like in perspective projections. What about Linear Depth? Linear depth means the depth increases evenly, which is exactly how orthographic projection works. So, there’s no need for a viewZToLinearDepth function. The orthographic depth function is already doing that.

    In summary:

    Perspective projection squashes depth for distant objects (non-linear depth). Orthographic projection keeps everything even (linear depth).