Skip to content

The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.

A history that moves is resampled with the Catmull-Rom kernel (#302)

YXade79c0589aa
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 3c2964d..48b328e 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -2517,6 +2517,32 @@ The firefly cut on a young diffuse history takes 4 to 5 % of the hall's diffuse
history) is not explained. The recordings and their measures were made outside the repository. Not checked on
Vulkan, nor in a browser.
+**A history that moves is resampled with the Catmull-Rom kernel (2026-12-02, after it).** In motion both denoisers
+fetched their histories bilinearly: the mean of four pixels at a new sub-pixel offset every frame, a blur that adds
+up over a history's length (the bounds on a moving history's length, `moving_frames`, are there for it).
+
+- Where the 4 × 4 pixels around the position, less the corners, all show this surface, the diffuse history (from the
+ length at which it is fetched at its pixel's centre, 16 frames) and the specular one (from 8 frames, at either of
+ its two places) are resampled with the Catmull-Rom kernel, held within the range of the four pixels around the
+ position: the kernel's negative lobes ring at a steep edge. Elsewhere, and for the histories' lengths and moments,
+ bilinearly as before. Standing still nothing is resampled and nothing changes.
+- Measured as the entry above and after its change (an M4 at half resolution). Of the offline render's detail the
+ street's picture has mid-turn 0.451 → 0.458, as the turn stops 0.380 → 0.392, mid-strafe 0.454 → 0.461, stopping
+ from 8 m/s 0.374 → 0.382, along its walk 0.351 → 0.364, 0.403 → 0.410 and 0.371 → 0.381; its ΔE at those moments
+ 2.86 → 2.83, 2.61 → 2.54, 3.22 → 3.18, 3.61 → 3.60, 3.94 → 3.86, 4.07 → 3.98, 4.90 → 4.79. The hall: 1 to 2 % more
+ of the detail in its moves (mid-turn 0.453 → 0.461, along its path 0.396 → 0.402), ΔE 0 to 1 % less, its light
+ against offline 0 to 2 % more. The change from a frame to the next after a move: the street's 4 × 4 block means the
+ same, the hall's 0 to 1 % less; per pixel 0 to 1 % more in both.
+- What it costs. Twelve clips against offline: eleven within 0.01 in ΔE; metals and gems on a turntable ΔE 2.37 →
+ 2.32 with 4 % more of the detail (0.298 → 0.311), and their whole pixels' change from a frame to the next 1.35 →
+ 1.46. `bench-ghosting --quick --check` passes: a tenth of a second after the stop 1.39 → 1.46, mid-strafe 1.31 →
+ 1.28, the others within 0.02. `bench-object-ghosting`: ΔE the same at all sixteen moments; the thrown lamp's trail a
+ tenth of a second after its flight 74 → 105 pixels at the same ΔE (3.67, 3.66). Frame time over the twelve clips
+ from 1.4 % less to 0.3 % more. Unit suite 292, render suite 273.
+
+Not done: the bounds on a moving history's length were set for the bilinear tap's blur and are as they were. Not
+checked on Vulkan, nor in a browser.
+
**The live passes from one place (2026-11-14, after it).** A buffer and a pass more (the locks' carry, above) took
seven edits that had to agree: the declaration in live.wgsl, the bind group layout's entries, the pass list, the
buffers' sizes and order, the bind group's entries, the dispatch grid (in two copies), and the merged layout's table.
diff --git a/renderer/shaders/live.wgsl b/renderer/shaders/live.wgsl
index 34d59e7..79b09e8 100644
--- a/renderer/shaders/live.wgsl
+++ b/renderer/shaders/live.wgsl
@@ -465,6 +465,13 @@ fn same_surface_n(tx: i32, ty: i32, z: f32, n: vec3<f32>, t: f32, ncos: f32) ->
const HIST_CENTRE: f32 = 16.0;
// Diffuse history length from which the firefly cut stops (dtemporal).
const FIREFLY_FRAMES: f32 = 16.0;
+// The specular history's length from which it is resampled with the sharper kernel in motion (`catrom`).
+const SPEC_CATROM_FROM: f32 = 8.0;
+
+// The Catmull-Rom kernel's four weights along one axis, for the pixels at -1, 0, 1 and 2 of a position f past pixel 0.
+fn catrom(f: f32) -> vec4<f32> {
+ return vec4<f32>(f * (-0.5 + f * (1.0 - 0.5 * f)), 1.0 + f * f * (-2.5 + 1.5 * f), f * (0.5 + f * (2.0 - 1.5 * f)), f * f * (-0.5 + 0.5 * f));
+}
// ---- The response of the histories: how long a pixel's history may be, and how it follows the lighting.
// (Written 2026-11; docs/RUNTIME.md "The temporal response of the live denoiser". Sources are named where a rule
@@ -718,6 +725,35 @@ fn dtemporal(@builtin(global_invocation_id) gid: vec3<u32>) {
hd = vec4<f32>(0.0);
hm = vec4<f32>(0.0);
}
+ // In motion a bilinear tap blurs the history a little every frame. A history old enough to be fetched at
+ // its centre, whose 4 x 4 pixels around (less the corners) all show this surface, is resampled with the
+ // Catmull-Rom kernel instead and held within the range of the four pixels around the position (the
+ // kernel's negative lobes ring at a steep edge). Its length and its moments stay the bilinear ones.
+ if (centred && speed > 0.0 && wsum > 0.999 && hd.w > 0.0) {
+ let wx = catrom(f.x);
+ let wy = catrom(f.y);
+ var whole = true;
+ var cs = vec3<f32>(0.0);
+ var cw = 0.0;
+ var lo = vec3<f32>(1.0e30);
+ var hi = vec3<f32>(-1.0e30);
+ for (var k = 0; k < 16; k++) {
+ let i = k % 4;
+ let j = k / 4;
+ if (!whole || ((i == 0 || i == 3) && (j == 0 || j == 3))) { continue; }
+ let tx = x0 + i - 1;
+ let ty = y0 + j - 1;
+ if (tx < 0 || ty < 0 || tx >= ps.x || ty >= ps.y || !same_surface_n(tx, ty, pp.z, n, t, 0.5)) { whole = false; continue; }
+ let v = diffuse_hist[last_half(u32(ty * ps.x + tx))].rgb;
+ cs += v * (wx[i] * wy[j]);
+ cw += wx[i] * wy[j];
+ if ((i == 1 || i == 2) && (j == 1 || j == 2)) {
+ lo = min(lo, v);
+ hi = max(hi, v);
+ }
+ }
+ if (whole && cw > 0.5) { hd = vec4<f32>(clamp(cs / cw, lo, hi), hd.w); }
+ }
if (non_finite(hd.rgb) || non_finite(hm.xyz)) {
hd = vec4<f32>(0.0);
hm = vec4<f32>(0.0);
@@ -934,6 +970,15 @@ fn atrous_gated(gid: vec3<u32>, stage: u32, step: i32, max_noise: f32) {
// Specular history at previous-frame position pp (prev_pixel: output pixels, view depth) on the previous traced grid:
// bilinear over the taps that show this surface; `virt`: through a reflection (the reflecting surface's normal and
// roughness must match, not its depth).
+fn spec_tap(tx: i32, ty: i32, pz: f32, n: vec3<f32>, t: f32, rough: f32, virt: bool) -> bool {
+ let ps = vec2<i32>(L.isz.zw);
+ if (tx < 0 || ty < 0 || tx >= ps.x || ty >= ps.y) { return false; }
+ let g = gb_unpack(gbuffer[last_half(u32(ty * ps.x + tx))]);
+ if (virt) { return g.depth > 0.0 && dot(g.n, n) > 0.95 && abs(g.rough - rough) < 0.1; }
+ if (t > 0.0) { return g.depth > 0.0 && abs(g.depth - pz) < 0.04 * pz + 0.002 && dot(g.n, n) > 0.8; }
+ return g.depth == 0.0;
+}
+
fn spec_history(pp: vec3<f32>, n: vec3<f32>, t: f32, rough: f32, virt: bool) -> vec4<f32> {
let ps = vec2<i32>(L.isz.zw);
let tc = (pp.xy + 0.5) * vec2<f32>(ps) / vec2<f32>(f32(L.size.x), f32(L.size.y)) - 0.5;
@@ -945,24 +990,38 @@ fn spec_history(pp: vec3<f32>, n: vec3<f32>, t: f32, rough: f32, virt: bool) ->
for (var k = 0; k < 4; k++) {
let tx = x0 + (k & 1);
let ty = y0 + (k >> 1u);
- if (tx < 0 || ty < 0 || tx >= ps.x || ty >= ps.y) { continue; }
- let j = u32(ty * ps.x + tx);
- let g = gb_unpack(gbuffer[last_half(j)]);
- var ok = false;
- if (virt) {
- ok = g.depth > 0.0 && dot(g.n, n) > 0.95 && abs(g.rough - rough) < 0.1;
- } else if (t > 0.0) {
- ok = g.depth > 0.0 && abs(g.depth - pp.z) < 0.04 * pp.z + 0.002 && dot(g.n, n) > 0.8;
- } else {
- ok = g.depth == 0.0;
- }
- if (!ok) { continue; }
+ if (!spec_tap(tx, ty, pp.z, n, t, rough, virt)) { continue; }
let bw = select(1.0 - f.x, f.x, (k & 1) == 1) * select(1.0 - f.y, f.y, (k >> 1u) == 1);
- h += spec_hist[last_half(j)] * bw;
+ h += spec_hist[last_half(u32(ty * ps.x + tx))] * bw;
wsum += bw;
}
if (wsum <= 1e-3) { return vec4<f32>(0.0); }
h /= wsum;
+ // (Off a pixel's centre, a history of some length whose 4 x 4 pixels around, less the corners, all pass: the
+ // Catmull-Rom kernel, within the range of the four around, as the diffuse history's in `dtemporal`.)
+ if (wsum > 0.999 && h.w >= SPEC_CATROM_FROM && max(min(f.x, 1.0 - f.x), min(f.y, 1.0 - f.y)) > 1.0e-3) {
+ let wx = catrom(f.x);
+ let wy = catrom(f.y);
+ var whole = true;
+ var cs = vec3<f32>(0.0);
+ var cw = 0.0;
+ var lo = vec3<f32>(1.0e30);
+ var hi = vec3<f32>(-1.0e30);
+ for (var k = 0; k < 16; k++) {
+ let i = k % 4;
+ let j = k / 4;
+ if (!whole || ((i == 0 || i == 3) && (j == 0 || j == 3))) { continue; }
+ if (!spec_tap(x0 + i - 1, y0 + j - 1, pp.z, n, t, rough, virt)) { whole = false; continue; }
+ let v = spec_hist[last_half(u32((y0 + j - 1) * ps.x + x0 + i - 1))].rgb;
+ cs += v * (wx[i] * wy[j]);
+ cw += wx[i] * wy[j];
+ if ((i == 1 || i == 2) && (j == 1 || j == 2)) {
+ lo = min(lo, v);
+ hi = max(hi, v);
+ }
+ }
+ if (whole && cw > 0.5) { h = vec4<f32>(clamp(cs / cw, lo, hi), h.w); }
+ }
if (non_finite(h.rgb) || non_finite(vec3<f32>(h.w))) { return vec4<f32>(0.0); }
return h;
}