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.

bench-temporal --shot edit: a lighting edit counted in frames (ROADMAP § 1a) (#52)

Yujia79e71bc4ec9f
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 4e094d7..f455394 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -1937,6 +1937,33 @@ the atlas) and field B are copied texture to texture, and the programs' step cou
0.6024 (as without the rebuild); main 0.90. test-render 187 pass. Not carried: GPU particles (a rebuild still starts
them afresh), and a grid whose size or program changed.
+**A lighting edit counted in frames (2026-11-13, after it).** The closing signs of `bench-temporal` run in real time
+and spread more than what they were asked to tell apart. `bench-temporal --shot edit` is the measure in frames
+(`tools/light-edit-scene.ts`: a closed room; a spot whose pool is on the back wall and whose bounce is on the floor;
+an emissive sign; each switched off and on at once; lockstep at 0.5, the frame k frames after the edit against the
+converged frame of the state after, beside the frame k frames after a history reset in that state). Two runs agree to
+0.01. Main (`cd54c70`), luminance against the reference at 1 / 8 / 32 / 128 / 256 frames after the edit:
+
+| edit, region | the edit | ΔE at 32 / 256 | a view with no memory, ΔE at 32 / 256 |
+|---|---|---|---|
+| lamp off, its pool | 29.8 / 11.2 / 3.33 / 1.36 / 1.17 | 15.2 / 1.75 | 0.53 / 0.36 |
+| lamp off, its bounce | 2.64 / 2.49 / 1.66 / 1.12 / 1.05 | 3.38 / 0.43 | 0.46 / 0.26 |
+| lamp on, its pool | 0.05 / 0.84 / 0.95 / 0.99 / 0.99 | 1.92 / 0.43 | 0.43 / 0.25 |
+| lamp on, its bounce | 0.37 / 0.43 / 0.72 / 0.93 / 0.97 | 3.00 / 0.53 | 1.15 / 0.52 |
+| sign off, the floor beside it | 2.94 / 2.53 / 1.66 / 1.12 / 1.05 | 12.7 / 1.56 | 0.73 / 0.46 |
+| sign on, the floor beside it | 0.35 / 0.48 / 0.76 / 0.95 / 0.97 | 7.28 / 0.84 | 0.80 / 0.43 |
+
+- **Open, the live view's largest fault found so far:** a lamp switched off leaves its pool on the wall for seconds,
+ 11 times too bright after 8 frames, 3.3 times after half a second, still 17 % after 4 s, in blotches. The excess
+ falls as 1 / k. The diffuse history is cut once, to 2 frames, when its fast mean leaves the slow one; half the old
+ light is still in it, the slow mean is set to the fast one, the anti-lag has nothing more to find, and the history
+ accumulates again from there (and after 45 frames the long history is back). The upscaler's 16 samples follow that.
+ ReBLUR's form is another: the slow history clamped every frame into the range of a fast one (about 6 frames) around
+ the pixel, so it is dragged along until it has followed. Not done here.
+- The question #39 left: the radiance cache's 4 frames while the lighting is live. At 32 frames the bounce follows
+ later (lamp off: 2.24 for 1.66 at 32 frames, 1.38 for 1.12 at 128; lamp on: 0.50 for 0.72, 0.79 for 0.93). The 4
+ frames buy what they were said to and stay; the 0.16 ΔE they cost a scene at rest is the price.
+
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.
diff --git a/tools/bench-temporal.ts b/tools/bench-temporal.ts
index abf235b..413055d 100644
--- a/tools/bench-temporal.ts
+++ b/tools/bench-temporal.ts
@@ -13,7 +13,7 @@
// node tools/bench-temporal.ts [--bundle out/bundles/kabukicho.js] [--out out/bench-temporal/<tag>] [--refs DIR]
// [--refs-ue out/bench-temporal/refs-ue | none] [--bin renderer/target/release/threert-render]
// [--tag name] [--scale auto|0.6|1] [--list-refs] [--motion-blur] [--region signs|ground|facades|u0,v0,u1,v1]
-// [--shot kabukicho|volumes|water|foliage]
+// [--shot kabukicho|volumes|water|foliage|edit]
// --shot volumes: tools/volume-scene.ts (bundle out/bundles/volume-scene.js) at frozen scene time, the camera strafing 3 m
// across the fog, smoke and fireball in 1 s; no lighting change. Regions fog | smoke | fire.
// --shot water | foliage: motion in the scene, the camera still. water: tools/water-scene.ts (out/bundles/water-scene.js),
@@ -21,6 +21,14 @@
// tools/foliage-scene.ts (out/bundles/foliage-scene.js), the plants swaying (windSway); regions plants | ferns. At scene
// times T = 6, 7 and 8 s, lockstep at 100 % scale: the reference holds T for 1024 frames (frame time 0), `still` holds
// it for 240 (the convergence floor), `moving` runs 240 frames at 60 fps up to T. The motion's cost is moving - still.
+// --shot edit: a lighting edit counted in frames (tools/light-edit-scene.ts, out/bundles/light-edit-scene.js; lockstep at
+// 60 fps, the camera still, --scale 0.5 unless given). A spot (`lamp`: its pool on the back wall, its bounce on the
+// floor) and an emissive panel (`sign`) are switched off and on at once. For each edit: the frame k frames after it
+// (k = 1 .. 256, after 300 frames in the state before) against the converged frame of the state after (1024 frames at
+// 100 %), per region: dE and the luminance ratio; beside it `fresh`, the frame k frames after a history reset in the
+// state after (a view with no memory of the state before). Where the edit's dE is above `fresh` the history holds the
+// old lighting; `settled` is the first k from which the luminance is within 2 % of the reference's for good (0: not
+// within the 256 frames). Lockstep: two runs of a build agree to 0.01.
// --motion-blur: motion blur in both (UE: MB=1 bun ue5/temporal.ts -> refs-ue-mb, amount 0.5 / max 5 % / target 30 fps). Movie
// Render Queue overrides the amount with its shutter fraction (the same 0.5) and the target FPS with the output rate (60;
// MoviePipelineImagePassBase.cpp), half the blur of the real-time viewport, so ours runs with what MRQ rendered
@@ -31,6 +39,7 @@ import { createInterface } from "node:readline";
import { createHash } from "node:crypto";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";
+import { bundleGame } from "./bundle-game.ts";
import { rendererVersion } from "./lib/bench.ts";
const root = resolve(import.meta.dirname, "..");
@@ -44,15 +53,20 @@ const TIME_SHOTS: Record<string, { bundle: string; regions: string[] }> = {
foliage: { bundle: "foliage-scene.js", regions: ["plants", "ferns"] },
};
const timeShot = TIME_SHOTS[flag("--shot", "kabukicho")];
+const editShot = flag("--shot", "kabukicho") === "edit";
+// (Its scene is one file: bundled here, unless a bundle is given.)
+if (editShot && !args.includes("--bundle")) await bundleGame(join(root, "tools/light-edit-scene.ts"), join(root, "out/bundles/light-edit-scene.js"));
// The volume scene's media animate with scene time: frozen, references and test frames show the same smoke.
if (volumes) process.env.THREERT_FREEZE_TIME = "1";
-const bundle = resolve(flag("--bundle", join(root, "out/bundles", volumes ? "volume-scene.js" : timeShot ? timeShot.bundle : "kabukicho.js")));
+const bundle = resolve(flag("--bundle", join(root, "out/bundles", volumes ? "volume-scene.js" : timeShot ? timeShot.bundle : editShot ? "light-edit-scene.js" : "kabukicho.js")));
const tag = flag("--tag", "run");
// --region: every comparison (ours and UE's) over one part of the frame, by name (bench-ghosting's regions of view v1)
// or as u0,v0,u1,v1.
const REGIONS: Record<string, string> = {
ground: "0,0.62,1,1", signs: "0.2,0,0.8,0.45", facades: "0,0.1,0.25,0.62", fog: "0.08,0.42,0.38,0.72", smoke: "0.4,0.15,0.6,0.65", fire: "0.7,0.42,0.86,0.62",
water: "0.3,0.55,1,1", reflections: "0.5,0.6,0.8,0.85", plants: "0,0.35,0.75,0.8", ferns: "0.12,0.55,0.75,0.8",
+ // The lighting-edit scene: the spot's pool on the back wall, the floor its bounce lights, the floor beside the sign.
+ pool: "0.6,0.28,0.8,0.58", bounce: "0.75,0.68,0.98,0.88", signfloor: "0.03,0.75,0.3,0.95", room: "0,0,1,1",
};
const region = args.includes("--region") ? (REGIONS[flag("--region", "")] ?? flag("--region", "")) : null;
const scale = flag("--scale", "auto"); // test-run render scale (references are always 100%)
@@ -174,6 +188,94 @@ if (timeShot) {
process.exit(0);
}
+// ------------------------------------------------------------------------------------------------ a lighting edit
+if (editShot) {
+ mkdirSync(out, { recursive: true });
+ mkdirSync(refs, { recursive: true });
+ const KS = [1, 2, 4, 8, 16, 32, 64, 128, 256];
+ // The scene's states by what is off, and the events that reach them from all on.
+ const STATES: Record<string, string[]> = { on: [], "lamp-off": ["lamp"], "sign-off": ["sign"] };
+ const EDITS: { name: string; from: string; event: string; to: string; regions: string[] }[] = [
+ { name: "lamp off", from: "on", event: "lamp", to: "lamp-off", regions: ["pool", "bounce", "room"] },
+ { name: "lamp on", from: "lamp-off", event: "lamp", to: "on", regions: ["pool", "bounce", "room"] },
+ { name: "sign off", from: "on", event: "sign", to: "sign-off", regions: ["signfloor", "room"] },
+ { name: "sign on", from: "sign-off", event: "sign", to: "on", regions: ["signfloor", "room"] },
+ ];
+ const session = async (s: string, state: string) => {
+ const live = new Live(s);
+ await live.wait((l) => l.includes("fps on"));
+ live.send({ cmd: "lockstep", dt: 1 / 60 });
+ for (const e of STATES[state]) live.send({ cmd: "event", type: e });
+ const frames = async (n: number, path?: string) => {
+ const id = `s${Math.random().toString(36).slice(2)}`;
+ const done = live.wait((l) => (path ? l.includes(`snapshot ${path}`) : l === `live: sync ${id}`));
+ live.send({ cmd: "frames", n, ...(path ? { snapshot: path } : { sync: id }) });
+ await done;
+ };
+ // (The events land with the first frames; then the history starts over in that state.)
+ await frames(4);
+ live.send({ cmd: "reset" });
+ return { live, frames };
+ };
+ const quit = async (live: Live) => {
+ live.quit();
+ await sleep(300);
+ };
+ // References: each state converged at 100 %.
+ for (const state of Object.keys(STATES)) {
+ const ref = join(refs, `edit-${state}.png`);
+ if (existsSync(ref)) continue;
+ const { live, frames } = await session("1", state);
+ await frames(1024, ref);
+ await quit(live);
+ }
+ const testScale = args.includes("--scale") ? scale : "0.5";
+ // Fresh: k frames after a reset in each state.
+ for (const state of Object.keys(STATES)) {
+ const { live, frames } = await session(testScale, state);
+ let at = 0;
+ for (const k of KS) {
+ await frames(k - at, join(out, `fresh-${state}-${k}.png`));
+ at = k;
+ }
+ await quit(live);
+ }
+ const compare = (ref: string, img: string, r: string) => JSON.parse(execFileSync(bin, ["compare", ref, img, "--region", REGIONS[r]]).toString().trim().split("\n").pop()!);
+ const rows: Record<string, string | number>[] = [];
+ const summary: Record<string, string | number>[] = [];
+ for (const e of EDITS) {
+ const tag = e.name.replace(" ", "-");
+ const { live, frames } = await session(testScale, e.from);
+ await frames(300);
+ live.send({ cmd: "event", type: e.event });
+ let at = 0;
+ for (const k of KS) {
+ await frames(k - at, join(out, `${tag}-${k}.png`));
+ at = k;
+ }
+ await quit(live);
+ const ref = join(refs, `edit-${e.to}.png`);
+ for (const r of e.regions) {
+ const ms = KS.map((k) => ({ k, edit: compare(ref, join(out, `${tag}-${k}.png`), r), fresh: compare(ref, join(out, `fresh-${e.to}-${k}.png`), r) }));
+ for (const m of ms) rows.push({ edit: e.name, region: r, k: m.k, dE: m.edit.mean_delta_e, fresh_dE: m.fresh.mean_delta_e, luminance: m.edit.luminance_ratio, fresh_luminance: m.fresh.luminance_ratio, ssim: m.edit.ssim });
+ // The first k from which the luminance stays within 2 % of the reference's (0: never within the frames taken).
+ const off = (m: (typeof ms)[number]) => Math.abs(m.edit.luminance_ratio - 1) > 0.02;
+ const last = ms.findLastIndex(off);
+ const at = (k: number) => ms.find((m) => m.k === k)!;
+ summary.push({
+ edit: e.name, region: r, settled: last === ms.length - 1 ? 0 : ms[last + 1].k,
+ "lum@8": at(8).edit.luminance_ratio, "lum@32": at(32).edit.luminance_ratio, "lum@128": at(128).edit.luminance_ratio, "lum@256": at(256).edit.luminance_ratio,
+ "dE@32": at(32).edit.mean_delta_e, "fresh@32": at(32).fresh.mean_delta_e, "dE@256": at(256).edit.mean_delta_e, "fresh@256": at(256).fresh.mean_delta_e,
+ });
+ }
+ }
+ console.table(summary);
+ writeFileSync(join(out, "metrics.json"), JSON.stringify({ rows, summary }, null, 1));
+ execFileSync(bin, ["montage", join(out, "edit.jpg"), "--width", "640", ...["lamp-off-8", "lamp-off-32", "lamp-off-256"].map((n) => join(out, `${n}.png`)), join(refs, "edit-lamp-off.png")]);
+ console.log(`${out}/edit.jpg, metrics.json (every k)`);
+ process.exit(0);
+}
+
// ------------------------------------------------------------------------------------------------ references
const refFiles = [...refPoses.map((k) => join(refs, `pose${k}.png`)), ...(volumes ? [] : [join(refs, "closing.png")])];
if (!refFiles.every(existsSync)) {
diff --git a/tools/light-edit-scene.ts b/tools/light-edit-scene.ts
new file mode 100644
index 0000000..7013947
--- /dev/null
+++ b/tools/light-edit-scene.ts
@@ -0,0 +1,75 @@
+// The lighting-edit scene of bench-temporal's `--shot edit`: a closed room, 10 x 4 x 8 m of grey plaster, the camera
+// inside it. Three sources:
+// - a ceiling lamp on the left (a point light, always on): the room's base light;
+// - `lamp`: a spot on the right aimed at the back wall, where it makes a pool; the floor before the wall is outside
+// its cone and takes its light only bounced off the wall (the radiance cache's);
+// - `sign`: an emissive panel on the left wall (light-sampled as an emitter), lighting the floor beside it.
+// Events `lamp` and `sign` switch one off or on at once (the object's power: a parameter change, in place), so the
+// bench can count the frames the live view takes to follow: direct light of a local light, its bounce, an emitter's.
+// To look at it: `threert-render play out/bundles/light-edit-scene.js`, keys L (the lamp) and K (the sign).
+// node tools/bench-temporal.ts --shot edit (it bundles this file to out/bundles/light-edit-scene.js)
+import { BoxGeometry, Color, Mesh, MeshStandardMaterial, PerspectiveCamera, PointLight, Scene, SkyColor, SpotLight } from "@threert/scene";
+import { defineGame } from "@threert/gameplay";
+
+const box = (m: MeshStandardMaterial, size: [number, number, number], at: [number, number, number], name?: string) => {
+ const b = new Mesh(new BoxGeometry(...size), m);
+ b.position.set(...at);
+ if (name) b.name = name;
+ return b;
+};
+
+export default defineGame({
+ state: { lamp: true, sign: true },
+ setup: () => {
+ const scene = new Scene();
+ scene.environment = new SkyColor(0x000000, 0);
+ const camera = new PerspectiveCamera(60, 16 / 9, 0.05, 100);
+ camera.position.set(0, 1.6, 3.4);
+ camera.lookAt(0, 1.3, -4);
+ camera.setManualExposure(5);
+ scene.add(camera);
+
+ const plaster = new MeshStandardMaterial({ name: "plaster", color: 0xb0aca4, roughness: 0.9 });
+ const floor = new MeshStandardMaterial({ name: "floor", color: 0x8c8880, roughness: 0.7 });
+ const wood = new MeshStandardMaterial({ name: "wood", color: 0x6b4a30, roughness: 0.6 });
+ scene.add(box(floor, [10, 0.2, 8], [0, -0.1, 0]));
+ scene.add(box(plaster, [10, 0.2, 8], [0, 4.1, 0]));
+ scene.add(box(plaster, [10, 4, 0.2], [0, 2, -4.1]));
+ scene.add(box(plaster, [10, 4, 0.2], [0, 2, 4.1]));
+ for (const s of [-1, 1]) scene.add(box(plaster, [0.2, 4, 8], [s * 5.1, 2, 0]));
+ // Things to cast and take shadows: a table and a cabinet.
+ scene.add(box(wood, [1.6, 0.08, 0.9], [1.2, 0.75, -1.2]));
+ for (const [x, z] of [[0.5, -1.55], [1.9, -1.55], [0.5, -0.85], [1.9, -0.85]]) scene.add(box(wood, [0.07, 0.75, 0.07], [x, 0.375, z]));
+ scene.add(box(wood, [0.9, 1.8, 0.5], [-2.2, 0.9, -3.7]));
+
+ const base = new PointLight(0xffe2c0, 250, 0);
+ base.position.set(-3, 3.6, 0.5);
+ base.radius = 0.08;
+ scene.add(base);
+
+ const lamp = new SpotLight(0xfff4e0, 3000, 0, Math.PI / 7, 0.3);
+ lamp.name = "lamp";
+ lamp.position.set(3, 3.7, 0.5);
+ lamp.target!.position.set(3, 1.6, -4);
+ lamp.radius = 0.05;
+ scene.add(lamp, lamp.target!);
+
+ const neon = new MeshStandardMaterial({ name: "neon", color: 0x000000, emissive: new Color().setRGB(1, 0.2, 0.55), emissiveIntensity: 400 });
+ scene.add(box(neon, [0.05, 1.2, 2], [-4.95, 1.6, -1], "sign"));
+ return { scene, camera, options: { name: "light-edit", width: 1280, height: 720, preset: "cinematic" as const } };
+ },
+ frame(f) {
+ f.object("lamp")!.power = f.state.lamp ? 1 : 0;
+ f.object("sign")!.power = f.state.sign ? 1 : 0;
+ },
+ // In a window (`threert-render play out/bundles/light-edit-scene.js`): L switches the lamp, K the sign.
+ keys: { L: "lamp", K: "sign" },
+ handlers: {
+ lamp(tx) {
+ tx.state.lamp = !tx.state.lamp;
+ },
+ sign(tx) {
+ tx.state.sign = !tx.state.sign;
+ },
+ },
+});