Master the fundamental concepts of software rasterizer through this focused micro-challenge.
A triangle is the fundamental primitive in computer graphics. Unlike arbitrary polygons, triangles are always convex, always planar, and produce unambiguous interior points. Every 3D model decomposes into triangles before rendering.
Rasterizing a triangle means determining which pixels lie inside it. The scanline edge-walk algorithm is the classic CPU approach and the conceptual ancestor of hardware rasterizers.
As you move down one scanline, each edge's x-intersection advances by a constant dx/dy (inverse slope). The triangle splits into a top half and bottom half at the middle vertex.
cLoading…
For example, a triangle with vertices (2,1), (8,1), (5,7) fills scanline y=4 between x=3 and x=7. GPUs parallelize this across tile rasterization units, but the geometry is identical.
You will implement scanline edge-walking and output the pixel coordinates that would be filled. This task does not require a framebuffer display. Getting edge interpolation correct here is the direct prerequisite for barycentric tests and z-buffering later in this subtrack.
Write a C program that fills a triangle using the scanline edge-walk algorithm.
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