Perspective Projection
Perspective projection is the map from the 3D view frustum to the normalized device coordinate cube. It is not a linear map — it involves a rational function of depth — and understanding its construction explains several otherwise puzzling properties of the rendering pipeline: why depth precision degrades at distance, why shadow maps need a bias, and why the NDC morph must be constructed in frustum space rather than clip space.
The Frustum
The view frustum is the region of space visible to the camera. It is defined by six planes: near, far, left, right, top, bottom. In camera eye space — with the camera at the origin looking along — the frustum is a truncated pyramid:
where and are the extents at the near plane.
Similar Triangles
The core of perspective projection is the observation that a point in eye space projects onto the near plane at:
This follows from similar triangles: the ratio of to equals the ratio of to (the sign arises because in eye space). The division by is the perspective divide — the non-linear step that shrinks far objects and expands near ones.
The Projection Matrix
The GPU performs the perspective divide implicitly via homogeneous coordinates. The projection matrix encodes the transform so that:
and the perspective divide is applied after:
The matrix is derived by requiring that:
- maps at the near plane to
- maps to
- maps to (OpenGL / WebGL convention)
- so that dividing by performs the perspective divide
Substituting into condition 1 and setting :
Since we need and , the matrix column-major form is:
In column-major storage (OpenGL / GLSL convention), the flat array reads column by column — see Foundations / Matrices for the layout derivation.
For a symmetric frustum (, ) parameterized by vertical field of view and aspect ratio :
This is the matrix p5’s perspective(fov, aspect, near, far) produces.
Depth Non-Linearity
The mapping is the critical one. From the matrix:
This is a rational function of . It is not linear — most of the NDC depth range is consumed by geometry near the camera, leaving very little precision for distant geometry.
Concretely, for , :
| Eye z | NDC z |
|---|---|
| (near) | |
| (far) |
Half the NDC range ( to ) covers the first 1% of the frustum depth. This is why depth buffer precision matters, and why a large ratio causes z-fighting at distance.
The Perspective Divide is Irreversible Without
After the divide , the original is gone — encodes it non-linearly, and recovering requires the original and . This is why the NDC morph in Spaces / Perspective to NDC is constructed in frustum eye space rather than clip space: clip space positions have already been scaled by , and the interpolation would be in the wrong space.
Connection to the Bias Matrix
The depth map in shadow mapping is stored in , not . The bias matrix remaps NDC to texture coordinates:
The composition maps world positions to shadow map UV coordinates in a single matrix multiply. See Shading / Shadow Mapping for the full pipeline.
Historical Note
The perspective projection matrix in its homogeneous form was established in the early 1960s alongside the development of computer graphics as a field. Ivan Sutherland’s Sketchpad (1963) operated in a projective framework; the specific form with became standard with the OpenGL specification (Silicon Graphics, 1992), which fixed the column-major, right-handed, convention that WebGL inherits. The non-linearity of the depth mapping was known from the beginning — it is an unavoidable consequence of the rational nature of the perspective transform.
Proof: The Mapping is Rational
Claim: No affine map can simultaneously satisfy and while being derived from a matrix that produces .
Proof: The row of must produce for some constants (since is linear). After dividing by :
This is affine in , not in . The only way to make it affine in would require , which gives — a constant, independent of . No depth information would be preserved. The non-linearity is therefore unavoidable.
References
- Ahn, S. H. OpenGL Projection Matrix. Detailed derivation with diagrams.
- Shirley, P. & Marschner, S. Fundamentals of Computer Graphics. CRC Press. §7.3.
- Lengyel, E. Mathematics for 3D Game Programming and Computer Graphics. Course Technology. Chapter 4.
- Sutherland, I. Sketchpad: A Man-Machine Graphical Communication System. MIT PhD thesis, 1963.