06 · Ray tracing

A Whitted-style ray tracer in a fragment shader: one primary ray per pixel, shadow rays toward the light, and mirror reflection rays up to a maximum depth. Drag to orbit. Companion to notes/11.

How it is built

The only geometry is one triangle that covers the whole screen. Its fragment shader runs once per pixel, builds the primary ray from the camera basis (the same u, v, n as Mat4.look_at), and intersects it with three spheres and a plane. Recursion is unrolled into a loop: with pure mirror reflection, each level of the ray tree has a single branch.