FREE LESSON · Graphics & simulation · 2 OF 5
Perspective projection and clipping
Perspective projection and clipping: Explain why distant objects shrink and why division needs a valid domain.
Prerequisites: Coordinate transformations and ratios.
Learning objectives
- Calculate a pinhole projection.
- Distinguish perspective from orthographic projection.
- Explain clipping before perspective division.
Projection discards a dimension
A camera maps three-dimensional geometry to a two-dimensional image. Under a simple pinhole model with camera looking along positive z and image plane at distance f, a point (x,y,z) with z greater than zero projects to (fx/z,fy/z). Similar triangles give this relationship. Other graphics conventions look along negative z; formulas must match the chosen convention.
For f=2, point (3,1,6) projects to (1,1/3). Doubling all three coordinates leaves the projected point unchanged: points along the same ray through the camera share an image location. Doubling only z halves the image coordinates, producing the familiar shrinking of distant objects.
Orthographic projection drops or linearly maps depth without dividing by z. Parallel lines remain parallel, and equal-size objects do not shrink with distance. It is useful for diagrams and some modeling tasks, but it represents a different camera model.
The viewing volume is part of the model
A practical camera has a finite field of view and near and far bounds. Geometry outside the visible volume is clipped. A triangle crossing a boundary may need to be replaced by a smaller polygon; simply discarding every triangle with an out-of-bounds vertex removes visible geometry.
Perspective pipelines often use homogeneous clip coordinates. Clipping is performed against the appropriate homogeneous inequalities before dividing by w. Dividing points at or near zero w can create unbounded coordinates and incorrect interpolation. The details of depth range and handedness depend on the graphics API and chosen matrices.
Trace a near-boundary crossing
Imagine an edge whose endpoints lie on opposite sides of the near plane. The visible portion begins where the edge intersects that plane. Compute the interpolation parameter from the signed plane distances, then create the intersection vertex and interpolate its attributes consistently. Keeping the entire edge can produce invalid projection; deleting it entirely loses the visible segment.
Depth and precision
A depth buffer stores a transformed depth value used to resolve visibility. Perspective depth is generally nonlinear in camera-space distance. An unnecessarily extreme ratio between far and near distances can waste precision in common fixed-point depth arrangements. Reversed-depth techniques and floating-point buffers change the precision behavior, so avoid universal claims that ignore the implementation.
Validate a camera with points on the center ray, known image-plane boundaries, and near-plane crossings. Separate world-to-camera transformation, projection, clipping, and viewport mapping. Each stage has a different contract, and naming those stages makes errors much easier to locate.
Practice problem
For f=3, project (2,4,6) and (2,4,12) using the positive-z convention. Explain why a triangle with one vertex behind the near plane should not always be discarded.
Worked solution
The first point maps to (1,2); the second maps to (0.5,1). Doubling depth with fixed x and y halves the projected coordinates. A triangle crossing the near plane may have a visible portion. Clip its edges against the plane, introduce intersection vertices, and triangulate the remaining polygon as needed. Discarding the entire triangle loses valid visible geometry, while projecting the unmodified triangle can introduce invalid or extreme coordinates. The clipping and attribute interpolation must use a consistent coordinate convention.
Check your understanding
Which projection makes equal-size distant objects appear smaller?
- Ordinary orthographic projection.
- Perspective projection.
- Translation alone.
- A pure color transform.
Explanation
Perspective divides image coordinates by depth.
Why clip before perspective division?
- To avoid invalid division and preserve the visible part of crossing primitives.
- To make every triangle invisible.
- To remove all depth information.
- To turn points into textures.
Explanation
Homogeneous clipping handles the valid viewing volume before division by w.
Primary reading
- Computer Graphics course and projects: UC Berkeley CS 184