How Path Tracing Works
Every pixel of a rendered film answers the same question: how much light lands here? Path tracing answers it with dice. Two short acts — first one ray at a time, then a few million.
Act 1 The story of one ray
Here is a room in flatland: a lamp in the ceiling, a red wall and a green wall, a blue box, a mirror, and a brass circle. On the left sits a camera with its strip of pixels — the image it is trying to form.
Path tracing works backwards. Instead of chasing light out of the lamp, fire a ray from the camera through a pixel and follow it. At every surface it picks up that surface's color and bounces on. If it reaches the lamp, the journey pays off: the pixel receives a bright sample tinted by everything the path touched. If it runs out of bounces first, the pixel receives black. A pixel's color is nothing more than the average of all its samples so far.
Tap a cell in the pixel strip to aim at a different pixel.
Now drag Max bounces down to 1 and fire a while: only direct light survives, and any spot the lamp cannot see goes pure black. Give the rays their bounces back and those shadows fill in with soft, borrowed light — the red wall lends its color to the floor beside it. That filling-in is global illumination. It is not an added effect; it is simply what more bounces compute.
The brass circle is switchable. Diffuse scatters a ray anywhere in the half-circle above the surface, weighted toward the perpendicular. Mirror is deterministic — one exact reflection, every time. Glossy is a mirror with jitter: a narrow lobe of directions around the reflection. Watch how the same incoming ray behaves under each.
Honest footnote: this act is genuinely two-dimensional, so “diffuse” importance-samples a cosine over a half-circle rather than a hemisphere, and anything that lives on solid angles is illustrative. The intersections, the occlusion, and the bounce-until-you-find-the-lamp logic are the real algorithm, unstaged.
Act 2 Now do it a few million times
The same idea in 3D, at full speed. This is a real path tracer running in your browser — no video, no precomputed anything. Every pixel below is the running average of its own samples, a few thousand new camera rays per frame.
It starts as static. With only a handful of samples, each pixel's average is mostly luck — that is variance, and it looks like noise. The noise is not wiped away by a filter; it dissolves, because averaging independent samples shrinks the error like 1/√N.
Look at the left cheek of the white box: it turns faintly pink, because light arrives there by bouncing off the red wall first. The mirror sphere carries the whole room on its skin. Set Max bounces to 1 and both vanish — direct light only, and the mirror goes black, since a reflection needs a second bounce. Wind it back to 8 and the room glows again.
Two honest notes. First, this tracer also aims one ray at the lamp from every diffuse bounce — next-event estimation — a standard technique that changes nothing about the answer, only how fast the noise fades. Second, production renderers stack many more accelerations on top: importance sampling everywhere, bounding volume hierarchies, machine-learned denoisers. What you are watching is the honest, slow, beautiful core they are all built on.
If you are reading this with a screen reader: the captions are the complete lesson, in order. The canvases visualize them, and the sight of noise melting into an image has no faithful non-visual equivalent — the sample counter above is its honest proxy.