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.

The specular history per pixel: bounded by each reflection's own parallax, not by what the camera did (ROADMAP § 1a) (#39)

Yujiafa8cb1262ac6
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 551d246..a7d2b3d 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -1839,6 +1839,44 @@ hid two faults of the live path's own:
- Not done: live GI, reflection and shadow rays still see no media (the stand-in light stays), overlapping media are
still taken whole in entry order, and a medium has no motion vector (smoke that drifts is reactive, not followed).
+**The specular history per pixel (2026-11-13, after it).** `stemporal` still set every pixel's history by what the
+camera did: 2 .. 12 frames by roughness whenever it moved or turned at all, 4 for the 8 frames after it translated
+(§ 2c's fix). Now each pixel's own, from two things it knows (output pixels a frame): its speed (a resampled history
+blurs: 48 frames at a pixel a frame, as the diffuse) and its reflection's parallax, how far what it reflects moved
+against the surface: the history may be no longer than keeps its trail (frames × parallax) within 2 px (`SPEC_TRAIL`),
+2 frames at least on a mirror, 4 from roughness 0.05. The parallax is the reflected point's where this frame's sample
+has one, the farthest possible point's where it has none, and a moving reflector's own speed. A turn has no parallax
+and keeps its history; a translation shortens it where the reflection slides, by how fast. NRD's ReBLUR bounds the
+specular history per pixel by parallax too (its source, `REBLUR_TemporalAccumulation`).
+
+| bench-ghosting --quick, excess over the settled frame / trail px (turn-mid, strafe-mid ground; the two returns + 0.5 s; stop + 0.1 s) | main | this |
+|---|---|---|
+| Kabukichō | 2.42 / 29, 3.27 / 60, 1.18 / 22, 1.23 / 23, 2.48 / 32 | 1.97 / 28, 2.86 / 56, 1.10 / 22, 1.10 / 22, 2.07 / 30 |
+| Bistro | 1.08 / 5, 1.76 / 6, 1.25 / 12, 1.34 / 12, 1.50 / 5 | 0.84 / 7, 1.60 / 6, 1.17 / 12, 1.26 / 11, 1.34 / 5 |
+
+- What was tried and left out, each measured (`out/liveq/gpu-runs-std.md`, S1–S20):
+ - the parallax weighed against the reflection's own blur, as ReBLUR weighs it against the lobe's angle (the
+ history may trail K lobe footprints behind): a wet street's lobe is 27–245 px wide here, the history ran through
+ a forward move, and the stop dragged a 65–112 px trail (limit 35);
+ - two thresholds instead of one budget (2 .. 12 frames from 0.25 px of parallax, 4 from 2 px): passes, a little
+ behind the budget on every reading;
+ - the pixel's speed taken for the parallax where the frame's sample has no reflected point: a turn then lost its
+ history on rough surfaces (2.14 for 1.97);
+ - budgets of 1, 2, 4 and 8 px: no reading tells them apart at these speeds (the floor of 2 .. 4 frames decides);
+ 2 is the tighter trail.
+- bench-temporal (Kabukichō, a 2.5 m dolly with a 12° turn in 1 s, real time, against each build's own converged
+ frames): the move reads 3.97 / 4.16 / 4.21 and the stop 2.92 on average over four runs of this rule (budgets 1 .. 4
+ px), main's one run of the day 3.92 / 4.07 / 4.12 and 2.88: 0.05–0.09 above main each time, inside the spread of
+ main's own runs across two days (move40 3.88–4.07). Stated as it is: the ghosting bench counts frames and repeats
+ to 0.02, this one does not.
+- Not changed, measured: what makes the scene's lighting "live" for the whole frame. Anything that moves or is edited
+ does, for 45 frames, so a scene with a walker in it is always at the 32-frame bound (NRD's own: 30), and the rule
+ for spark lights adds nothing there (the Bistro slice reads the same without it). The radiance cache's history is
+ cut to 4 frames by the same switch: at 32 the slice reads 2.66 for 2.82 at rest and 5.80 for 6.03 at its
+ explosion, and all of test-render passes; what the 4 frames buy is how fast indirect light follows an edit, which
+ no bench here counts in frames. It waits for a lockstep lighting-edit measure.
+- Gone with it: the frames-since-translation counter, temporal flag 16384 and the Playground's H switch.
+
Not done here: filters sized by hit distance, which is what would let a short history stand without noise; the
Playground and the page still open a 1280 × 720 view; the live buffers are sized by the output (about 1.7 GB at
2560 × 1440), though the traced grid rarely fills it.
@@ -2041,8 +2079,9 @@ dynamic-resolution floor, 60 Hz camera input.
- No effect: Catmull-Rom instead of bilinear specular history, counting only disocclusions as fresh history,
picking one of the surface / mirror-image histories instead of blending them, a 4σ box everywhere.
- Fix: for 8 frames after the view last translated (the stop included), the specular history is clamped at 4σ and
- held to 4 frames; a rotation keeps the long history (`THREERT_TEMPORAL_FLAGS=16384` switches it off). Excess mean dE /
- trail, old → new:
+ held to 4 frames; a rotation keeps the long history (`THREERT_TEMPORAL_FLAGS=16384` switches it off). (2026-11-13:
+ the whole frame's rule and its switch are gone: each pixel's history is bounded by its own reflection's parallax,
+ § 1a "The specular history per pixel".) Excess mean dE / trail, old → new:
- strafe mid, street: 4.10 / 79 px → 3.82 / 58 px;
- strafe back + 0.5 s, whole frame: 1.47 → 1.13;
- stop + 0: 3.85 / 68 px → 3.24 / 38 px;
diff --git a/playground/README.md b/playground/README.md
index 0aaac5e..3b71642 100644
--- a/playground/README.md
+++ b/playground/README.md
@@ -34,9 +34,8 @@ references in `out/ue/{lumen,pathtracer}`.
Viewport: LMB drag orbit · RMB drag look (+ WASD / QE fly, Shift faster) · MMB or Shift-drag pan · wheel or trackpad
pinch dolly · click select · F focus selection · Home scene camera · G outline / game view · F11 fullscreen.
Editor: Alt+P Play / Stop · Esc stop / deselect · Cmd+Z / Cmd+Shift+Z undo / redo · Alt+1..6 view modes.
-A/B switches (editor and Play; the Output Log shows the state): N motion blur on / off (whatever the scene's post
-settings say) · H the specular history clamp after camera translation on / off (bench-ghosting's fix, docs/ROADMAP.md
-§ 2c).
+A/B switch (editor and Play; the Output Log shows the state): N motion blur on / off (whatever the scene's post
+settings say).
Details fields: drag horizontally across a field to scrub its value (intensities scrub multiplicatively).
Compare (toolbar): ThreeRT Live · UE5 Lumen · UE5 Path Tracer — the UE5 modes split the viewport (drag to move the split).
diff --git a/playground/host/src/main.rs b/playground/host/src/main.rs
index 0058b31..6c792c4 100644
--- a/playground/host/src/main.rs
+++ b/playground/host/src/main.rs
@@ -648,17 +648,12 @@ impl State {
let core = self.core.as_mut();
match (name, core) {
("viewMode", Some(core)) => core.view_mode = c["mode"].as_u64().unwrap_or(0) as u32 % 6,
- // A/B switches for review (docs/REVIEW-21-26.md): motion blur, and PR #24's history clamp after translation.
+ // A/B switch for review (docs/REVIEW-21-26.md): motion blur.
("toggleMotionBlur", Some(core)) => {
core.motion_blur_off = !core.motion_blur_off;
let on = !core.motion_blur_off;
self.log("info", "viewport", if on { "Motion blur ON (scene setting; key N toggles)" } else { "Motion blur OFF (key N toggles)" });
}
- ("toggleGhostFix", Some(core)) => {
- core.ghost_fix_off = !core.ghost_fix_off;
- let on = !core.ghost_fix_off;
- self.log("info", "viewport", if on { "Ghosting fix (PR #24, clamp after translation) ON (key H toggles)" } else { "Ghosting fix (PR #24) OFF: pre-#24 specular history (key H toggles)" });
- }
("bounces", Some(core)) => {
// 0 = auto (governed, up to 4); 1..8 = fixed.
let v = c["value"].as_u64().unwrap_or(0) as u32;
@@ -868,7 +863,6 @@ impl State {
"F11" => self.host_command(&c("fullscreen")),
"1" | "2" | "3" | "4" | "5" | "6" if alt => self.host_command(&json!({ "name": "viewMode", "mode": name.parse::<u32>().unwrap() - 1 })),
"N" if !cmd => self.host_command(&c("toggleMotionBlur")),
- "H" if !cmd => self.host_command(&c("toggleGhostFix")),
_ if !cmd => {
// Game input while playing (the backend ignores keys when no game runs).
let msg = json!({ "type": "key", "key": name });
diff --git a/renderer/shaders/live.wgsl b/renderer/shaders/live.wgsl
index 132360b..3b5b80e 100644
--- a/renderer/shaders/live.wgsl
+++ b/renderer/shaders/live.wgsl
@@ -18,7 +18,7 @@ struct LiveParams {
size: vec4<u32>, // width, height, frame, reset history (1)
misc: vec4<f32>, // exposure scale, max history, vignette intensity, bloom on (1) / off (0)
misc2: vec4<f32>, // denoise strength, sample clamp (display units at the current exposure), -, samples this frame
- mode: vec4<u32>, // view mode (0 lit, 1 base color, 2 world normal, 3 lit no denoise, 4 raw sample, 5 history), frames since the view translated, the scene's lighting is changing (live.rs `live_lighting`), experiment flags
+ mode: vec4<u32>, // view mode (0 lit, 1 base color, 2 world normal, 3 lit no denoise, 4 raw sample, 5 history), -, the scene's lighting is changing (live.rs `live_lighting`), experiment flags
post: vec4<f32>, // chromatic aberration (UE scene fringe), film grain, bloom threshold (<= 0 off), -
ae: vec4<f32>, // auto exposure: low / high fraction, histogram log2 min / max
ae2: vec4<f32>, // compensation (2^bias; manual: the exposure), min / max average luminance, mode (1 = auto)
@@ -124,8 +124,7 @@ fn ycocg_rgb(y: vec3<f32>) -> vec3<f32> {
}
// Experiment switches (THREERT_TEMPORAL_FLAGS): 1 = a-trous gated by history length (round 3), 2 = specular spatial
-// filter on mirror-like surfaces too (round 3), 4 = specular clamp also while the view holds still (UE's literal
-// setting; see the specular block in `temporal`).
+// filter on mirror-like surfaces too (round 3).
fn xflag(b: u32) -> bool { return (L.mode.w & b) != 0u; }
fn lum(c: vec3<f32>) -> f32 {
@@ -632,6 +631,9 @@ fn spec_history(pp: vec3<f32>, n: vec3<f32>, t: f32, rough: f32, virt: bool) ->
return h;
}
+// The most a specular history may trail behind its reflection, output pixels (`stemporal`).
+const SPEC_TRAIL: f32 = 2.0;
+
// Specular temporal accumulation on the traced grid (UE 5.8 Lumen reflections, LumenReflectionDenoiserTemporal.usf): the
// surface history and the reflection-hit one (reprojected through the mirror image of what it shows); the one closer to
// this frame's neighbourhood mean wins. Writes the specular filter's input and the traced grid's g-buffer.
@@ -683,26 +685,44 @@ fn stemporal(@builtin(global_invocation_id) gid: vec3<u32>) {
let mv = motion_in[q];
var hs = vec4<f32>(0.0);
var hv = vec4<f32>(0.0);
+ // What bounds this pixel's history, in output pixels a frame: its own speed (a resampled history blurs a little
+ // every frame) and its reflection's parallax, how far what it reflects moved against the surface (none in a turn of
+ // the camera; the history then trails behind the reflection).
+ var speed = 0.0;
+ var parallax = 0.0;
if (L.size.w == 0u && L.isz.z > 0u) {
let pp = prev_pixel(p + select(vec3<f32>(0.0), mv.xyz, mv.w > 0.5 && t > 0.0));
- if (pp.z > 0.0) { hs = spec_history(pp, n, t, rough, false); }
- // (Not on moving objects: the camera-only reprojection ignores a moving reflector's own motion.)
+ if (pp.z > 0.0) {
+ hs = spec_history(pp, n, t, rough, false);
+ speed = length(sp - 0.5 - pp.xy);
+ // (A moving reflector: the camera-only reprojection ignores its own motion, here and below. Its speed.)
+ parallax = speed;
+ if (mv.w <= 0.5) {
+ // Of the reflected point where this frame has one, else of the farthest (the sample took the diffuse
+ // lobe, or the sky): the most it can be.
+ let pf = prev_pixel(L.cur.pos.xyz + dir * (t + select(1.0e3, min(st, 1.0e3), t > 0.0 && st > 0.0)));
+ parallax = select(0.0, length(pf.xy - pp.xy), pf.z > 0.0);
+ }
+ }
if (t > 0.0 && st > 0.0 && mv.w <= 0.5) {
let pv = prev_pixel(L.cur.pos.xyz + dir * (t + min(st, 1.0e3)));
if (pv.z > 0.0) { hv = spec_history(pv, n, t, rough, true); }
}
}
let cap = select(L.misc.y, min(L.misc.y, 4.0), px.albedo.w > 1.5);
- let moving = any(L.cur.pos.xyz != L.prev.pos.xyz) || any(L.cur.fwd.xyz != L.prev.fwd.xyz);
- let translated = L.mode.y < 8u && !xflag(16384u);
let ys = ycocg(hs.rgb);
let yv = ycocg(hv.rgb);
var surf = select(0.0, 0.8, length(smean - yv) > length(smean - ys) + 0.01 / exposure_scale());
surf = select(surf, 1.0, hv.w <= 0.0);
surf = select(surf, 0.0, hs.w <= 0.0 && hv.w > 0.0);
let hy = mix(yv, ys, surf);
- var max_s = select(cap, mix(2.0, 12.0, clamp(rough / 0.05, 0.0, 1.0)), moving);
- if (translated) { max_s = min(max_s, 4.0); }
+ // The history's length is the pixel's own (until 2026-11-13 every pixel's was held to 2 .. 12 frames by roughness
+ // while the camera moved or turned at all, and to 4 for 8 frames after it translated): HIST_MOVING at a pixel a
+ // frame, as the diffuse; and no longer than keeps its trail behind the reflection (frames x parallax) within
+ // SPEC_TRAIL pixels, 2 frames at least on a mirror, 4 from roughness 0.05 (below that the filter has nothing to
+ // work with).
+ var max_s = mix(cap, min(cap, HIST_MOVING), clamp(speed, 0.0, 1.0));
+ max_s = min(max_s, clamp(SPEC_TRAIL / max(parallax, 1e-4), mix(2.0, 4.0, clamp(rough / 0.05, 0.0, 1.0)), cap));
let frames_s = select(hv.w, hs.w, surf > 0.5);
var count_s = 1.0;
var s_out = cur;
diff --git a/renderer/src/live.rs b/renderer/src/live.rs
index da0262b..d9feecb 100644
--- a/renderer/src/live.rs
+++ b/renderer/src/live.rs
@@ -1126,8 +1126,6 @@ pub struct LiveCore {
post: [f32; 4],
/// Motion blur (UE MotionBlurAmount, MotionBlurTargetFPS; amount 0 = off).
blur: (f32, f32),
- /// Frames since the view last moved sideways or along its axis (0 = this frame; rotation alone keeps counting).
- still: u32,
/// Last submission of each frame still on the GPU (at most two frames in flight).
inflight: std::collections::VecDeque<wgpu::SubmissionIndex>,
pub gpu_ms: f32,
@@ -1159,10 +1157,8 @@ pub struct LiveCore {
pub view_mode: u32,
/// Lockstep frame time (s; benchmarks): motion blur and exposure adaptation use it instead of the wall clock.
pub fixed_dt: Option<f32>,
- /// A/B switches (playground keys N / H): motion blur off whatever the scene's post settings say; the
- /// translation-aware specular history cap of PR #24 off (temporal flag 16384).
+ /// A/B switch (playground key N): motion blur off whatever the scene's post settings say.
pub motion_blur_off: bool,
- pub ghost_fix_off: bool,
pub triangles: usize,
pub scene_name: String,
/// Scene time, s: what `advance_time` added up, the dt each frame script gets, so it is the game's clock (`f.time`)
@@ -1630,7 +1626,7 @@ impl LiveCore {
// brings it, `gpu::loop_guard_of`.)
let guard_read = (gpu::loop_guard_of(!g.hwrt).is_some() && targets.kernel.guard.is_some())
.then(|| (g.device.create_buffer(&wgpu::BufferDescriptor { label: Some("loop guard read"), size: 4, usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false }), Arc::new(AtomicU32::new(0))));
- let mut core = LiveCore { particle_spawns: Default::default(), grid_sources: Default::default(), g, passes, targets, sc, presets: presets.to_path_buf(), assets: assets.to_path_buf(), w, h, seq: 0, aspect: w as f32 / h as f32, cam, prev_cam: cam, frame: 0, history_len: 0.0, reset: true, bloom: ([0.0; 6], [0.0; 6]), vignette: 0.0, post: [0.0; 4], blur: (0.0, 0.0), still: 0, inflight: Default::default(), gpu_ms: 0.0, gpu_frame: 0, gpu_trace_ms: 0.0, edit_ms: 0.0, instanced_ms: 0.0, edit_split: EditSplit::default(), rebuild_ms: 0.0, fallback: None, fallbacks: 0, bounces: 4, rays: true, view_mode: std::env::var("THREERT_VIEW_MODE").ok().and_then(|v| v.parse().ok()).unwrap_or(0), fixed_dt: None, motion_blur_off: false, ghost_fix_off: false, triangles, scene_name, time: 0.0, frame_dt: 1.0 / 60.0, last_frame: Instant::now(), post_key: String::new(), render_scale: 1.0, dynamic_res: false, min_scale: MIN_SCALE, display_scale: 1.0, over_budget: (0, 0), profile, timer, raster, cache, restir, restir_prev: None, kernel_bg, prev_span: None, reposed: false, emitters_moved: false, cold_frames: 0, pose_span: None, pose_reposed: false, inst_moving: vec![], inst_moved: false, prev_isz: (0, 0), lit_changed: 0, spark_lights: false, shown_spp: 1, cpu_skin_ms: 0.0, cpu_upload_ms: 0.0, gpu_blas_ms: 0.0, cpu_wait_ms: 0.0, sky_cover: 0.0, guard_trips: guard_read.as_ref().map(|_| 0), guard_read };
+ let mut core = LiveCore { particle_spawns: Default::default(), grid_sources: Default::default(), g, passes, targets, sc, presets: presets.to_path_buf(), assets: assets.to_path_buf(), w, h, seq: 0, aspect: w as f32 / h as f32, cam, prev_cam: cam, frame: 0, history_len: 0.0, reset: true, bloom: ([0.0; 6], [0.0; 6]), vignette: 0.0, post: [0.0; 4], blur: (0.0, 0.0), inflight: Default::default(), gpu_ms: 0.0, gpu_frame: 0, gpu_trace_ms: 0.0, edit_ms: 0.0, instanced_ms: 0.0, edit_split: EditSplit::default(), rebuild_ms: 0.0, fallback: None, fallbacks: 0, bounces: 4, rays: true, view_mode: std::env::var("THREERT_VIEW_MODE").ok().and_then(|v| v.parse().ok()).unwrap_or(0), fixed_dt: None, motion_blur_off: false, triangles, scene_name, time: 0.0, frame_dt: 1.0 / 60.0, last_frame: Instant::now(), post_key: String::new(), render_scale: 1.0, dynamic_res: false, min_scale: MIN_SCALE, display_scale: 1.0, over_budget: (0, 0), profile, timer, raster, cache, restir, restir_prev: None, kernel_bg, prev_span: None, reposed: false, emitters_moved: false, cold_frames: 0, pose_span: None, pose_reposed: false, inst_moving: vec![], inst_moved: false, prev_isz: (0, 0), lit_changed: 0, spark_lights: false, shown_spp: 1, cpu_skin_ms: 0.0, cpu_upload_ms: 0.0, gpu_blas_ms: 0.0, cpu_wait_ms: 0.0, sky_cover: 0.0, guard_trips: guard_read.as_ref().map(|_| 0), guard_read };
core.spark_lights = core.sc.tables.emitter_tris.iter().any(|e| e.nominal);
core.sky_cover = core.sc.tables.cloud_cover;
core.apply_post(&pp);
@@ -3700,7 +3696,6 @@ impl LiveCore {
self.last_frame = now;
let moved = self.cam != self.prev_cam;
self.update_light_lod();
- self.still = if self.cam.pos != self.prev_cam.pos { 0 } else { self.still.saturating_add(1) };
// A camera cut (a jump no camera makes in one frame: 2 m or 30 degrees) is not motion: no blur (UE: bCameraCut).
let cut = (self.cam.pos - self.prev_cam.pos).length() > 2.0 || self.cam.fwd.dot(self.prev_cam.fwd) < 0.866;
self.cold_frames = if self.reset || cut { 0 } else { self.cold_frames.saturating_add(1) };
@@ -3942,7 +3937,7 @@ impl LiveCore {
// UpdateMotionBlurTimeScale) blurs over +- amount / 2 x the motion x (1 / target FPS) / frame time, the
// actual frame time without a target. 0 while nothing moves (the pass then costs nothing).
misc2: [1.0, SAMPLE_CEILING, if !blur { 0.0 } else if self.blur.1 > 0.0 { self.blur.0 / (self.blur.1 * self.frame_dt.clamp(1.0 / 240.0, 0.25)) } else { self.blur.0 }, spp.max(1) as f32],
- mode: [self.view_mode, self.still, self.live_lighting() as u32, temporal_flags() | if self.ghost_fix_off { 16384 } else { 0 }],
+ mode: [self.view_mode, 0, self.live_lighting() as u32, temporal_flags()],
post: self.post,
ae: self.sc.exposure_settings.ae,
ae2: self.sc.exposure_settings.ae2,