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
The upscaler's tolerance from the samples' own flicker: no glow along a silhouette under a light that changes (ROADMAP § 1a) (#59)
Yujiaced8a0118c14
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex b9c6794..a21282e 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -1993,6 +1993,53 @@ cut by luminance stays beside it. `bench-temporal --shot edit`, ΔE against theview with no memory at half a second. The long history on a settled scene is untouched: nothing measured herespeaks against it.+**The upscaler's tolerance from the samples' own flicker (2026-11-13, after it).** The Tokyo clip of the site's reel+(the afternoon into night in ten seconds, the camera still) showed every roof and the tower outlined in the sky of+seconds ago, a glow ten pixels wide. The raw samples and the denoiser's accumulations are clean there; it is the+upscaler's history. `judge` holds each traced sample against the range of the history's nine pixels around its+point, and allowed it half that range outside (a point against means: detail finer than a pixel). The allowance was+measured on the history it judges: beside a roof the range runs from the roof to the old sky, so the sky could dim+by half of that unseen; the pixel left behind widened the range of the next, and so outward. With the verdicts off+the clip is 15 times too bright (a 16-sample blend under a sky that falls 4 % a frame), which is what the outlines+were.++- The allowance is the samples' now (`Flicker`, kept by `compose` in the two words the fast mean's buffer had+ free): how much the composed sample at a surface changes from frame to frame under the jitter, as a share of its+ level; 2 deviations of it outside the history's range are allowed. The deviation is of the second difference (a+ steady rise or fall has none), read where the surface was a frame ago, added to and kept by how still the pixel+ is (none from a pixel a frame on: a pixel that moved earns it again at rest), and a frame counts for 4 deviations+ at most (a light switched does not earn tolerance). UE's TSR keeps the input's flicker over time for the same+ decision.+- Tokyo at dusk, the real-time frame against the same moment held, ΔE / p99 over the skyline at 6, 7, 8 s: 3.82 /+ 37.6, 3.13 / 37.3, 1.51 / 26.2 → 2.05 / 11.0, 0.93 / 8.3, 0.42 / 5.0; the whole frame 2.70, 1.46, 0.84 → 1.54,+ 0.70, 0.55. (A session of this clip lands in one of two states a few tenths apart, the same build either way:+ nothing finer than that is read from it.)+- Elsewhere, main → now. Held still at 1440p against offline (ΔE; frame to frame): Bistro at 0.5 1.93; 0.54 →+ 1.85; 0.46, Kabukichō at 0.375 4.98 → 4.85. bench-ghosting, ΔE against each build's converged frames: Bistro+ settled 0.98 → 0.82, turn 2.33 → 2.22, strafe 2.85 → 2.66, a tenth of a second after the stop 2.63 → 2.48;+ Kabukichō 1.30 → 1.25, 3.63 → 3.53, 4.26 → 4.01, 3.81 → 3.50 (lower in every shot and region of both). The orbit+ of Thames against offline: detail 0.52 → 0.57 moving, ΔE 1.51 → 1.34 held. The fire shot's box 6.28 / 5.56 /+ 3.66 → 5.99 / 5.15 / 3.45; the Bistro slice half a second after its explosion 5.76 → 5.28. The lighting-edit shot+ as it was or a little under (the lamp's pool at 32 frames 3.05 → 3.02, lamp on 1.10 → 0.99). `compose` + `judge`+ 0.78 → 0.90 ms at 1440p output. test-render 188 pass (`upscale/dimming-behind-edge-live`: main 1.395 of 1 ± 0.1).+- What was tried and left out, each measured (`out/liveq/gpu-runs-std.md`, U1–Z2, F1–J14):+ - no allowance at all: Tokyo as good, a still Bistro three times the flicker (frame to frame 0.54 → 1.57);+ - half the range on each side by that side's own spread: the outlines stay (any measure taken from the history+ feeds itself);+ - verdicts averaged among samples of the same depth and weighted by how narrow their range was: a tenth off the+ outlines;+ - the history clamped into the frame's nine samples always (a TAA's rule): the outlines go, and the rest of the+ frame pays (p99 17.2 for 9.7);+ - the deviation of the first difference: a dimming sky counts as flicker (Tokyo's skyline 1.75 at 7 s, above+ either state of 1.06 / 1.44); in+ absolute light, with a switch counted in full: the lamp's pool twice as far off at 32 frames (7.37); read at+ the place on screen, in motion too: the ground after a strafe worse than main (Kabukichō 2.79 → 3.02);+ - 1 and 3 deviations: Bistro's frame to frame 0.49, 0.38 for 0.42 at 2; Tokyo's skyline p99 at 3 the highest.+- Left: the pixel at the silhouette itself (in the test, the first pixel beside the edge reads 2.3 times the wall,+ the second 1.2; in Tokyo a rim one or two pixels thin). That is not the allowance: the sample there lies within a+ range that runs from the roof to the sky whatever is allowed outside it, and the samples beside it lie between+ their own history and the stale pixel. Holding still, nothing holds a history pixel against the samples.+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 917a4be..7cb4897 100644--- a/renderer/shaders/live.wgsl+++ b/renderer/shaders/live.wgsl@@ -60,8 +60,8 @@ struct Pixel { color: vec4<f32>, albedo: vec4<f32>, normal: vec4<f32>, emit: vec@group(0) @binding(15) var<storage, read_write> lumq: array<f32>; // quarter res log2 luminance (unexposed)@group(0) @binding(16) var<storage, read_write> lumb: array<f32>; // edge-aware blur of lumq// Per traced sample, what `judge` finds of the output grid's colour history (`Judged`, f16), in `ae_out`. Until then-// `ae_out` holds what the previous frame's `dtemporal` wrote to `ae_in`, its ping-pong partner: the diffuse fast mean-// in colour (`fast_load`).+// `ae_out` holds what the previous frame wrote to `ae_in`, its ping-pong partner: `dtemporal` the diffuse fast mean+// in colour (`fast_load`: x, y), `compose` how much the composed sample flickers (`Flicker`: z, w).@group(0) @binding(17) var<storage, read_write> ae_in: array<vec4<u32>>;@group(0) @binding(18) var<storage, read_write> ae_out: array<vec4<u32>>;// Specular history on the traced grid (rgb + history length), diffuse luminance moments (mean, mean square, fast mean, -).@@ -892,7 +892,24 @@ fn compose(@builtin(global_invocation_id) gid: vec3<u32>) {let pv = prev_pixel(p + select(vec3<f32>(0.0), mv.xyz, object_moves));if (pv.z > 0.0) { vel = clamp(sp - 0.5 - pv.xy, vec2<f32>(-2048.0), vec2<f32>(2048.0)); }}- fb[q] = vec4<f32>(finite_or_zero(max(c, vec3<f32>(0.0))), t);+ let shown = finite_or_zero(max(c, vec3<f32>(0.0)));+ fb[q] = vec4<f32>(shown, t);+ // How much this sample flickers (`Flicker`), from where its surface was in the previous frame's traced grid.+ let now = min(lum(shown), 6.0e4);+ var f = Flicker(vec2<f32>(0.0), 0.0, 0.0);+ let ps = vec2<i32>(L.isz.zw);+ if (L.size.w == 0u && ps.x > 0) {+ let pc = vec2<i32>(floor((sp - vel) * vec2<f32>(ps) / vec2<f32>(f32(L.size.x), f32(L.size.y))));+ if (pc.x >= 0 && pc.y >= 0 && pc.x < ps.x && pc.y < ps.y) { f = flicker_at(u32(pc.y * ps.x + pc.x)); }+ }+ let still = 1.0 - clamp(length(vel) / UP_SPEED, 0.0, 1.0);+ var sd = select(1.0, f.sd, f.n >= 1.0);+ if (f.n >= 2.0) {+ let bend = min(abs(now - 2.0 * f.last.x + f.last.y) / max(max(now, max(f.last.x, f.last.y)), 1e-9), UP_ONSET * max(f.sd, 0.01));+ sd = sqrt(mix(f.sd * f.sd, bend * bend / 6.0, still / min(f.n - 1.0, 8.0)));+ }+ ae_in[q].z = pack2x16float(vec2<f32>(now, select(now, f.last.x, f.n >= 1.0)));+ ae_in[q].w = pack2x16float(vec2<f32>(sd * still, min(max(f.n + still, 1.0), 9.0)));let reactive = max(select(0.0, 1.0, px.albedo.w > 1.5), clamp(medium_share(q) / UP_MEDIUM, 0.0, 1.0));xhist_out[q] = vec4<f32>(vel, depth, reactive);}@@ -914,8 +931,13 @@ const UP_REJECT: f32 = 0.25;const UP_REACTIVE: f32 = 4.0;// The share of a pixel a medium that changes with time takes (`medium_share`) from which the pixel is as reactive.const UP_MEDIUM: f32 = 0.25;-// How far outside the range of the history's pixels around it a point sample may lie, in that range's widths (`judge`).-const UP_POINT: f32 = 0.5;+// How far outside the range of the history's pixels around it a point sample may lie (`judge`): this many deviations+// of the traced sample's own flicker (`Flicker`). Of 1, 2, 3 (measured while the deviation was still an amount of+// light): Bistro held still changes 0.49, 0.42, 0.38 from frame to frame, and Tokyo's skyline at dusk is furthest from+// its held frame at 3.+const UP_FLICKER: f32 = 2.0;+// The most a frame's change counts for in the flicker, in deviations of what it was (or of 1 % of the level).+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;@@ -936,6 +958,38 @@ const UP_STALE: f32 = 0.05;// with itself), confirmed by colour (the history there lies outside this frame's range), so the still edges that the// jitter does catch keep their history.+// A sample is a point and the history's pixels are means over a pixel: of a feature finer than a pixel (a row of+// windows, a grating) a sample lies outside their range in a still picture too, a little further on some jitters than+// on others, and correcting for that flickers. How far is not the history's to say. (It was: half the range of the+// history's nine pixels. A pixel standing off the truth then widened the range of the samples next to it, which were+// allowed to stand off by half of that, and so outward: under a sky that dimmed every frame a silhouette kept the sky+// of seconds ago in a glow ten pixels wide, with nothing but the blend to bound it.) It is the samples': how much the+// traced sample at this place changes from one frame to the next under the jitter, which is what a temporal+// upscaler's flicker history is for (UE's TSR keeps the input's luminance over time for the same decision).++// `Flicker`, per traced sample, in the words `dtemporal` leaves free in `ae_in` (f16; `compose` keeps it): the+// composed sample's luminance of the last frame and of the one before, the deviation of its frame-to-frame change as+// a share of its level, and of how many frames that is (0: none; the deviation is then 1: unknown, as much as the+// level), all read where the sample's surface was a frame ago (in motion the place on screen would read the motion+// as flicker).+// - The deviation is of the second difference (this frame's, less twice the last, plus the one before: of+// independent samples its mean square is six variances), which a steady rise or fall does not have: a sky dimming+// 4 % a frame is no flicker. A running mean over the first eight frames, an exponential one after.+// - A share of the level (the largest of the three frames), not an amount of light: what a lit floor's samples+// scattered by says nothing of the same floor with the lamp off.+// - Tolerance is earned slowly: a frame's second difference counts for UP_ONSET deviations at most, so a light+// switched (two large ones) raises it by a fifth and a pixel that really flickers reaches its level in a second.+// - Flicker is the jitter's with all else still: a pixel in motion changes by its motion (a wet street's reflections+// every frame), so the deviation is added to by how still the pixel is and kept by the same, none from UP_SPEED on+// (TSR fades its flicker rule out with velocity too): a pixel that moved has none and earns it again at rest,+// while its history, cut to UP_MOVING samples by the motion, grows back.+struct Flicker { last: vec2<f32>, sd: f32, n: f32 };+fn flicker_at(q: u32) -> Flicker {+ let v = ae_out[q];+ let b = unpack2x16float(v.w);+ return Flicker(unpack2x16float(v.z), b.x, b.y);+}+// `judge`: per traced sample, into `ae_out` (f16): that distance (linear RGB), the sample's luminance (< 0: no// history there), the motion its output pixels reproject by: the surface nearest the camera among the nine samples// around (the sky the farthest), since an edge moves with what is in front of it; and whether its history is of@@ -990,10 +1044,10 @@ fn judge(@builtin(global_invocation_id) gid: vec3<u32>) {hn += 1.0;}if (hn > 0.0) {- // The history's pixels are means over a pixel and the sample is a point: of a feature finer than a pixel- // it can lie outside their range by as much as they differ among themselves (UP_POINT of it allowed).- let slack = UP_POINT * (hi - lo);+ // (The sample is a point and the history's pixels are means: UP_FLICKER deviations of its own flicker+ // outside their range are the jitter's.)let c = fb[q].rgb;+ let slack = UP_FLICKER * unpack2x16float(ae_in[q].w).x * c;d = clamp(c - clamp(c, lo - slack, hi + slack), vec3<f32>(-6.0e4), vec3<f32>(6.0e4));l = min(lum(c), 6.0e4);// Gone from in front: the previous frame's nearest depth around where this point was (its traced grid'sdiff --git a/tests/render/upscale-dimming-behind-edge-live.ts b/tests/render/upscale-dimming-behind-edge-live.tsnew file mode 100644index 0000000..7db90fa--- /dev/null+++ b/tests/render/upscale-dimming-behind-edge-live.ts@@ -0,0 +1,36 @@+// A light that dims every frame behind a silhouette (live.wgsl `judge`, `Flicker`): an emitting wall fills the view,+// 4 % dimmer each frame, and a black slab covers its left half. The wall beside the slab's edge reads what the wall+// far from it reads. (The upscaler holds each traced sample against the range of its colour history around the+// sample's point, and once allowed half that range outside it: at the edge the range ran from the slab to the wall+// of frames ago, the dimmer wall lay inside, and the history there followed by its blend alone, a glow along every+// roof under a sky at dusk.)+import { BoxGeometry, Color, Mesh, MeshStandardMaterial, PlaneGeometry } from "@threert/scene";+import { defineGame } from "@threert/gameplay";+import { camera, result, sceneWithSky, type TestMeta } from "./lib.ts";++export const test: TestMeta = {+ id: "upscale/dimming-behind-edge-live", features: ["dynamic-emission", "upscaler"], reference: "analytic", temporal: true,+ metric: { kind: "ratio", a: [0.5063, 0.3, 0.5313, 0.7], b: [0.8, 0.3, 0.95, 0.7], expected: 1, tolerance: 0.1 },+ live: 90,+ note: "a wall 4 % dimmer every frame behind a black slab's edge: its four pixels beside the edge (the second to the fifth) as far from it",+};++let wall: MeshStandardMaterial;+export default defineGame<Record<string, never>>({+ state: {},+ setup: () => {+ const scene = sceneWithSky(0);+ wall = new MeshStandardMaterial({ name: "wall", color: new Color(0, 0, 0), emissive: new Color(1, 1, 1), emissiveIntensity: 40, roughness: 1 });+ const back = new Mesh(new PlaneGeometry(40, 40), wall);+ back.name = "back";+ back.position.z = -5;+ const slab = new Mesh(new BoxGeometry(6, 12, 0.2), new MeshStandardMaterial({ name: "slab", color: new Color(0, 0, 0), roughness: 1 }));+ slab.name = "slab";+ slab.position.set(-3, 0, -2);+ return result(scene, camera(scene, [0, 0, 3], [0, 0, -5]), [back, slab]);+ },+ frame() {+ wall.emissiveIntensity *= 0.96;+ },+ handlers: {},+});