Sampling
Every random number the path tracer uses comes from a sampler, addressed by three things: the pixel (through a per-pixel seed), the sample index and a dimension. Changing the sampler changes how the noise looks and how fast it falls; the mean of the image stays the same.
Samplers
Set with integrator.sampler:
How Owen-Sobol is laid out
The sampler hands out pairs of numbers. Each pair has its own seed, shuffle and scramble, so pairs are independent of each other, and the first 2^m samples of one pair are well stratified. Sample counts that are powers of two make the most of that.
Pairs are hashed, not tabulated, so a deep path costs no table. The map is in dimensions.ts, with a TypeScript twin of every sampler.
Seeds and the sample index
setSeed(seed)sets the scrambling seed. Each seed gives an independent realisation of the noise. Two renders with the same seed and the same sample count use the same random numbers.- The sample index is the number of sample passes since the last
reset. It is the sample counterpt.samples.resetsets it back to 0, so a restarted image repeats the noise pattern of the first one; give it a new seed if that matters. - In frame mode (
integrator.frame) the sample index is the frame index: it advances with eachencode, andsetFrameIndexsets it, for example to replay a frame.
pt.setSeed(7);
pt.reset(encoder); // sample index back to 0
pt.encode(encoder, 64); // samples 0..63 of seed 7
Blue noise
The 'bluenoise' sampler reads the first few pairs of every sample from a blue-noise texture at the pixel, and shifts the texture every frame so the average over frames still converges to the right image. Deeper pairs fall back to Owen-Sobol.
The textures are our own: we generate them (void-and-cluster and a joint two-channel optimisation) rather than use third-party blue noise. The sampler needs a two-channel, single-slice, power-of-two texture: gf-vec2-64 or gf-vec2-128. Both ship in @pmndrs/raytracer, and loadBlueNoise decodes one without a fetch (each is a separate module, so a bundle carries only the one you load):
import { loadBlueNoise } from '@pmndrs/raytracer';
import { PtMegakernel, ptSceneOptions } from '@pmndrs/pathtracer';
const blueNoise = await loadBlueNoise('gf-vec2-128'); // the default, gf-vec2-64, needs no option at all
const pt = await PtMegakernel.create(device, caps, ptSceneOptions(scene, { mode: 'realtime', blueNoise }));
The other textures (vc2d-*, st-*) are in packages/raytracer/assets/bluenoise/ with a manifest.json: serve that folder and load one with fetchBlueNoise(url, name), which decodes the 16-bit PNG itself. Never decode these files through a canvas or createImageBitmap: those are 8-bit and lose the noise's precision. decodeBlueNoisePng decodes bytes you already have.
The 'realtime' mode switches to this sampler when you pass blueNoise, and stays on Owen-Sobol otherwise.
Path depth
setLimits({ maxDepth, rrStartDepth }) bounds each path.
maxDepth counts scattering events, with pbrt-v4's maxdepth meaning:
Mitsuba 3's max_depth is our maxDepth + 1. Without a setLimits call the kernel uses maxDepth 5 and no Russian roulette; a mode preset may start from other limits.
Glass needs depth: light through a closed glass object takes at least two scattering events, and smooth dielectrics in a white furnace need very deep paths to reach their exact value.
Russian roulette
Russian roulette ends paths that carry little light, at random, and scales up the ones that survive so the mean is unchanged. From scattering vertex rrStartDepth on (1 = the first surface hit), a path whose throughput's largest channel m is below 1 ends with probability 1 − m; otherwise its throughput is divided by m. Omitted or 0 turns it off.
pt.setLimits({ maxDepth: 16, rrStartDepth: 3 });
Roulette trades a little noise for speed on deep paths. The preview and realtime presets turn it off and cap the depth instead.