Master the fundamental concepts of software rasterizer through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksA modern GPU rasterizes millions of triangles per frame. Most triangles are small and touch only a tiny screen fraction. Testing every pixel on the full framebuffer for every triangle wastes work and destroys cache locality.
Tile-based rasterization divides the screen into rectangles (typically 8x8, 16x16, or 32x32 pixels). The rasterizer first finds which tiles a triangle overlaps, then runs fine per-pixel tests only inside those tiles.
cLoading…
For example, on a 32x32 screen with 8x8 tiles, a small triangle in the top-left corner might touch only tile (0,0) instead of all 16 tiles. Mobile GPUs (ARM Mali, PowerVR, Apple) extend this with tile-based deferred rendering, keeping intermediate results in on-chip memory to cut VRAM bandwidth.
You will implement tile assignment for three triangles on a 32x32 screen divided into 4x4 tiles of 8x8 pixels. This task asks you to print which tiles each triangle touches. The cache-friendly chunking you model here is why phones render complex 3D scenes without draining the battery on constant memory traffic.
Tile-based GPUs (and parallel software rasterizers) first bin triangles: the screen is cut into T×T tiles, and each triangle is added to the list of every tile it might touch, so tiles can later be rasterized independently. Compare two binning tests, then check the bins against real pixel coverage:
# starts a comment line.
cLoading…
The tile grid is ceil(W/T) × ceil(H/T), at most 16 × 8.
(tx·T, (tx+1)·T) × (ty·T, (ty+1)·T). Merely touching its boundary does not count.NAME: degenerate, not binned.maxx ≤ x0, minx ≥ x1, maxy ≤ y0 or miny ≥ y1.E(a→b, corner) = (bx-ax)(cy-ay) - (by-ay)(cx-ax) ≤ 0 at all four tile corners, which means that edge separates them.ay == by && bx > ax) or left (by < ay) edges. A bin with no covered centre is marked *.cLoading…
(off screen) when there are none. Plurals: tile(s), pixel(s), bin(s).+ above 9.screen: W (1-128) H (1-64), tile: 4, 8, 16 or 32tri: NAME X0 Y0 X1 Y1 X2 Y2, tri: coordinates within +-1000, at most 16 trianglesbin: at most 16 x 8 tiles (use larger tiles)unknown command XInput:
cLoading…
Output:
cLoading…
Hidden tests cover two triangles tiling a screen exactly, degenerate and off-screen triangles, a sliver whose only pixel centre lies on its diagonal, a single large tile, and argument errors.