skip to content

Why do hybrid renderers trace about one reflection ray per pixel on rain-wet streets, and how does spatiotemporal denoising make that noisy result usable?

level: seniorimportance: should knowfreq 38%

answer

  1. Monte Carlo, one sample
  2. noise falls with the square root
  3. reproject, validate, accumulate
  4. variance steers the blur
  5. reflections move with the reflected point

basics

~20 s

A frame can rarely afford more than one ray per pixel per effect, so each pixel gets one noisy Monte Carlo sample. A denoiser reprojects and accumulates samples over frames, then blurs spatially with edge-stopping weights guided by an estimated per-pixel variance.

solid answer

~50 s

A rough reflection averages light over a cone of directions, and one random ray per pixel estimates that average with heavy noise; halving the noise costs four times the rays, which the frame cannot pay. A **denoiser** reuses samples instead. **Temporal accumulation** reprojects each pixel with motion vectors, discards history where depth or normal disagree (a disocclusion), and blends the new sample in with an exponential moving average while tracking luminance moments for a **variance** estimate. **SVGF** then runs an edge-aware à-trous filter whose depth and normal weights stop at silhouettes and whose luminance weight, scaled by variance, blurs only where the estimate is still noisy; lighting is divided by albedo first so textures stay sharp. Reflections add two rules: reproject with the hit distance, because reflected objects move with their virtual position, and size the kernel by roughness.

code

pseudocode · 14 lines
pseudocode
-- motion[p] = current screen position minus previous screen position
function accumulate(p, sample, motion, history, gbuffer, maxLength, minAlpha):
    prevPos = p - motion[p]
    prev = history.fetch(prevPos)        -- colour, moments, length, depth, normal
    if not onScreen(prevPos) or not sameSurface(prev, gbuffer[p]):
        -- disocclusion: start over from this frame's sample
        return (sample, moments(sample), 1)
    length = min(prev.length + 1, maxLength)
    alpha = max(1 / length, minAlpha)    -- plain average while history is short
    colour = lerp(prev.colour, sample, alpha)
    m = lerp(prev.moments, moments(sample), alpha)   -- (lum, lum * lum)
    return (colour, m, length)

-- variance for the spatial filter: m.y - m.x * m.x

go deeper

for a junior

Recall that one ray per pixel gives a noisy estimate and that denoisers reuse samples across frames and neighbouring pixels.

for a middle

Explain reprojection, disocclusion checks, the moving average and why albedo is divided out before the spatial filter.

for a senior

Diagnose denoiser artefacts from symptoms: ghosting, boiling after cuts and smeared reflections, and say which validation, kernel or reprojection change fixes each.

for a principal

Weigh denoiser cost against ray count when setting per-tier quality: more rays, better sampling such as ReSTIR, or stronger filtering, and what each costs in stability.

## Why one sample is noisy A reflection on a rough surface is an average: light arrives from a cone of directions around the mirror direction, weighted by the material's reflectance. A ray tracer estimates that average by **Monte Carlo** sampling. With one ray per pixel, each pixel's estimate comes from one random direction, so neighbouring pixels disagree wildly and the image looks speckled. The noise's standard deviation falls with the square root of the sample count, so halving it takes four times the rays, and a frame can rarely afford even two rays per pixel per effect. On rain-wet streets the noise varies across the surface. Standing water is nearly a mirror: its cone is narrow, so one ray is already close to the answer. The wet asphalt around it is rougher: its cone is wide, so one ray is very noisy. A **denoiser** turns that signal into a stable image by reusing samples across time and across neighbouring pixels. ## Temporal accumulation 1. **Reproject**: use the pixel's motion vector to find where the same surface was in the previous frame. 2. **Validate**: compare depth, normal and, if available, object ID at that previous position. A large disagreement means the surface was just revealed, a **disocclusion**, so the history belongs to something else and is discarded. 3. **Blend**: mix the new sample into the history with an exponential moving average. While the history is short the weight is `1 / length`, which gives a plain average; after that it stays at a floor such as `0.2`. 4. **Track moments**: keep running averages of luminance and luminance squared; their difference is a per-pixel **variance** estimate. The floor trades remaining noise against how quickly the image reacts. With a weight `a = 0.2`, the steady-state variance is `a / (2 - a) = 0.2 / 1.8`, one ninth of a single sample's, the same as averaging nine frames. ## Variance-guided spatial filtering Accumulation still leaves noise, especially on freshly revealed pixels. **SVGF** (spatiotemporal variance-guided filtering) follows it with an edge-aware spatial filter. - It uses an **à-trous** wavelet filter: a small kernel, 5x5 taps in the original method, applied several times with the gap between taps doubling: 1, 2, 4, 8 and 16 pixels. - Five passes of 25 taps reach a footprint 125 pixels across for 125 taps per pixel, where a dense kernel that wide would need 15,625. - **Edge-stopping weights** shrink a neighbour's contribution when its depth or normal differs, so the blur does not cross silhouettes. - A **luminance weight** scaled by the local variance lets the filter blur hard where the estimate is noisy and keep detail where it has converged. - **Albedo demodulation**: lighting is divided by the surface's albedo before filtering and multiplied back afterwards, so texture detail is not blurred. ## What reflections add - **Different motion**: a reflection does not move with the surface. A building reflected in a puddle appears to lie below the street, at the reflected hit's virtual position. Reprojecting with the street's motion vectors smears it; reflection denoisers use the hit distance to place that virtual point and reproject it instead. - **Roughness sets the kernel**: a mirror puddle needs little spatial blur, rough asphalt needs a wide one, and a short hit distance tightens it near contact, where reflections are sharp. - **Reduced rate**: rough reflections are often traced at half resolution or in a checkerboard and upsampled before filtering. ## Failure modes | Symptom | Cause | Usual mitigation | |---|---|---| | Ghost trails behind moving objects | stale history kept | stricter validation; clamp history to the current neighbourhood's range | | Boiling noise after a camera cut | history discarded everywhere at once | wider spatial filter while history is short | | Smeared, lagging reflections | surface motion used for reflected content | reproject the virtual reflected point | | Over-blurred contact detail | kernel ignores hit distance | scale the kernel by hit distance | ## Better samples, not only more filtering **ReSTIR** (reservoir-based spatiotemporal importance resampling) attacks the same problem from the sampling side, mainly for direct light from many sources. Each pixel streams cheap candidate lights through a small **reservoir** that keeps one, then merges its reservoir with the previous frame's and with neighbours' before tracing a single shadow ray. The surviving sample is far better than a randomly chosen light, so the denoiser has less noise to remove.

  • Why does a reflection on the street smear when it is reprojected with the street's own motion vectors?
    The street's motion vectors describe how the asphalt moves on screen. A reflected building appears at a virtual position behind the mirror plane, the hit distance beyond the surface along the view ray, and as the camera moves that virtual point shifts differently from the asphalt. Reflection denoisers place the virtual point from the hit distance and reproject it, falling back to stronger spatial filtering where that estimate is unreliable, for example on rough surfaces.
  • How does ReSTIR differ from a denoiser, and why are they used together?
    A denoiser filters samples after they are traced; ReSTIR improves which sample is traced. For each pixel it resamples many cheap light candidates, keeping one chosen in proportion to its estimated contribution divided by the chance of drawing it, then reuses reservoirs from the previous frame and neighbours before one visibility ray. Better samples leave less noise, and the denoiser removes what remains. Reusing neighbours can add bias unless corrected.
  • Why divide lighting by albedo before filtering?
    The noise lives in the lighting, not in the texture. Filtering the product would blur texture detail such as road markings along with the noise. Dividing by albedo leaves smooth lighting to filter, and multiplying back restores sharp textures.

  • Denoising recovers detail the rays never sampled, so one ray is as good as many.
  • Reflections can reuse the surface's motion vectors exactly like diffuse lighting.
  • A longer history is always better, so accumulation should never be reset.
  • The spatial filter should blur equally across depth and normal edges.
  • Mirror-smooth puddles need the heaviest denoising.