Overview
This worksheet traces a single vertex through the five coordinate spaces that every OpenGL pipeline passes through. You will identify what each space represents geometrically, label the matrices responsible for each transition, and connect the sequence to the vertex shader expression gl_Position = projection * view * model * position.
Learning Objectives
By the end of this lab you will be able to:
- By the end of this worksheet you will be able to name all five coordinate spaces in the OpenGL pipeline and describe what each one represents geometrically
- By the end of this worksheet you will be able to state which matrix is responsible for each transition between coordinate spaces
- By the end of this worksheet you will be able to trace a vertex from object space to NDC and describe the geometric change at each step
- By the end of this worksheet you will be able to explain why the transforms in gl_Position = projection * view * model * position are applied right to left
Concept
A 3D model is defined in its own local space, but it needs to appear at a specific location on a screen showing a scene that may contain many other objects. Getting there requires more than one step. Modelling, camera placement, and screen mapping are controlled by different parts of the program and can change independently: the object may move, the camera may orbit, and the viewport may be resized without affecting the others. Collapsing all of this into a single operation would make these concerns inseparable. The pipeline keeps them distinct.
The pipeline is a sequence of coordinate system changes. Each stage transforms vertices from one frame of reference to the next using a matrix multiplication. Object Space (also called local space) is the native coordinate system of the mesh, with the origin at the mesh centre by convention. The model matrix moves vertices into World Space, the shared frame where all objects in the scene coexist. The view matrix shifts everything so the camera sits at the origin looking down the negative Z axis, producing View Space. The projection matrix encodes the camera frustum and yields Clip Space, where the hardware performs clipping and the w component carries depth information. Dividing each clip-space vector by its w component produces NDC (Normalised Device Coordinates), where all visible geometry fits within the cube [-1, 1] on every axis.
In the vertex shader this entire pipeline is expressed in one line: gl_Position = projection * view * model * position. Matrix multiplication is applied right to left, so model acts on the vertex first, then view, then projection. The result assigned to gl_Position is a clip-space vector. The hardware performs the perspective divide and viewport mapping automatically after the shader runs.
Tasks
Task 1 - Tracing a Vertex Through the Pipeline
The diagram below shows the five coordinate spaces and the matrices that connect them. The worked example traces the vertex p = (1, 0, 0, 1) - the tip of the positive X axis in object space - through each transformation stage.
[ Object Space ]
|
model matrix
|
v
[ World Space ]
|
view matrix
|
v
[ View Space ]
|
projection matrix
|
v
[ Clip Space ]
|
divide by w
|
v
[ NDC ]
-
Object to World Space - model matrix: translate by (3, 0, 0)
p_world = (1+3, 0+0, 0+0, 1) = (4, 0, 0, 1)
The vertex now lives 4 units along X in the shared scene frame. Every other object in the scene is also expressed in World Space after its own model matrix is applied.
-
World to View Space - view matrix: camera at (0, 0, 5) looking at the origin
p_view = (4, 0, -5, 1)
The view matrix moves the entire world so the camera ends up at the origin looking down -Z. A camera at z = 5 is equivalent to shifting the world by -5 on Z. The x and y coordinates are unchanged here because the camera has no rotation in this example.
-
View to Clip Space - projection matrix: 90 deg FoV, aspect = 1.0, near = 1, far = 10
w_clip = -z_view = -(-5) = 5 x_clip = f * x_view = 1 * 4 = 4 (f = 1/tan(45 deg) = 1 for 90 deg FoV) y_clip = f * y_view = 1 * 0 = 0
The projection matrix scales x and y by the focal length and encodes depth into z_clip. The critical result is w_clip = 5. The z_clip value encodes a nonlinear depth that will map to the range [-1, 1] after the next step. The full derivation of the projection matrix is covered in the Perspective Projection worksheet (WS-M06).
-
Clip Space to NDC - perspective divide: divide by w_clip = 5
NDC_x = x_clip / w_clip = 4 / 5 = 0.8 NDC_y = y_clip / w_clip = 0 / 5 = 0.0
Dividing by w compresses all visible geometry into the cube [-1, 1] on every axis. NDC_x = 0.8 means the vertex is 80% of the way to the right edge of the screen. The rasteriser uses NDC coordinates to compute the final pixel position.
Task 2 - Label the Pipeline
The diagram below has all five space names and all three matrix labels removed. Use the questions below to identify each blank, then complete the five sentence starters.
[ ??? (A) ]
|
??? (1) matrix
|
v
[ ??? (B) ]
|
??? (2) matrix
|
v
[ ??? (C) ]
|
??? (3) matrix
|
v
[ ??? (D) ]
|
divide by w
|
v
[ ??? (E) ]
(A) - The mesh's native coordinate system, origin at the mesh centre: Space.
(B) - The shared frame where all objects in the scene coexist: Space.
(C) - The camera sits at the origin looking down -Z: Space.
(D) - Produced by the projection matrix; w encodes depth; hardware clips here: Space.
(E) - All visible geometry fits within [-1, 1] on every axis: .
(1) - The matrix that moves vertices from Object Space into the shared scene: the matrix.
(2) - The matrix that positions the world relative to the camera: the matrix.
(3) - The matrix that encodes the camera frustum and produces Clip Space: the matrix.
Complete: "Object Space is the coordinate system where ___."
Complete: "World Space is the shared frame where ___."
Complete: "View Space places the ___ at the origin, looking down ___."
Complete: "Clip Space exists after the ___ matrix. The w component encodes ___."
Complete: "NDC is produced by ___. All visible geometry fits within ___."
Solution
Try the tasks above before revealing the solution.