Carat
A spectral gemstone ray tracer, written against raw WebGPU
- Year
- 2026
- Role
- Solo
- Stack
- WGSL, WebGPU, JavaScript
One 805-line HTML file. No engine, no framework, no build step, no dependencies.
Instead of carrying light as three numbers, Carat carries a wavelength for each ray and recomputes the stone's refractive index at every surface it touches, so dispersion falls out of the physics rather than being authored afterwards. The 65-facet brilliant is modelled as 65 intersected half-spaces, not a mesh, which turns intersection into one ordered loop over planes.
It holds a 36 ms median frame at 912×638 on a 2-core Ryzen 3 APU with integrated graphics. I then wrote a second, independent model of the optics in numpy and validated rendered output against it. It found nine bugs, every one of which had produced a plausible number from a broken renderer.