Master the fundamental concepts of software rasterizer through this focused micro-challenge.
After projection and perspective division, triangle vertices live in normalized device coordinates. Attributes like color, texture coordinates, and normals are not linear in screen space under perspective projection. Linear interpolation stretches values near the camera and compresses them far away.
For example, a textured wall viewed at a steep angle shows visible warping if you interpolate UVs linearly across the triangle. PlayStation 1 titles skipped perspective correction to save cycles, and the swimming textures were a signature artifact.
The fix: interpolate A/w and 1/w in screen space, then divide:
cLoading…
Here u, v, w are screen-space barycentric coordinates and w0, w1, w2 are homogeneous w values from the projection matrix. Any attribute divided by w becomes linear in screen space; the final division corrects perspective distortion.
You will compare linear and perspective-correct color interpolation at a test point with known barycentric coordinates and w values. This task asks you to print both results side by side so the difference is visible. Anyone writing a WebGL fallback or software renderer must implement this 1/w division themselves.
Write a C program that compares linear and perspective-correct interpolation of a color attribute across a triangle.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github