Prism

Software rasterizer · Rust

Real triangles.
Drawn on the CPU.

Prism is a 3D rendering pipeline written from scratch in Rust. No GPU, no graphics crates. Just a framebuffer, a z-buffer, and barycentric math turning vertices into pixels.

View on GitHub How it works

cargo run -- render -o out.ppm

Live in the browser.

drag to orbit · rasterized on the CPU, per pixel

Speed {{ speedLabel }}

Barycentric fill,
pixel by pixel.

Each triangle walks the bounding box of its three screen-space vertices. For every pixel center, three edge functions decide whether the point lies inside; their signed ratios are the barycentric weights.

Those same weights interpolate depth across the face, so every covered pixel arrives at the depth test with a z of its own.

let l0 = w0 / area;
let l1 = w1 / area;
let l2 = w2 / area;
let z = l0 * v0.z
      + l1 * v1.z
      + l2 * v2.z;

fb.set_with_depth(x, y, z, color);

The z-buffer
settles overlaps.

One depth value per pixel, holding the nearest surface drawn so far. A fragment writes color only if it is closer, so triangles behind others are hidden regardless of the order they were submitted in.

Depth test per pixel
Shading flat, directional
Transforms hand-written 4×4
Output PPM (P6)
Dependencies clap