Computer graphics
Rasterization: how triangles become pixels
The GPU path. Same picture, opposite direction — and the reason real-time works.
Rasterization inverts the ray tracer's question. Instead of asking "what does this pixel see?", it asks "which pixels does this triangle cover?" That sounds like the same work, but it has one enormous advantage: the work is naturally parallel over triangles, and each triangle only touches a small screen region.
The pipeline, in order, with the one thing each stage is for:
Vertex shader — transform each vertex from model space to clip space. This is where the famous MVP matrix lives: Model → View → Projection.
Clipping — clip primitives against the view frustum.
Perspective divide + viewport — divide clip coordinates by `w`, then map to render-target coordinates.
Triangle setup / rasterize — determine coverage and generate fragments for covered samples.
Fragment shader — shade generated fragments; with multisampling, one pixel can contain multiple covered samples.
Depth/stencil tests and blending — tests decide which fragments pass; if blending is enabled, passing shader output is combined with the existing render-target value before writing.
// The MVP chain, written out (column-major, so it reads right-to-left)
clip = Projection * View * Model * vec4(pos_model, 1.0)
// After the vertex shader you have clip-space positions.
// The GPU then does, per vertex:
ndc = clip.xyz / clip.w // <- perspective divide, this is what makes far things small
// And per pixel, the rasterizer interpolates attributes like uv/normal
// with PERSPECTIVE-CORRECT weights (dividing by w again). This is why
// a texture does not swim when a floor recedes into the distance.For a first teaching implementation, brute-force ray tracing is conceptually compact but expensive as scene complexity grows. Rasterization has more pipeline rules, while hardware can process many projected triangles efficiently. Production systems make both approaches substantially more sophisticated.
What does the perspective divide achieve?
Why is perspective-correct interpolation needed?
Rasterization
Triangles → covered pixels; parallel and cheap to run.
MVP matrix
Model · View · Projection — model space to clip space.
Perspective divide
Divide by w; this is what makes distance look like distance.
Z-fighting
Nearly-coplanar surfaces flipping depth order due to limited precision.
Review cards
Rasterization
Triangles → covered pixels; parallel and cheap to run.
MVP matrix
Model · View · Projection — model space to clip space.
Perspective divide
Divide by w; this is what makes distance look like distance.
Z-fighting
Nearly-coplanar surfaces flipping depth order due to limited precision.
Sources for this lesson
Below are the references, editions and original links for further reading and checking.
Tomas Akenine-Möller, Eric Haines, Naty Hoffman
4th edition
实时渲染的参考手册。第 4 版新增 VR/AR 一章,并覆盖全局光照与曲线曲面。配套站点持续更新书目。
DocsWebGL Fundamentalsfree
Gregg Tavares
持续更新
GPU 管线与光栅化的官方级入门读物,全部可交互运行。
DocsDirect3D Rasterizer Stagefree
Microsoft Learn
Direct3D 11 documentation
Documents rasterization rules, clipping, viewport mapping, multisampling and per-pixel attribute interpolation.
DocsDirect3D Output-Merger Stagefree
Microsoft Learn
Direct3D 11 documentation
Documents depth/stencil tests, render-target writes, multisample behavior and blending in the output-merger stage.
Lights up these nodes in the hub:b-02 · b-03