rasterizer_engine · C++17 + SDL2 compiled to WebAssembly

The desktop program, unchanged, in a tab

This is src/main.cpp built with Emscripten's SDL2 port instead of the system one. Every pixel is computed on the CPU into a framebuffer and handed to SDL as a single texture per frame.

-CPU per frame
-triangles drawn
800 × 600framebuffer

Pipeline switches

Each frame

  1. Model transform. Rotate each vertex about Y and X, push it 4 units into the screen.
  2. Culling. Drop faces whose normal points away from the camera: 12 triangles become 6.
  3. Flat shading. One Lambert term per face from the normal and a fixed light.
  4. Projection. mat4::perspective, then divide by w and map to pixels.
  5. Rasterize. Edge functions over a bounding box; their barycentric weights interpolate 1/w for a per-pixel depth test.

Turn culling off and nothing looks different: the depth buffer already hides the back faces. It just costs twice the rasterization to find that out.