WASM RaytracerRust → WebAssembly
Three reflective spheres on a checkerboard, ray-traced per pixel — shadows, reflections and all — by a raytracer written in Rust and compiled to wasm32-unknown-unknown. There's no wasm-bindgen here: Rust exposes two functions over a raw linear-memory ABI, JS blits the framebuffer straight out of WebAssembly memory onto the canvas. The whole renderer is 22 KB of wasm.
booting…
Loading WebAssembly…
What you're looking at
Every frame, Rust shoots one ray per pixel from an orbiting camera into the scene, finds the nearest sphere or the ground plane, then adds a diffuse term, a hard shadow ray toward the light, a specular highlight, and up to two reflection bounces. Gamma-corrected colours are packed as RGBA into aVec<u8> that lives in WebAssembly's linear memory. JavaScript never touches the pixels — it just wraps that memory in a Uint8ClampedArray and calls putImageData. Bump the resolution to feel the cost scale, and watch the FPS.
Rust source (src/lib.rs)
Click “View Rust source” to load…