The Viewing Pipeline and Projections

Chapter 9: The Viewing Pipeline and Projections

Rendering a 3D scene involves converting 3D coordinates into a 2D image. This transition is handled by the viewing pipeline and projection matrices.

The 3D Viewing Pipeline

The viewing pipeline is a sequence of transformations that takes an object from its local model space to the final screen space.

  1. Model Transformation: Objects from local space (around their own origin) are placed into world space.
  2. Viewing (Camera) Transformation: The entire world is moved so the camera sits at the origin (0,0,0)(0, 0, 0) looking down the z-z axis (standard in many systems).
  3. Projection Transformation: The 3D view space is projected onto a 2D plane (clip space).
  4. Perspective Division: Each coordinate (x,y,z,w)(x, y, z, w) is divided by ww to account for perspective.
  5. Viewport Transformation: The coordinates are mapped to the actual pixel dimensions of the window on the screen.

Projection Types

Projection is the process of mapping a higher-dimensional space (3D) to a lower-dimensional space (2D).

Orthographic (Parallel) Projection

In an orthographic projection, parallel lines in 3D remain parallel in the 2D image. Size does not depend on distance.

  • View Volume: A rectangular box (frustum).
  • Applications: Engineering drawings, blueprinting, and technical illustrations.

Portho=[2rl00r+lrl02tb0t+btb002fnf+nfn0001]P_{ortho} = \begin{bmatrix} \frac{2}{r-l} & 0 & 0 & -\frac{r+l}{r-l} \\ 0 & \frac{2}{t-b} & 0 & -\frac{t+b}{t-b} \\ 0 & 0 & -\frac{2}{f-n} & -\frac{f+n}{f-n} \\ 0 & 0 & 0 & 1 \end{bmatrix} Where l,r,b,t,n,fl, r, b, t, n, f represent Left, Right, Bottom, Top, Near, and Far planes.

Orthographic (Parallel Lines)

Perspective Projection

Perspective projection mimics how the human eye and cameras perceive the world. Parallel lines appear to converge at a "vanishing point." Objects appear smaller as their distance from the camera increases.

  • View Volume: A truncated pyramid called a frustum.
  • Applications: Most realistic 3D games, movies, and simulations.

The key feature of perspective projection is the perspective divide. The ww component of the homogeneous coordinate becomes the distance from the camera. Dividing xx and yy by ww creates the perspective effect.

Camera Perspective Frustum

Clipping

Before we display anything, we must "clip" the scene against the view frustum.

  • Clipping Volumes: Any part of an object that falls outside the Left, Right, Top, Bottom, Near, or Far planes is discarded.
  • Near Plane Clipping: Essential for preventing objects from being too close and distorting or passing behind the camera.

Summary

The projection pipeline is the final bridge between our abstract 3D mathematical models and the 2D grid of pixels on our screens. Choosing between orthographic and perspective projections can fundamentally change the aesthetic and functional characteristics of a digital experience. Understanding how to construct these matrices is the key to creating a sense of depth and realism in computer graphics.