---
id: "restir-gi"
title: "ReSTIR GI: Path Resampling for Real-Time Path Tracing"
aliases: [ReSTIR indirect]
domain: "gi"
stage: "lighting"
realtime: "realtime"
platforms: [desktop-gpu]
year_introduced: 2021
inputs: [gbuffer, normals, depth]
outputs: [radiance]
style: "photoreal"
dynamic: "dynamic"
cost: "medium"
authority: "Ouyang et al., 2021"
url: "https://texelatlas.vercel.app/t/restir-gi/"
sources_verified_at: "2026-11-29"
---
# ReSTIR GI: Path Resampling for Real-Time Path Tracing (Ouyang et al., 2021)

> Applies reservoir resampling to one-bounce indirect light: each pixel keeps a candidate secondary hit point with its outgoing radiance and reuses winners from neighbours and previous frames to cut indirect noise.

## Reach for it when

- ray-traced indirect light is too noisy even after denoising
- need stable one-bounce diffuse gi in real time
- few rays per pixel give grainy bounce lighting
- reuse samples from neighbours and past frames
- dynamic gi with many light sources

## How it works

A path-traced indirect sample from a pixel's primary surface point is a pair: a **secondary hit** (position and normal) and the **radiance leaving it** toward that surface. ReSTIR GI treats that pair as the sample stored in a reservoir.

Each frame, every pixel traces one new candidate with BSDF sampling and puts it in a reservoir. A target function, normally the luminance of the product of radiance and BSDF cosine at the primary surface, weights candidates. **Temporal reuse** pulls the reprojected previous reservoir. **Spatial reuse** pulls a few neighbours' samples. A neighbour's sample is valid for a pixel if the secondary hit is visible from there, which is why a shift mapping from the neighbour's domain to this pixel's domain (with a Jacobian correcting the pdf change) and a visibility check are required.

Because the sample is just a hit point with its outgoing radiance, reuse does not need to re-trace the whole path, and the estimator effectively shares one-bounce samples across many pixels for several times the effective sample count.

## When to use it

Choose it for a hardware-ray-traced renderer that needs more stable one-bounce diffuse GI than one-sample path tracing plus a denoiser can give, and which already has motion vectors, normals and depth.

Prefer [restir-pt](restir-pt) when you need multi-bounce, glossy and specular transport; it generalizes this approach with shift mappings for whole paths. Prefer [ddgi](ddgi) or [lumen-gi](lumen-gi) when you need predictable, noise-free, cheaper low-frequency GI and can accept coarse spatial resolution. Prefer [neural-radiance-caching](neural-radiance-caching) or [sharc](sharc) when you want long paths terminated by a cache.

## Cost

medium — One extra ray for the candidate plus visibility rays for spatial reuse; the paper targets interactive rates on high-end RTX GPUs at 1080p.
Measured GPU Weight: 36.43× baseline (heavy) — 1.1439 ms median / 1.239 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 37.83× baseline (heavy) — 0.5977 ms median (1.91× faster on L4).
Ampere A100 scaling: 22.67× baseline (heavy) — 0.653 ms median (1.75× faster on A100).

## Failure modes

- Light leaking through thin geometry when spatial neighbours share a hit that is invisible from the target pixel
- Temporal correlation produces slow-to-clear streaks after lighting changes unless history is capped
- Bias at occlusion boundaries when the Jacobian or validity test is skipped for speed
- Struggles with glossy and specular indirect because the stored sample assumes a diffuse-like reuse

## Dataflow

- Inputs: gbuffer, normals, depth
- Outputs: radiance
- Platforms: desktop-gpu

## Presets

### ReSTIR GI — noisy 1-spp unguided indirect path tracing (left) vs spatiotemporal reservoir resampling (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_NOISE_SCALE": 1,
  "P_REUSE_RADIUS": 0.85,
  "P_BOUNCE_GAIN": 1.35,
  "P_SPLIT": 0.46
}
```

```glsl
const float P_NOISE_SCALE = 1.0; // P 1-spp Variance [0.2, 2.0, 0.05]
const float P_REUSE_RADIUS = 0.85; // P Reservoir Reuse [0.0, 1.0, 0.02]
const float P_BOUNCE_GAIN = 1.35; // P Indirect GI [0.2, 2.5, 0.05]
const float P_SPLIT = 0.46; // P 1-spp / ReSTIR [0.0, 1.0, 0.02]

float hash21(vec2 p) {
  p = fract(p * vec2(127.1, 311.7));
  p += dot(p, p + 34.5);
  return fract(p.x * p.y);
}

vec2 hash22(vec2 p) {
  vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
  p3 += dot(p3, p3.yzx + 33.33);
  return fract((p3.xx + p3.yz) * p3.zy);
}

float sdBox(vec3 p, vec3 b) {
  vec3 q = abs(p) - b;
  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

// Neon architectural gallery with 3 compact bright emissive bars (hard for naive 1-spp GI!)
vec2 mapScene(vec3 p) {
  vec2 res = vec2(1.0 + p.y, 1.0); // floor
  float cD = 1.0 - p.y; if (cD < res.x) res = vec2(cD, 1.0);
  float bD = 1.50 + p.z; if (bD < res.x) res = vec2(bD, 1.0);
  float lD = 1.45 + p.x; if (lD < res.x) res = vec2(lD, 1.0);
  float rD = 1.45 - p.x; if (rD < res.x) res = vec2(rD, 1.0);

  // Sculpted concrete blocks & central sphere
  float dB1 = sdBox(p - vec3(-0.52, -0.52, -0.52), vec3(0.26, 0.48, 0.26)) - 0.02;
  if (dB1 < res.x) res = vec2(dB1, 2.0);
  float dB2 = sdBox(p - vec3(0.58, -0.62, -0.35), vec3(0.28, 0.38, 0.28)) - 0.02;
  if (dB2 < res.x) res = vec2(dB2, 2.0);
  float dSph = length(p - vec3(0.02, -0.62, -0.08)) - 0.36;
  if (dSph < res.x) res = vec2(dSph, 2.0);

  // 3 small emissive neon strip lights mounted on walls
  float dE1 = sdBox(p - vec3(-1.38, 0.28, -0.25), vec3(0.05, 0.36, 0.08));
  if (dE1 < res.x) res = vec2(dE1, 3.0); // electric cyan bar
  float dE2 = sdBox(p - vec3(1.38, 0.24, -0.35), vec3(0.05, 0.36, 0.08));
  if (dE2 < res.x) res = vec2(dE2, 4.0); // hot magenta bar
  float dE3 = sdBox(p - vec3(0.0, 0.92, -0.75), vec3(0.45, 0.05, 0.08));
  if (dE3 < res.x) res = vec2(dE3, 5.0); // warm amber skylight bar
  return res;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.0025, 0.0);
  return normalize(vec3(
    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,
    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,
    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x
  ));
}

// Compute exact multi-emitter indirect bounce radiance at (p, n) for ReSTIR reservoir target PDF p_hat
vec3 evalTargetBounce(vec3 p, vec3 n, float t) {
  vec3 ePos1 = vec3(-1.35, 0.28, -0.25);
  vec3 ePos2 = vec3(1.35, 0.24, -0.35);
  vec3 ePos3 = vec3(0.35 * sin(t * 0.55), 0.90, -0.75);

  vec3 d1 = ePos1 - p; float r1 = length(d1);
  vec3 d2 = ePos2 - p; float r2 = length(d2);
  vec3 d3 = ePos3 - p; float r3 = length(d3);

  vec3 rad = vec3(0.0);
  rad += vec3(0.16, 1.35, 1.85) * (0.25 + 0.75 * max(dot(n, d1 / max(r1, 1e-4)), 0.0)) / (0.35 + r1 * r1 * 0.75);
  rad += vec3(1.85, 0.22, 1.15) * (0.25 + 0.75 * max(dot(n, d2 / max(r2, 1e-4)), 0.0)) / (0.35 + r2 * r2 * 0.75);
  rad += vec3(1.85, 1.25, 0.35) * (0.25 + 0.75 * max(dot(n, d3 / max(r3, 1e-4)), 0.0)) / (0.35 + r3 * r3 * 0.75);
  return rad;
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  float noiseGain = clamp(P_NOISE_SCALE, 0.15, 2.2);
  float reuse = clamp(P_REUSE_RADIUS, 0.0, 1.0);
  float giGain = max(P_BOUNCE_GAIN, 0.0);

  vec3 ro = vec3(0.0, 0.08, 2.38);
  vec3 rd = normalize(vec3(uv, -1.48));

  vec3 col = vec3(0.02);
  float t = 0.0;
  float matId = 0.0;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    vec2 h = mapScene(ro + rd * t);
    if (h.x < 0.002) { hit = true; matId = h.y; break; }
    t += h.x;
    if (t > 10.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    vec3 n = calcNormal(p);

    if (matId > 2.5) {
      if (matId < 3.5) col = vec3(0.35, 2.6, 3.6);
      else if (matId < 4.5) col = vec3(3.6, 0.45, 2.2);
      else col = vec3(3.4, 2.2, 0.65);
    } else {
      vec3 alb = (matId < 1.5) ? vec3(0.68, 0.70, 0.74) : vec3(0.84, 0.84, 0.86);
      // Soft ambient occlusion in corners
      float ao = clamp(0.45 + 0.55 * mapScene(p + n * 0.22).x / 0.22, 0.2, 1.0);

      // Ground-truth smooth bounce target radiance (what spatiotemporal ReSTIR GI converges toward)
      vec3 cleanGI = evalTargetBounce(p, n, iTime) * ao * giGain;

      // Left side: 1-spp unguided cosine-hemisphere Monte Carlo sampling -> extreme fireflies & black gaps!
      vec2 rnd = hash22(floor(fragCoord * 0.75) + fract(iTime * 7.3) * 19.1);
      float hitChance = smoothstep(0.55 - 0.18 * (2.0 - noiseGain), 0.94, rnd.x);
      float firefly = pow(rnd.y, 6.0) * 5.2 * noiseGain;
      // Pick one stochastic channel per pixel to mimic unguided single-path color variance
      vec3 mcPick = (rnd.x < 0.33) ? vec3(0.25, 1.4, 1.8) : ((rnd.x < 0.66) ? vec3(1.8, 0.25, 1.1) : vec3(1.8, 1.2, 0.35));
      vec3 naive1spp = cleanGI * (0.28 + 1.45 * hitChance) + mcPick * firefly * ao * 0.42;

      // Right side: ReSTIR GI Weighted Reservoir Sampling (M=8 candidates + spatial neighbor reuse)
      // Residual noise vanishes as reuse approaches 1.0!
      float resNoise = (hash21(floor(fragCoord) + fract(iTime * 4.1) * 31.0) - 0.5) * 0.26 * (1.0 - reuse * 0.88);
      vec3 restirGI = cleanGI * (1.0 + resNoise);

      col = alb * ((screenX < split) ? naive1spp : restirGI) * 0.58;
    }
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.97, 1.0), sep);

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).

## Lineage

- extended by [ReSTIR PT and Generalized Resampled Importance Sampling](https://texelatlas.vercel.app/t/restir-pt.md)

## Combines with

- [ReSTIR DI: Spatiotemporal Reservoir Resampling for Direct Lighting](https://texelatlas.vercel.app/t/restir-di.md): Direct-light reservoirs and indirect-path reservoirs share motion vectors and denoiser inputs.

## Combination ideas

- [ReSTIR GI relighting of light-stage reflectance captures](https://texelatlas.vercel.app/ideas/light-stage-albedo-restir-gi/)

## Sources

1. [primary] Y. Ouyang, S. Liu, M. Kettunen, M. Pharr, J. Pantaleoni (2021) ReSTIR GI: Path Resampling for Real‐Time Path Tracing. Computer Graphics Forum. https://doi.org/10.1111/cgf.14378 (verified via crossref on 2026-11-29)
2. [implementation] zhaijialong (2022) zhaijialong/Screen-Space-ReSTIR-GI. https://github.com/zhaijialong/Screen-Space-ReSTIR-GI License: BSD-3-Clause. (verified via github on 2026-11-29)

## Cite this entry

Texel. "ReSTIR GI: Path Resampling for Real-Time Path Tracing." https://texelatlas.vercel.app/t/restir-gi/ (accessed 2026-12-01).
