Watching a path tracer converge

A path tracer works out the colour of a pixel by averaging random paths of light. One path is a wild guess. A thousand make a picture.

Four spheres on a pale floor: a chrome one, a large blue one, a small yellow one and a white one, lit softly from the upper left
1,024 samples per pixel, from a small JavaScript path tracer.

The same corner, sample by sample

Here’s one corner of that image at six sample counts. Each uses four times as many samples as the one before:

The error in a Monte Carlo estimate falls with the square root of the number of samples, so quadrupling the samples only halves the noise. Getting from recognisable to clean is where all the time goes.

As a video

Here’s the same render as it accumulates, from 1 to 1,024 samples on a log scale:

Six seconds, 960 × 540.

Cheating, a little

The sphere light is small, so a randomly bounced ray rarely hits it. So each time a path lands on a diffuse surface, the tracer also aims a ray straight at the light, and adds its contribution if nothing is in the way. This is called next-event estimation. Without it, even the 1,024-sample image would still be grainy.

At full scale

RT 01, my from-scratch path tracer, used the same idea at a much larger scale, on a one-million-polygon Mercedes-Benz 300 SL:

RT 01, 2019.