A software rasterizer in Rust.
Prism draws real 3D triangles on the CPU. No GPU, no graphics crates. Just a framebuffer, a z-buffer, and barycentric math turning vertices into pixels.
A small, from-scratch 3D rendering pipeline you can read start to finish in one sitting. It takes a scene of triangles, transforms them through a model, view, and projection matrix, rasterizes each one with barycentric coordinates, resolves overlaps with a z-buffer, and shades faces with a simple directional light. The output is a binary PPM image, so there is no image codec to pull in either.
- Vertices are moved from model space to world space to camera space to clip space by a chain of 4x4 matrices, written by hand in
src/vec.rs. - Projection divides by w to land in normalized device coordinates, then maps to pixel coordinates on the screen.
- Rasterization walks the bounding box of each triangle and uses barycentric coordinates to decide which pixels are inside it (
src/raster.rs). - The z-buffer keeps, for every pixel, the depth of the nearest surface drawn so far, so triangles behind others get correctly hidden.
- Shading is flat per triangle: a dot product between the face normal and a fixed light direction sets its brightness.
- Output is written as PPM (P6), a plain binary format any image viewer or
convertcan open.
cargo run -- render -o out.ppm
cargo run -- render -o out.ppm --width 800 --height 600
This renders the built-in demo scene, a rotated, lit cube, and writes it to the given path.
cargo test
Covers triangle fill (interior pixels set, exterior pixels clear), z-buffer depth resolution (the nearer triangle wins an overlap), and PPM output (correct header and byte length for the given dimensions).
By Pavan Nallamothu.