graphics · sub-star
rasterizer_engine
software rasterizer in C++: a shaded, depth-tested cube, every pixel on the CPU.
readme
A rasterizer in C++ that takes a mesh through a 4x4 perspective matrix, culls and shades each face, and fills and depth-tests every pixel into a CPU framebuffer that SDL2 only uploads. It is the pipeline a GPU normally hides, written out explicitly, and the counterpart to photon_tracer, which approaches the same problem from the opposite direction.
artifact
not simulated: 3d points through a perspective matrix, projected live.
signal log
- 4x4 perspective projection and perspective divide applied by hand, with y flipped into screen space.
- back-face culling from the face normal and the ray to the camera, and flat Lambert shading per face.
- edge functions over a bounding box: divided by the signed area they are barycentric weights, which decide coverage and interpolate a 1/w depth buffer.
- one texture upload per frame instead of a draw call per pixel: 0.51 ms of CPU work per 800x600 frame.
- the same main.cpp builds against Emscripten’s SDL2 port and runs in a browser tab.
built with
C++17SDL2WebAssembly