The Graphics Pipeline
The graphics pipeline is the complete sequence of operations from 3D vertex data to the final pixels on screen. Modern GPUs implement this pipeline in hardware for extreme performance.
Pipeline Overview
Graphics Pipeline Stages:
βββββββββββββββ
β Vertex β Transform vertices
β Shader β (model-view-projection)
ββββββββ¬βββββββ
v
βββββββββββββββ
β Primitive β Assemble primitives
β Assembly β (triangles, lines, points)
ββββββββ¬βββββββ
v
βββββββββββββββ
β Clipping β Remove primitives
β β outside view volume
ββββββββ¬βββββββ
v
βββββββββββββββ
β Rasterizer β Convert to fragments
β β (potential pixels)
ββββββββ¬βββββββ
v
βββββββββββββββ
β Fragment β Compute final pixel
β Shader β color and depth
ββββββββ¬βββββββ
v
βββββββββββββββ
β Per-Frag β Depth test, blending,
β Operations β stencil test
ββββββββ¬βββββββ
v
βββββββββββββββ
β Framebufferβ Final image
β Output β
βββββββββββββββ
Vertex Processing
Vertex Shader (programmable):
- Transforms vertex positions
- Computes per-vertex lighting
- Passes data to fragment shader
gl_Position = projection * view * model * vec4(position, 1.0);
fragColor = lightingCalculation(normal, lightDir);
Fixed-function vertex operations:
- Model-view transformation
- Projection
- Viewport mapping
Rasterization
Converts primitives to fragments:
Input: Triangle vertices (after clipping)
Output: Fragments (potential pixels)
For each triangle:
1. Compute bounding box
2. For each pixel in bbox:
- Test if inside triangle
- Interpolate vertex attributes
(color, normal, texcoord, depth)
- Generate fragment with interpolated data
Fragment Processing
Fragment Shader (programmable):
- Computes final color of each fragment
- Texture sampling
- Per-pixel lighting
- Effects (fog, shadows, reflections)
outColor = texture(texCoord) * lightColor;
Per-fragment operations:
- Depth test (Z-buffer)
- Stencil test
- Blending (transparency)
- Logical operations
Early Depth Testing
An optimization where depth testing is performed before the fragment shader. Fragments that fail the depth test are discarded early, saving shader computation.
Standard:
Fragment Shader β Depth Test
Optimized:
Depth Test β Fragment Shader (only if depth test passes)
Limitation: Fragment shader cannot modify depth
(if it does, early depth test is disabled)