No history yet

Mathematical Pipeline Transformation

From Local Space to World Space

Every 3D model starts in its own little universe, called local space or model space. The model's center is at the origin (0, 0, 0), and all its vertices are defined relative to that point. To place this model into a larger scene with other objects, we need to move it into world space. This is done with a model matrix.

This matrix is a combination of three fundamental transformations: scale, rotation, and translation. By multiplying them together, we create a single 4x4 matrix that takes a vertex from its local coordinates and places it correctly in the shared world.

Mmodel=MtranslationMrotationMscaleM_{model} = M_{translation} \cdot M_{rotation} \cdot M_{scale}

But why a 4x4 matrix for 3D space? A 3x3 matrix can handle scaling and rotation perfectly well, but it can't perform translation through multiplication. To solve this, we use , which add a fourth component, w, to our 3D vectors (x, y, z). For points in space, w is set to 1, turning our vector into (x, y, z, 1). This simple addition unlocks the ability to represent translation as a matrix multiplication, unifying all our transformations into one elegant system.

The Camera's Perspective

Once all our objects are arranged in world space, we need to view them from a specific point—the camera. The view matrix transforms the entire world so that the camera is at the origin, looking down a specific axis (usually the negative z-axis). This simplifies later calculations by putting everything into a consistent, camera-centric coordinate system called view space or camera space.

A common way to construct this matrix is with a . Instead of defining a rotation and a translation directly, we specify three things: the camera's position (eye), the point it's looking at (target), and a vector indicating which way is 'up' (up).

Projecting to a 2D Plane

Now that our scene is in view space, we need to simulate how a 3D world is projected onto a 2D surface. This is the job of the projection matrix. It takes points in 3D view space and transforms them into 4D clip space. This step is what creates the illusion of perspective.

The most common type is a perspective projection, which defines a viewing volume called a . Anything inside this frustum is visible. Anything outside is 'clipped' and discarded. The shape of the frustum is defined by a field of view (FOV), an aspect ratio, and near and far clipping planes.

After the projection matrix transforms a vertex into clip space, its coordinates are (x_clip, y_clip, z_clip, w_clip). The w component is no longer 1; it now holds the depth information from before the projection. To get our final 2D coordinates, we perform the perspective divide.

xndc=xclip/wclipyndc=yclip/wclipzndc=zclip/wclipx_{ndc} = x_{clip} / w_{clip} \\ y_{ndc} = y_{clip} / w_{clip} \\ z_{ndc} = z_{clip} / w_{clip}

Normalized Device Coordinates are a standardized, cube-shaped space where x, y, and z values all range from -1 to 1. This is the final coordinate system before the coordinates are mapped to pixels on your screen.

Quiz Questions 1/5

What is the primary purpose of a model matrix in the 3D rendering pipeline?

Quiz Questions 2/5

Why are 4x4 matrices and homogeneous coordinates used for 3D transformations instead of 3x3 matrices?

This sequence of matrix multiplications—Model, View, then Projection—forms the core of the geometry stage in the rendering pipeline. It's a powerful and efficient system for taking abstract 3D data and preparing it for the screen.