AssetBash Docs Sign in
Lunaris USD + path tracing in TouchDesigner

Performance

How to get a clean image in fewer samples, and how to stop paying for samples we don't need. This page is a plan: each item says whether it is in, planned, or to verify.

Already in the tracer

TechniqueWhat it buys
Direct light sampling + MISEvery bounce samples one light and the BSDF, combined with the power heuristic, so small bright lights and sharp highlights both converge.
HDRI importance samplingDome texels are sampled in proportion to their brightness (a CDF built from the HDRI), so the sun in an HDRI is found directly.
GGX visible-normal (VNDF) samplingSpecular directions are drawn from the part of the microfacet distribution the eye can see: less wasted rays on rough metal.
Ray-cone texture LODTexture lookups use the right mip level for the ray's footprint: less aliasing noise, better cache use.
Path regularisation + indirect clampAfter a diffuse bounce, glossy lobes are widened and per-sample radiance is capped: kills caustic fireflies at a small bias.
Temporal accumulationA still camera keeps every sample, up to 1024 per pixel.
OptiX denoiser (Temporal)Cleans the remaining noise using albedo, normal and motion guides.

Found on 11/19

  • fixed Partial opacity shimmered. The random first hit changed every frame, the history test saw a different surface and discarded the history half the time. Frame-to-frame change on a 50% cube went from 14.5% to 1.9% (denoiser off), the same as solid surfaces.
  • fixed Lights were picked uniformly. Each bounce chooses one light at random with equal odds. In Phos the bar spot carries ~2.8× the power of each of the six hanging lights (22.9 vs 8.2, radiance × area), yet is picked 1 time in 7.
  • fixed It never stopped. After 1024 samples the tracer keeps tracing every frame, adding samples at weight 1/1024 that no one can see.

Shipped 11/19: pause, light selection, Sobol

All three are on the Path Trace page and can be switched for A/B: Pause When Converged, Light Selection (Uniform / By Power), Sampler (Random / Sobol).

Noise

Demo scene (3 lights + HDRI dome), 1286×882, denoiser off. RMSE of the image after N samples against a 1024-sample reference (lower is better):

Configuration16 samples64 samples
Before (uniform lights, white noise)0.03990.0257
Light selection by power0.02230.0175
Sobol sampler0.02370.0192
Both (new default)0.01860.0154

With both on, 16 samples measured cleaner than 64 did before. How far to trust these numbers:

  • One run per configuration, on one scene with three lights; 8-bit tonemapped captures of the display.
  • The figures flatten towards ~0.012–0.015, a floor that is probably sub-pixel anti-aliasing at edges and in fine texture (that is where the old and new references differ), but that is not measured. Until 11/19 evening the sub-pixel jitter was not aligned to the reset, so captures saw different jitter sets; it now is.
  • The old and new 1024-sample references have the same mean brightness (0.6114 vs 0.6115), but a whole-image average cannot rule out a small local bias near one light. The selection code was reviewed for bias line by line (weight > 0 wherever a light can contribute; the MIS probability matches the pick), which is the stronger evidence.

How each works

  • Pause When Converged. After Max Samples frames with no change to the camera, the stage, any Path Trace parameter, the stage time or the HDRI, null_out is locked: nothing pulls the trace, accumulation or denoiser, so they stop cooking and the last image stays up. Any change unlocks it in the same frame (checked: 747 idle frames while paused; a parameter change resumed tracing within 10 frames).
  • Light selection by power. At each shading point every light gets a weight equal to its estimated irradiance there: distant = its irradiance, sphere = L π r²/d², rect / disk / cylinder = L area/d², and zero behind a one-sided rect or disk. The light is picked in proportion; the BSDF-hit MIS weight recomputes the same probability at the previous vertex, so the result stays unbiased. Above 64 lights it falls back to uniform.
  • Sobol sampler. Owen-scrambled, per-pixel shuffled Sobol (Burley 2020). Each path vertex draws 4D points for the BSDF (lobe + direction), the light (pick + position) and the dome; the index is the sample number since the last reset. Russian roulette stays on white noise.

Speed

not measured The cost of the new sampling is unknown: at 3× resolution (3858×2646, denoiser off) both versions hit the display's 60 fps cap (59.8 vs 59.6), and a capped run cannot show a cost. Light selection by power loops over every light (twice per path vertex, and again when a bounce ray hits a light shape), so its cost grows with the light count; it was only run with three lights. To measure: a scene with many lights, under enough load to fall below 60 fps.

The expensive stage on the demo scene is the OptiX denoiser: 36.6 fps at 2× with it on, against the 60 fps cap with it off. Pausing when converged removes the denoiser's cost too.

The denoiser, and Upscale While Moving

The OptiX denoiser is the largest single cost measured so far. Demo scene, output 2572×1764, one run each, bench() (display capped at 60 fps):

DenoiserTraced atfps
off2572×176460 (cap)
Single frame2572×176445.0
Temporal (the default)2572×176434.8
Single + Upscale 2×1286×88259.8
Temporal + Upscale 2×1286×88260 (cap)

Upscaling from half resolution removes the denoiser's cost, but the result is visibly softer (texture detail and reflections; RMSE 0.018 against native at 1286×882). So the path tracer now switches by itself: in Upscale While Moving (Path Trace page, on by default). While the camera moves, plus 8 frames, it traces at half the Resolution Scale with Temporal + Upscale 2×; when the camera is still it goes back to your settings, so the accumulation converges sharp and Pause When Converged freezes it. Your Resolution Scale and Denoise Model parameters are never changed; the ray grid and the denoiser read the effective values. Measured on a 60-frame orbit: the switch happens on the first moving frame and 8 frames after the stop, both in a normal 16.5 ms frame (no hitch). If you choose an upscale model yourself, it is left alone.

Plan, ranked by value for effort

#ItemEffortWin
1in Pause when converged. When the history is full and nothing has changed (camera, stage revision, parameters), skip the trace and show the accumulated image.Small~100% of the tracer's GPU time on a still frame, free for the rest of the show.
2in Power-weighted light selection, per shading point (estimated irradiance; see above).SmallLess noise wherever lights differ in strength; same cost per sample.
3in Better random numbers. Replace white-noise PCG per sample with a low-discrepancy sequence (Owen-scrambled Sobol) or blue-noise tiles for the first dimensions.SmallThe same number of samples looks less noisy; the noise that remains is fine-grained, which the denoiser handles better.
4Radiance cache (stored light). See below.Medium–largeThe big one: indirect light computed once and reused across pixels and frames.
5ReSTIR DI (reservoir resampling of light samples across neighbouring pixels and frames).LargeScenes with hundreds of lights or emissive triangles (Phos screens, light strips) without hundreds of shadow rays.
6Adaptive sampling. Use the accumulation's variance to spend samples where the image is still noisy.MediumFaster convergence of the hard parts (glass, interiors) when a frame budget is fixed.

Radiance cache: storing light

The idea: most of a path tracer's cost is indirect light, and indirect light changes slowly in space and time. A cache stores outgoing radiance at points on surfaces so a path can stop early and read it.

Recommended shape: a world-space hash-grid cache

  • Where light is stored. A hash table in a GPU buffer. The key is the hit position quantised to a voxel (voxel size grows with distance from the camera) plus the quantised normal. Each entry holds accumulated radiance and a sample count (~16–32 bytes).
  • Filling it. Every frame a small fraction of pixels (say 1 in 16) trace a longer path and write the radiance they find at each vertex into the cache.
  • Using it. Normal paths trace the first bounce exactly, then at the second hit read the cache instead of continuing. Fewer bounces, far less noise in interiors like the Phos ship.
  • Keeping it fresh. Entries blend new samples with old (an exponential moving average) and expire when unused, so moving lights and objects update within a few frames.
  • Cost. A little bias (light is averaged over a voxel) and a short lag when lighting changes. Direct light stays exact; only indirect goes through the cache.

This is the technique behind path-space filtering by jittered spatial hashing (Binder, Fricke and Keller, 2018) and NVIDIA's SHaRC. We would write our own from the published method rather than vendor an SDK.

to verify The cache needs a buffer that the GLSL POP can read and write with atomics and that persists between frames. Whether a GLSL POP exposes that (or needs a feedback POP / a second compute pass) is the first thing to check in TD before building.

Alternatives considered

MethodWhy not first
Irradiance probes (DDGI-style grid)Simpler lookups but a fixed grid: light leaks through thin walls, and the Phos ship is all thin walls.
Baked lightmapsExact and free at runtime, but static: any change means a rebake, which defeats a live tool.
Neural radiance cacheNeeds a CUDA training library outside TouchDesigner's shader model.
ReSTIR GIExcellent quality, but large and complex. Revisit after the hash-grid cache.

How we measure

  • fps: lunaris.pathtrace.bench(seconds) raises the cook rate to 1000, counts frames the tracer actually ran (pt_frame) over wall-clock time, and restores the rate. Do not count absTime.frame: with Realtime on it follows the clock and reads ~1000 whatever the GPU does. The display caps at 60 fps (vsync), so compare costs under enough load to fall below 60, and with the same denoiser setting.
  • Noise: RMSE between two consecutive captures of a region, denoiser off (the jitter test above).
  • Convergence: RMSE against a 1024-sample reference after N frames (Reset before every configuration).