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.
Rust electron-alternativegame-engineglobal-illuminationgraphicsjavascript-runtimemetalpath-tracingray-tracingreal-time-renderingrenderingrustthreejstypescriptvoxelvulkanwebgpuwgpu
History lengths per pixel within one bound: no edit cuts the whole frame's history (ROADMAP § 1a) (#33)
Yujiaf2dfb0bb3d58
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 005eb69..1b1091d 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -1777,8 +1777,37 @@ Measured on the M5 Pro (`out/liveq/gpu-runs-std.md`; single runs unless said):set again from this build's readings with the margins the old ones had (tools/bench-ghosting.ts); the trails'limits and the other shots' stand.-Not done here: the whole-frame history caps of the traced grid's accumulations (48 frames while the camera moves, 16-after a lighting change, 4 after a geometry edit, 24 with spark lights) and filters sized by hit distance; the+**History lengths (2026-11-12, after it).** The whole frame's history was cut by what happened in the scene: held to+48 frames while the camera moved, every pixel cut to 16 at a lighting edit and to 4 at a geometry edit, 24 for good in+a scene with spark lights. Now one bound while the scene's lighting changes (32 frames, a real-time denoiser's: NRD's+default is 30; `HISTORY_LIVE`), the long history once it has settled, and within it each pixel's own: 48 where it+moves a pixel a frame, and an anti-lag that cuts the irradiance history by how far its fast mean left the slow one+beyond their noise (ReBLUR's form; it was on / off). No edit cuts anything.++| dE against the offline render or the converged frame | main | this |+|---|---|---|+| the Bistro slice half a second after its explosion (2560 × 1440, scale 0.375) | 6.58 | 6.03 |+| the Bistro slice at rest, 5 s in | 2.79 | 2.82 |+| Kabukichō 2 s / 4 s after its signs close (bench-temporal at 0.5, real time) | 6.56, 6.61 / 2.82, 2.86 | 6.58, 6.70, 7.73 / 2.91, 2.92, 2.95 |+| bench-ghosting excess, Bistro (turn-mid, strafe-mid ground; the two returns; stop + 0.1 s) | 1.17, 1.85, 1.38, 1.47, 1.59 | 1.08, 1.76, 1.25, 1.34, 1.50 |+| the same, Kabukichō | 2.46, 3.31, 1.25, 1.29, 2.52 | 2.42, 3.26, 1.14, 1.20, 2.47 |++- What was tried and left out, each measured (`out/liveq/gpu-runs-std.md`, H1–H31):+ - no bound at all: a long history lags behind what moves (the explosion 5.94 with SSIM 0.809 for 0.832);+ - 64 frames: the explosion reads better (5.72) but a lighting edit is followed a second late (the signs 7.82 / 3.37);+ - the cuts at edits kept beside the new bound: as main (the explosion 6.69): a cut is the whole frame's for a+ change in one corner;+ - an anti-lag on the specular (its fast mean kept with the moments): at one sample a pixel that mean is noise, and+ cutting by it cost more than the lag (the slice at rest 2.98 for 2.82);+ - the anti-lag in a settled scene: it finds noise (a still Bistro 2.43 for 2.23). It runs while the lighting+ changes, as before.+- A lighting edit is followed a little later than under main's cut, sometimes (the table's third row; the bench runs+ in real time and its 2 s reading was already too run-dependent to gate on).+- By day none of this shows (Thames through fifteen explosions: frame to frame the same as main to 0.02): the sun's+ direct light and the upscaler's own history carry the frame. A geometry edit by night was not measured.+- Cost: none that shows (Bistro's passes 6.64–6.66 ms a frame in both builds).++Not done here: filters sized by hit distance, which is what would let a short history stand without noise; thePlayground and the page still open a 1280 × 720 view; the live buffers are sized by the output (about 1.7 GB at2560 × 1440), though the traced grid rarely fills it.diff --git a/renderer/shaders/live.wgsl b/renderer/shaders/live.wgslindex 5a7baf9..04f2d3d 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, lighting edited in the last 45 frames, experiment flags+ 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 flagspost: vec4<f32>, // chromatic aberration (UE scene fringe), film grain, bloom threshold (<= 0 off), -ae: vec4<f32>, // auto exposure: low / high fraction, histogram log2 min / maxae2: vec4<f32>, // compensation (2^bias; manual: the exposure), min / max average luminance, mode (1 = auto)@@ -334,6 +334,11 @@ fn same_surface_n(tx: i32, ty: i32, z: f32, n: vec3<f32>, t: f32, ncos: f32) ->// History length (frames) from which `dtemporal` reprojects the pixel's centre instead of its jittered sample.const HIST_CENTRE: f32 = 16.0;+// The most frames the irradiance history holds where the pixel moves a pixel a frame or more (it is resampled every+// frame, each time a little blurrier), and the relative difference of its fast mean from its slow one, beyond their+// noise, at which anti-lag leaves it two frames (`dtemporal`).+const HIST_MOVING: f32 = 48.0;+const ANTILAG: f32 = 0.15;// Diffuse history length from which the firefly cut stops (dtemporal).const FIREFLY_FRAMES: f32 = 16.0;@@ -361,6 +366,7 @@ fn dtemporal(@builtin(global_invocation_id) gid: vec3<u32>) {var hd = vec4<f32>(0.0);var hm = vec4<f32>(0.0);var around = vec2<f32>(-1.0);+ var speed = 0.0; // output pixels this framelet ps = vec2<i32>(L.isz.zw);if (L.size.w == 0u && ps.x > 0) {let mv = motion_in[q];@@ -406,6 +412,7 @@ fn dtemporal(@builtin(global_invocation_id) gid: vec3<u32>) {hd = vec4<f32>(0.0);hm = vec4<f32>(0.0);}+ speed = length(sp - 0.5 - pp.xy);// Slow / fast means over the 3x3 around it on the same surface (anti-lag compares them).if (t > 0.0 && L.mode.z != 0u) {var acc = vec2<f32>(0.0);@@ -423,14 +430,17 @@ fn dtemporal(@builtin(global_invocation_id) gid: vec3<u32>) {}}}- let cap = select(L.misc.y, min(L.misc.y, 4.0), anim);+ // How long the history may be at most is the frame's (`misc.y`: live.rs HISTORY_LIVE while the scene's lighting+ // changes, far longer once it has settled); within it, each pixel's own: less where it moves (until 2026-11-12 the+ // whole frame's was held to 48 while the camera moved), a few frames on animated shading, and anti-lag below.+ let cap = mix(select(L.misc.y, min(L.misc.y, 4.0), anim), min(L.misc.y, select(HIST_MOVING, 4.0, anim)), clamp(speed, 0.0, 1.0));var m1 = hm.x;var m2 = hm.y;let sd = sqrt(max(m2 - m1 * m1, 0.0));if (hd.w >= 4.0 && hd.w < FIREFLY_FRAMES) {// Firefly, while the history is young (after a disocclusion or a lighting change): a sample moves the pixel by// (l - mean) / frames; cut only what would show as a sparkle (more than half the mean above it). Not from- // FIREFLY_FRAMES on: histories are capped (48 frames moving, 24 with sparks), so a cut tied to the frame count+ // FIREFLY_FRAMES on: histories are capped (48 frames moving, 32 while the scene's lighting changes), so a cut tied to the frame count// kept clipping the rare bright samples of small strong lights for good. Bistro crowd at 10 s, held: diffuse// 0.70 of our offline render with it, 0.82 without; moving ΔE 15.3 -> 12.9.let hi = m1 + 4.0 * sd + 0.5 * m1 * hd.w + 1e-4;@@ -438,14 +448,20 @@ fn dtemporal(@builtin(global_invocation_id) gid: vec3<u32>) {}let fast = select(l, mix(hm.z, l, 0.25), hd.w > 0.0);var count = min(hd.w + 1.0, cap);- // Anti-lag: around this point the fast average left the slow one by more than its (neighbourhood-averaged)- // noise allows: the lighting changed here (a sign switched off, a door opened). Restart the history locally- // instead of capping it everywhere.+ // Anti-lag (as ReBLUR's): around this point the fast average left the slow one by more than its+ // (neighbourhood-averaged) noise allows: the lighting changed here (a sign switched off, a door opened, a wall+ // gone, a spark passing). The history is cut by how far, down to two frames at ANTILAG of the mean: a slow change+ // shortens it a little every frame until it follows, a sudden one restarts it. While the scene's lighting changes+ // (`mode.z`): once it has settled there is nothing to find, and what the test then finds is noise (a still Bistro+ // read dE 2.43 against offline with it always on, 2.23 without).+ // (The specular has none: at one sample a pixel its fast mean is noise, and cutting by it cost more than the lag:+ // the Bistro slice at 5 s read dE 2.98 with it for 2.82.)if (L.mode.z != 0u && hd.w >= 6.0 && around.x >= 0.0) {- let dev = abs(around.y - around.x);- if (dev > 3.0 * 0.38 * sd / 3.0 + 0.15 * max(around.x, around.y) + 1e-4) {- count = min(count, 2.0);- m1 = around.y;+ let over = abs(around.y - around.x) - 3.0 * 0.38 * sd / 3.0 - 1e-4;+ let keep = 1.0 - clamp(over / (ANTILAG * max(max(around.x, around.y), 1e-6)), 0.0, 1.0);+ if (keep < 1.0) {+ count = max(min(count, hd.w * keep + 1.0), 2.0);+ m1 = mix(around.y, m1, keep);m2 = m1 * m1 + sd * sd;}}diff --git a/renderer/src/live.rs b/renderer/src/live.rsindex 419ce06..07cb725 100644--- a/renderer/src/live.rs+++ b/renderer/src/live.rs@@ -1119,8 +1119,6 @@ pub struct LiveCore {pub frame: u32,pub history_len: f32,reset: bool,- /// Max history for the next frame after a scene update (keeps geometry history, fades stale lighting fast).- cap_next: Option<f32>,/// Bloom stage radii / tints (`bloom_stages`).bloom: ([f32; 6], [f32; 6]),vignette: f32,@@ -1543,8 +1541,15 @@ const CACHE_FRAMES_LIT: f32 = 4.0;const VOLUME_TRAIN_SHARE: f32 = 1.0 / 8.0;/// Media voxel training points per frame (pathtrace.wgsl MEDIA_TRAIN_POINTS).const MEDIA_TRAIN_POINTS: u32 = 4096;-/// Diffuse history cap (frames) in scenes with light-sampled particles.-const SPARK_HISTORY: f32 = 24.0;+/// The most frames a pixel's history holds while the scene's lighting changes: short enough to follow the change by+/// itself (a real-time denoiser's bound: NRD's default is 30), so no edit has to cut it. Against main's rules (24+/// frames for good in a scene with spark lights, every pixel cut to 16 at a lighting edit, an on / off anti-lag), dE+/// against the offline render or the converged frame: the Bistro slice half a second after its explosion 6.04 for+/// 6.58, at rest 2.82 for 2.79; Kabukichō 2 s and 4 s after its signs close 6.70 and 2.92 for 6.56 and 2.82. At 64+/// frames the explosion read 5.72 and the signs 7.82 and 3.37.+const HISTORY_LIVE: f32 = 32.0;+/// The most once the scene has settled: holding still, the frame converges on the offline render.+const HISTORY_FRAMES: f32 = 4096.0;/// THREERT_TL_HIDE (diagnostics): the translucency pass trains the volume voxels but draws nothing, so frames show what is/// behind translucent particles; `odd` hides them on odd frames only (rain on / off pairs from one run).@@ -1625,7 +1630,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, cap_next: None, 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), 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 };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);@@ -1723,7 +1728,6 @@ impl LiveCore {self.edit_ms += t.elapsed().as_secs_f32() * 1e3;// As after a rebuild: history validated per pixel, the reservoirs' triangle indices dropped.self.restir_prev = None;- self.cap_next = Some(4.0);self.lit_changed = self.frame.max(1);}Err(why) => {@@ -1906,10 +1910,9 @@ impl LiveCore {self.sc.dof = c.dof.clone();self.cam = self.sc.scene_camera;}- // Lighting changed: a mild global history cap for one frame (indirect light follows within ~0.25 s); where the- // change is strong the temporal pass restarts the history locally (anti-lag).+ // Lighting changed: for 45 frames the histories hold HISTORY_LIVE frames at most (`live_lighting`), and where the+ // change is strong the temporal pass cuts the history locally (anti-lag).if d.materials || d.lights || d.objects || d.environment {- self.cap_next = Some(self.cap_next.map_or(16.0, |c| c.min(16.0)));self.lit_changed = self.frame.max(1);}// (A new cloud cover re-bakes the sky and dims the sun as a sun move does.)@@ -1953,7 +1956,6 @@ impl LiveCore {self.put_sky(b);}}- self.cap_next = Some(self.cap_next.map_or(16.0, |c| c.min(16.0)));self.lit_changed = self.frame.max(1);}@@ -2284,7 +2286,6 @@ impl LiveCore {enc.copy_buffer_to_buffer(&r.staging, 0, &self.sc.up.emitters, 0, r.bytes.min(self.sc.up.emitters.size()));self.g.queue.submit([enc.finish()]);self.emitter_params(r.entries, r.total, r.power);- self.cap_next = Some(self.cap_next.map_or(16.0, |c| c.min(16.0)));self.lit_changed = self.frame.max(1);}@@ -2302,8 +2303,7 @@ impl LiveCore {if !powers.is_empty() {e.put_powers(&powers);self.g.queue.write_buffer(&self.sc.up.objects, 0, bytemuck::cast_slice(&e.objects));- // The lighting changed (as when a result lands): the history cap and the anti-lag restart.- self.cap_next = Some(self.cap_next.map_or(16.0, |c| c.min(16.0)));+ // The lighting changed (as when a result lands): `live_lighting` for the next 45 frames.self.lit_changed = self.frame.max(1);}}@@ -3507,7 +3507,6 @@ impl LiveCore {self.prev_span = None;self.pose_span = None;self.emitters_moved = false;- self.cap_next = Some(4.0);self.lit_changed = self.frame.max(1);Ok(())}@@ -3568,6 +3567,12 @@ impl LiveCore {self.dynamic_res = true;}+ /// The scene's lighting is changing: something moved or was edited in the last 45 frames, or the scene has spark+ /// lights (light-sampled particles: they move every frame, and no edit says so).+ fn live_lighting(&self) -> bool {+ self.spark_lights || (self.lit_changed > 0 && self.frame.wrapping_sub(self.lit_changed) < 45)+ }+/// Fixed render scale (`s` in SCALE_FLOOR ..= 1), or dynamic resolution (`s` = 0).pub fn set_scale(&mut self, s: f32) {self.dynamic_res = s <= 0.0;@@ -3704,12 +3709,11 @@ impl LiveCore {// Camera motion is reprojected exactly (disocclusions are rejected per pixel), so history survives motion;// the cap only bounds smearing of view-dependent shading (glossy reflections).// Diffuse lighting reprojects exactly with the camera; view-dependent specular is handled per pixel (temporal pass).- let mut cap = if self.reset { 1.0 } else if let Some(c) = self.cap_next.take() { c } else if moved { 48.0 } else { 4096.0 };- // Light-sampled particles (sparks) light surfaces for a moment and fade gradually, which anti-lag (a sudden- // change) does not catch: a short history lets the lit surfaces follow them.- if self.spark_lights {- cap = cap.min(SPARK_HISTORY);- }+ // The most frames a pixel's history holds: HISTORY_LIVE while the scene's lighting changes, HISTORY_FRAMES once+ // it has settled. Within it the length is each pixel's own (live.wgsl `dtemporal`: less where it moves, anti-lag+ // where its lighting changes, restarted where its surface is new). No edit cuts it: until 2026-11-12 a+ // lighting edit left every pixel 16 frames and a geometry edit 4, the whole frame for a change in one corner.+ let cap = if self.reset { 1.0 } else if self.live_lighting() { HISTORY_LIVE } else { HISTORY_FRAMES };self.history_len = if self.reset { 1.0 } else { (self.history_len + 1.0).min(cap) };let cam = self.cam;let g = &self.g;@@ -3816,10 +3820,7 @@ impl LiveCore {if self.cache.is_some() {// Light-sampled particles (sparks: Particles emitterArea) move their light every frame: the cache and// the temporal pass keep the short history of a lighting edit while the scene has them.- if self.spark_lights {- self.lit_changed = self.frame.max(1);- }- let lit = self.lit_changed > 0 && self.frame.wrapping_sub(self.lit_changed) < 45;+ let lit = self.live_lighting();let cold = if self.cold_frames >= COLD_FALLBACK_FRAMES { 1 } else { 0 };p.cache = [1.0, CACHE_SAMPLES, if lit { CACHE_FRAMES_LIT } else { CACHE_FRAMES }, (cache_flags() | cold) as f32];}@@ -3941,7 +3942,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.lit_changed > 0 && self.frame.wrapping_sub(self.lit_changed) < 45) as u32, temporal_flags() | if self.ghost_fix_off { 16384 } else { 0 }],+ mode: [self.view_mode, self.still, self.live_lighting() as u32, temporal_flags() | if self.ghost_fix_off { 16384 } else { 0 }],post: self.post,ae: self.sc.exposure_settings.ae,ae2: self.sc.exposure_settings.ae2,