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
A sample's noise is no finding against the upscaler's history (#295)
YXd7e97902c961
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex d03aad6..064b27e 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -2314,6 +2314,49 @@ its two levels: the unchanged trace read the same when alternated).passed by its trail (the light the lamps left on the sky made up the mean); with the trail gone it reads 0.066 for0.1. What it was for is open (Known issues: lamps in motion keep half their light).+**A sample's noise is no finding against the upscaler's history (2026-11-29).** Where a scene's light is sparse (the+lit end of a night street, a hall of small lamps and glossy machines) the upscaled picture sparkled in motion, and+MetalFX's temporal upscaler given the same denoised frames did not. The measure is the change of the picture's+4 × 4 block means from one frame to the next (luma of 255; blocks, so that neither a pixel's own noise nor the+picture's sharpness reads as flicker), beside the scene's own change, which two offline renders a frame apart give+(each with two sample sequences: the mean of their product is the change without the renders' noise). At 960 × 540+and half resolution on an M4, built-in / MetalFX / the scene: the street with its crowd, the camera drifting, 1.39 /+0.50 / 0.54; the hall 1.20 / 0.63 / 0.52; a still room of lamps 0.043 / 0.50 / 0. MetalFX's picture is not the+softer one (0.54 of offline's detail on the street for 0.51).++Where it comes from, one thing changed at a time: not the history's length in motion nor its clamp (`UP_MOVING` 16,+the clamp off, both: within 3 %), nor animated shading's bound. With every sample four times over (at full+resolution, or four a frame) the street reads 0.91, with sixteen 0.68: it is the samples' noise. With `reject`'s+correction and drop both off, 0.47 on both: the noise comes in through `judge` and `reject`. A path tracer's sample+lies outside the range of the history around its point by its noise, a bright one by more than the range, and+`reject` took the mean of the nine nearest for a change from about one standard error.++- `reject` takes the mean over 5 × 5 samples (binomial weights) and counts it by its own standard error: not under 2+ (`UP_FINDING`), in full from 4 (`UP_CERTAIN`). `judge`'s distance of a sample from the history's range stays: the+ sample less the history's mean around it, tried first, differs by the jitter over whole regions at once, and the+ still room read 0.50 for 0.043.+- While the scene's lighting changes a history holds 8 samples (`UP_LIVE`) for 16, as the denoiser's histories are+ bounded then (`HISTORY_LIVE`), and 16 at a thin feature's lock. (The same bound for every history that is+ resampled, tried first, made a wall behind lamps finer than a pixel change a fifth more than before.)++Before → after: the street 1.39 → 1.01, the hall 1.20 → 0.85, the room 0.043 → 0.033; their detail against offline+0.506 → 0.498, 0.687 → 0.681, 0.838 → 0.837. Eleven clips against offline: ΔE the same or less on each (a city+through an afternoon in ten seconds 2.32 → 1.91, the street 3.48 → 3.41, the hall 3.33 → 3.24); whole pixels' change+from a frame to the next 2.08 → 1.55 on the street, 2.04 → 1.64 in the hall, 0.44 → 0.20 behind glass, 0.31 → 0.24+walking through a gallery, 0.46 → 0.49 in the city's afternoon. `bench-ghosting --quick --check`: every check as+before or better (turn 0.85 → 0.80, strafe 1.36 → 1.30, after the stop 1.32 → 1.33). `bench-object-ghosting`:+fifteen of sixteen moments as before or better, the thrown lamp 0.3 s after its stop 1.95 → 1.98.+`bench-temporal --shot edit`: the same frames to settle on every row. Frame time, the two builds alternated: from+2.2 % less to 0.8 % more over twelve clips.++The thresholds are a trade. At 3 and 6 the street reads 0.63 and the hall 0.67, and what a moving object leaves+behind is 5 to 18 % more (a thrown lamp's trail 105 pixels for 59 a tenth of a second after it stops); at 2.5 and 5,+0.76 and 0.72 for 1 to 9 % more; at 1.5 and 3 the street reads 1.61. Not done: a change keeps its sign from frame to+frame and noise does not, so evidence gathered over frames would tell them apart where one frame cannot; and a mean+over larger regions would find a change that is slow and everywhere (that afternoon's light), which the bound on the+history only contains. Test: `a_noisy_picture_holds_from_frame_to_frame` (thirty-six lamps a centimetre wide before a+wall, the camera drifting: the 4 × 4 means change 1.45 steps a frame before, 1.10 now). Not checked on Vulkan.+**The live passes from one place (2026-11-14, after it).** A buffer and a pass more (the locks' carry, above) tookseven edits that had to agree: the declaration in live.wgsl, the bind group layout's entries, the pass list, thebuffers' sizes and order, the bind group's entries, the dispatch grid (in two copies), and the merged layout's table.diff --git a/docs/RUNTIME.md b/docs/RUNTIME.mdindex 48754b9..1e7b6b6 100644--- a/docs/RUNTIME.md+++ b/docs/RUNTIME.md@@ -1837,6 +1837,8 @@ Three more, measured on whole scenes against the offline render in linear radian3.8 % dark: 2.2 for the bounces, 1.0 for the live indirect clamp, 0.7 for the cache.- The upscaler's history of a sky seen directly lags a sky that changes fast: in a time-lapse that dims it 1 % aframe the picture reads 4 % bright, and comes down in 64 to 128 frames once the clock is held.+ (Measured before the history came to hold 8 samples while the lighting changes, 2026-11-29: that time-lapse's ΔE+ against offline went from 2.32 to 1.91 with it; the 4 % has not been measured again.)## Live rendering settings@@ -2277,8 +2279,18 @@ over a polished floor, a character running over a sunlit floor, the camera still+A traced sample's noise is not taken for a change (2026-11-29): `reject` corrects and drops the upscaler's history by+the mean distance of the 5 × 5 samples around a traced pixel from the history's range, counted by its own standard+error (not under 2, in full from 4). A path tracer's sample lies outside that range by its noise; the mean of the+nine nearest, taken from about one standard error, wrote it into the history wherever the light is sparse (a night+street with a crowd: the picture's 4 × 4 block means changed 1.39 from a frame to the next where the scene's own+change is 0.54, now 1.01; docs/ROADMAP.md § 1a, the entry of that date, has the measurements and what the+thresholds trade against). And while the lighting is live the upscaler's history holds 8 samples for 16 (`UP_LIVE`),+as the denoiser's do, but for a thin feature's.+Not covered: a change of the light too small or too noisy for the change chart and the drift, and any change-where the light comes by rare samples, trail by the frame's bound (`HISTORY_LIVE`). A fast light's effect on diffuse+where the light comes by rare samples, trail by the frame's bound (`HISTORY_LIVE`; the upscaler's history by+`UP_LIVE`). A fast light's effect on diffuselighting (a shadow it casts) still lags by the two to four frames the chart needs, and the band just uncoveredstarts from this frame's samples (more aliased for a frame or two, as any disocclusion).diff --git a/renderer/shaders/live.wgsl b/renderer/shaders/live.wgslindex 0f3c2f2..2b9d1ab 100644--- a/renderer/shaders/live.wgsl+++ b/renderer/shaders/live.wgsl@@ -1484,6 +1484,17 @@ fn track(@builtin(global_invocation_id) gid: vec3<u32>) {// still, and moving UP_SPEED output pixels a frame or faster.const UP_SAMPLES: f32 = 16.0;const UP_MOVING: f32 = 4.0;+// The most it holds while the scene's lighting changes (`L.mode.z`), as the denoiser's histories are bounded then+// (live/mod.rs `HISTORY_LIVE`): a change of the lighting too slow or too noisy for `reject` to find trails by the+// history's length. A city through an afternoon in ten seconds, the camera still, ΔE against offline 2.32 → 1.91 (a+// still view gathers less under a light that changes: 0.95 of offline's detail → 0.91). Not at a thin feature+// (`Lock`): a lamp finer than a pixel is hit once in a jitter sequence, and a history shorter than the sequence shows+// each hit (thirty-six lamps a centimetre wide before a wall while something moves: the picture's 4 x 4 means change+// 1.40 steps of 255 a frame without the exception, 1.27 with it; the city's ΔE is 1.81 without it). Tried and not+// kept: the same bound for every history that is resampled, whatever the lighting does (no clip's picture, detail or+// flicker differs between 12 and 16 samples there, and with 8 the lamps' wall changes a fifth more than it did);+// 8 samples everywhere (a still room of lamps changes a quarter more from frame to frame).+const UP_LIVE: f32 = 8.0;const UP_SPEED: f32 = 1.0;// The reconstruction kernel exp(-UP_SHARP d^2), d in output pixels from the pixel's centre to a traced sample.const UP_SHARP: f32 = 3.5;@@ -1509,6 +1520,10 @@ const UP_ONSET: f32 = 4.0;// A surface counts as gone from in front when what is nearest now lies behind what was nearest by this share of its// depth (`judge`), and the history as stale there when it lies outside this frame's range by UP_STALE of its luminance.const UP_GONE: f32 = 0.05;+// How many of its own standard errors the mean distance of the samples around a traced pixel stands from zero before+// it counts as a finding against the history, and from where it counts in full (`reject`).+const UP_FINDING: f32 = 2.0;+const UP_CERTAIN: f32 = 4.0;const UP_STALE: f32 = 0.05;// History rejection at the render resolution (where UE's TSR judges its history too), in two passes. What a frame@@ -1798,9 +1813,24 @@ fn judge(@builtin(global_invocation_id) gid: vec3<u32>) {// `reject`: per traced pixel, into `spec_pp`'s slot 0 (free once the specular filter is done; f16): the correction// `upscale` adds to every output pixel's history here (linear RGB), and the share of that history to drop. The-// correction is the mean of the nine samples' distances less what their scatter explains (noise, which the blend-// averages); a correction that is a large share of the colour drops the history too, as do samples that found none-// and one whose history is of something gone.+// correction is the mean of the distances of the 5 x 5 samples around (binomial weights), as far as it is a finding. A+// traced sample is noisy: one bright sample of a lamp's light lies outside the history's range by more than the range,+// and its distance is no change of the picture. Noise is spread about zero and a change is one way, so the mean counts+// by how many of its own standard errors (the samples' scatter over the root of their number) it stands from zero:+// not under UP_FINDING, in full from UP_CERTAIN. A correction that is a large share of the colour drops the history+// too, as do samples that found none (asked of the nine nearest) and one whose history is of something gone.+// (Before, the mean of the nine nearest counted less half its scatter's share of it, about one standard error, and a+// bright sample or two among the nine passed for a change: the history was corrected by noise and dropped, anew every+// frame where the light is sparse. The change of a picture's 4 x 4 block means from a frame to the next, luma of 255,+// at 960 x 540 and half resolution on an M4, 2026-11-29, before / after / the scene's own (two offline renders a frame+// apart): a night street with a crowd, the camera drifting, 1.39 / 1.01 / 0.54; a hall of moving machines 1.20 / 0.85+// / 0.52; a still room of lamps 0.043 / 0.033 / 0. With every sample four times over the rule before read 0.91 and+// 0.90 to 1.00: the excess was the samples' noise. The thresholds are the highest at which what a moving object leaves+// behind is no worse (bench-object-ghosting: of sixteen moments fifteen as before or better, one 1.5 % more). At 2.5+// and 5 the three clips read 0.76, 0.72, 0.024 and that error 1 to 9 % more; at 3 and 6, 0.63, 0.67, 0.024 and 5 to+// 18 % more, a thrown lamp's trail 105 pixels for 59 a tenth of a second after it stops; at 1.5 and 3 the street+// reads 1.61. A change keeps its sign from frame to frame and noise does not: within one frame they are told no+// further apart. Over 7 x 7 samples: the same as over 5 x 5. The frame's time is as it was, clips alternated.)@compute @workgroup_size(8, 8, 1)fn reject(@builtin(global_invocation_id) gid: vec3<u32>) {let iw = i32(L.isz.x);@@ -1809,22 +1839,29 @@ fn reject(@builtin(global_invocation_id) gid: vec3<u32>) {let q = gid.y * L.isz.x + gid.x;let e = exposure_scale();var kern = array<f32, 2>(0.5, 0.25);+ var wide = array<f32, 3>(0.375, 0.25, 0.0625);var d1 = vec3<f32>(0.0);var x1 = 0.0;var x2 = 0.0;var level = 0.0;var wsum = 0.0;+ var wsq = 0.0;var wall = 0.0;- for (var k = 0; k < 9; k++) {- let dx = k % 3 - 1;- let dy = k / 3 - 1;+ var wfound = 0.0;+ for (var k = 0; k < 25; k++) {+ let dx = k % 5 - 2;+ let dy = k / 5 - 2;let qx = i32(gid.x) + dx;let qy = i32(gid.y) + dy;if (qx < 0 || qy < 0 || qx >= iw || qy >= ih) { continue; }- let wt = kern[abs(dx)] * kern[abs(dy)];- wall += wt;+ // (Whether a sample found a history is asked of the nine nearest.)+ var w9 = 0.0;+ if (abs(dx) <= 1 && abs(dy) <= 1) { w9 = kern[abs(dx)] * kern[abs(dy)]; }+ wall += w9;let j = judged_at(u32(qy * iw + qx));if (j.lum < 0.0) { continue; }+ wfound += w9;+ let wt = wide[abs(dx)] * wide[abs(dy)];let hw = 1.0 / (1.0 + j.lum * e);let x = lum(j.d) * hw;d1 += j.d * wt;@@ -1832,17 +1869,21 @@ fn reject(@builtin(global_invocation_id) gid: vec3<u32>) {x2 += x * x * wt;level += j.lum * hw * wt;wsum += wt;+ wsq += wt * wt;}var delta = vec3<f32>(0.0);var drop = 1.0;if (wsum > 0.0) {- // The scatter of the distances about their mean (in luminances compressed by the exposure, so a bright- // sample's noise counts as a dark one's): a mean of nine carries about a third of it.+ // The mean's standard error: the scatter of the distances about it (in luminances compressed by the exposure,+ // so a bright sample's noise counts as a dark one's) over the root of their number, which for weighted samples+ // is the square of the weights' sum over the sum of their squares (13 of the 25).let mean = x1 / wsum;- let sd = sqrt(max(x2 / wsum - mean * mean, 0.0));- let keep = clamp(1.0 - 0.5 * sd / max(abs(mean), 1e-12), 0.0, 1.0);+ let n = wsum * wsum / max(wsq, 1e-12);+ let se = sqrt(max(x2 / wsum - mean * mean, 0.0) / max(n - 1.0, 1.0));+ let keep = clamp((abs(mean) / max(se, 1e-12) - UP_FINDING) / (UP_CERTAIN - UP_FINDING), 0.0, 1.0);delta = d1 / wsum * keep;- let found = wsum / wall;+ var found = 0.0;+ if (wall > 0.0) { found = wfound / wall; }drop = clamp(abs(mean) * keep / (UP_REJECT * level / wsum + 0.01 / e), 0.0, 1.0) * found + (1.0 - found);}// (Its history is of something that is gone from in front of this: all of it goes; and where what went was moving,@@ -1978,7 +2019,10 @@ fn upscale(@builtin(global_invocation_id) gid: vec3<u32>) {var hc = max(hist.rgb + verdict.xyz, vec3<f32>(0.0));// (And where the light changed among the samples around: the history is of the light before.)hc = mix(hc, clamp(hc, xlo, xhi), max(moving, shaded) * (1.0 - lock));- let most = min(mix(UP_SAMPLES, UP_MOVING, moving), mix(UP_SAMPLES, UP_REACTIVE, clamp(sample_vel[u32(bc.y * iw + bc.x)].w, 0.0, 1.0)));+ // (While the lighting changes it holds UP_LIVE, but for a thin feature.)+ var rest = UP_SAMPLES;+ if (L.mode.z != 0u) { rest = mix(UP_LIVE, UP_SAMPLES, lock); }+ let most = min(mix(rest, UP_MOVING, moving), mix(UP_SAMPLES, UP_REACTIVE, clamp(sample_vel[u32(bc.y * iw + bc.x)].w, 0.0, 1.0)));count = min(kept + conf, most);let a = clamp(conf / max(count, 1e-4), 0.0, 1.0);outc = mix(hc, cur, a);diff --git a/renderer/src/live/inplace_tests.rs b/renderer/src/live/inplace_tests.rsindex d96c8f3..d38370c 100644--- a/renderer/src/live/inplace_tests.rs+++ b/renderer/src/live/inplace_tests.rs@@ -5426,3 +5426,50 @@ fn the_camera_at_the_worlds_origin_sees_what_it_sees_elsewhere() {assert!(d < 1.0, "{what}: from the world's origin the picture is {d:.2} steps from the one seen 0.4 m away (means {a:.1} for {b:.1})");}}++/// A wall lit by thirty-six lamps a centimetre wide (a path's light is one of them: a sample a pixel is noisy), traced+/// at half the output's resolution, the camera drifting a twentieth of a pixel a frame: how much the means of 4 x 4+/// pixels change from one frame to the next. The samples' noise is no finding against the upscaler's history+/// (live.wgsl `reject`: the mean of the samples around counts by its standard error), so the history is neither+/// corrected by it nor dropped for it: 1.10 steps of 255 on an M4, where the mean of the nine nearest, less half its+/// scatter, gave 1.45.+#[test]+fn a_noisy_picture_holds_from_frame_to_frame() {+ let presets = crate::default_presets_dir();+ let mut w = world();+ // (The sun and the lamp away: the small lamps before the wall light it.)+ w.set_visible(20, false).unwrap();+ w.set_visible(12, false).unwrap();+ w.set_material(6, serde_json::from_value(serde_json::json!({ "name": "spark", "color": [0.0, 0.0, 0.0], "opacity": 1, "metalness": 0, "roughness": 1, "emissive": [1, 0.8, 0.6], "emissiveIntensity": 20000.0, "doubleSided": true })).unwrap());+ w.set_geometry(7, Geometry { positions: vec![-0.005, -0.005, 0.0, 0.005, -0.005, 0.0, 0.005, 0.005, 0.0, -0.005, 0.005, 0.0], normals: [0.0, 0.0, 1.0].repeat(4), uvs: vec![0.0; 8], indices: vec![0, 1, 2, 0, 2, 3], groups: vec![], colors: vec![] }).unwrap();+ for i in 0..36u32 {+ w.set_object(100 + i, format!("spark {i}"), None, Kind::Mesh { geometry: 7, material: 6, own_blas: false, materials: vec![] }, true, false).unwrap();+ w.set_transform(100 + i, Vec3::new(-0.75 + 0.3 * (i % 6) as f32, -0.75 + 0.3 * (i / 6) as f32, 0.15), glam::Quat::IDENTITY, Vec3::ONE).unwrap();+ }+ let mut live = match gpu::Gpu::new().and_then(|g| LiveCore::new(g, &w, Path::new("."), &presets, 96, 54)) {+ Ok(c) => c,+ Err(e) => return eprintln!("skipped: {e}"),+ };+ live.set_scale(0.5);+ w.take_changes();+ let frame = |k: u32, live: &mut LiveCore, w: &mut World| {+ w.set_transform(4, Vec3::new(0.004 * k as f32, 0.0, 5.0), glam::Quat::IDENTITY, Vec3::ONE).unwrap();+ live.commit(w).unwrap();+ picture(live, 1)+ };+ let blocks = |p: &[u8]| -> Vec<f64> { (0..13 * 24).map(|b| region_mean(p, [b % 24 * 4, b / 24 * 4, b % 24 * 4 + 4, b / 24 * 4 + 4])).collect() };+ let mut last = Vec::new();+ for k in 0..48 {+ last = frame(k, &mut live, &mut w);+ }+ let mut change = 0.0;+ for k in 48..64 {+ let next = frame(k, &mut live, &mut w);+ change += (blocks(&last).iter().zip(blocks(&next)).map(|(a, b)| (a - b) * (a - b)).sum::<f64>() / (13.0 * 24.0)).sqrt() / 16.0;+ last = next;+ }+ let lit = region_mean(&last, [0, 0, 96, 54]);+ eprintln!("HOLDS: the picture's 4 x 4 means change {change:.3} steps a frame (its mean {lit:.1})");+ assert!(lit > 10.0, "the lamps light the wall: the picture's mean is {lit:.1}");+ assert!(change < 1.25, "the picture's 4 x 4 means change {change:.3} steps from a frame to the next");+}