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.

A mesh an edit wrote has no cutout map (#306)

YXca6926b84010
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index d2b068a..bd2313f 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -2578,7 +2578,11 @@ maps in place of the reads and the stepping kept, the frame cost what the test c
under it).
- Edits. A material or a texture changed in place drops the maps of the rows drawn with it: the cutout is then
opaque to these rays, as before the maps, until the scene is prepared again. An instance placed at run time takes
- its mesh's.
+ its mesh's. (Found after the merge, the same day: so did an object whose geometry an edit had rewritten where it
+ lies, and an emitter's shadow rays then went by the map of the triangles the mesh had had. A card's texture
+ coordinates mirrored at run time kept its old picture of light and shadow on the ground. A mesh whose triangles an
+ edit wrote has no map now, `shadow/cutout-emitter-geometry-edit-live`: opaque to these rays, as above. To make its
+ map again where it is edited needs the texture's pixels and room in the maps' stream then: not done.)
- Measured. The bushes and the hedge beside the walk, the kernel's samples against offline: 0.966 and 0.992, which
is what the alpha test reads there (0.966, 0.992). In the walking frame the upscaled picture there has 0.91 and
0.99 of the offline one's light for 0.73 and 0.70. The frame, three alternated runs: the street's first view
diff --git a/docs/RUNTIME.md b/docs/RUNTIME.md
index 3682b6e..956c716 100644
--- a/docs/RUNTIME.md
+++ b/docs/RUNTIME.md
@@ -1770,7 +1770,7 @@ view, the way to hold a live picture to the offline one).
| 1 `A_GLASS_SHADOWS` | shadow rays to the analytic lights and the sky pass glass in full, untinted | light under tinted glass 4.3 x (`shadow/glass-tint`) | a glass scene +34 % (khronos-transmission 5.20 -> 6.97 ms) |
| 2 `A_MEDIA_SHADOWS` | only homogeneous media dim shadow rays: smoke and fire cast no shadow | light behind optical depth 1: e x (`shadow/medium`) | the Bistro slice +0.84 ms (9 %), the fire scene +0.10 |
| 4 `A_CUTOUT_PATHS` | cutouts are opaque to rays past a camera hit's own, off mirror paths | a camera hit's own light is whole (`sky/cutout-clear-live`: its samples take the share those rays cannot bring, `light_mis`); what a cutout lights sends nothing on (`sky/cutout-bounce`: black) | Bistro +1.63 ms of 8.54 |
-| 8 `A_CUTOUT_EMITTERS` | at a camera hit, emitters' shadow rays ask a cutout's map (its triangles' cells, solid or hole, made once from its alpha: renderer/src/cutout.rs) in one query and read no texture; a cutout without maps is opaque to them | a camera hit's light past a cutout is whole (`shadow/cutout-emitter-live`, `shadow/cutout-emitter-side-live`); a cell is two texels wide, sixteen on Bistro's widest cards, and offline by the maps its foliage reads 0.9999 and 0.9994 of the light the alpha test gives | Bistro's frame +14 % (16.0 -> 18.2 ms at the street's first view, 17.9 -> 20.6 over its walk) |
+| 8 `A_CUTOUT_EMITTERS` | at a camera hit, emitters' shadow rays ask a cutout's map (its triangles' cells, solid or hole, made once from its alpha: renderer/src/cutout.rs) in one query and read no texture; a cutout without maps (a material whose function may change its opacity; one whose material or texture was edited since the maps were made; a mesh an edit wrote) is opaque to them | a camera hit's light past a cutout is whole (`shadow/cutout-emitter-live`, `shadow/cutout-emitter-side-live`); a cell is two texels wide, sixteen on Bistro's widest cards, and offline by the maps its foliage reads 0.9999 and 0.9994 of the light the alpha test gives | Bistro's frame +14 % (16.0 -> 18.2 ms at the street's first view, 17.9 -> 20.6 over its walk) |
| 16 `A_FAR_EMITTERS` | the light tree proposes no emitter beyond 120 m; without a tree, the emitter cull (60 m, 120 m in view) | panels 150 m up: 3 % of their light (`light/emitter-far`); Kabukichō's and Tokyo's shots unchanged | Tokyo from the air 4.7 -> 9.2 ms; the 3 x 3 district +0.15 |
Measured 2026-11-15 and 16 with the loop guard on. Bistro held still, ΔE against the offline render: 1.82 as
diff --git a/renderer/src/cutout.rs b/renderer/src/cutout.rs
index 2f3d71f..38110ac 100644
--- a/renderer/src/cutout.rs
+++ b/renderer/src/cutout.rs
@@ -52,7 +52,8 @@ pub fn row_run(row: &crate::scene::Row) -> Option<u32> {
/// The runs of the rows `mine` of an instance of `mesh` that an edit places: those of an instance the scene has of
/// that mesh, section by section where the material is the same (its maps are of the mesh's triangles and that
-/// material, whichever instance asks).
+/// material, whichever instance asks). For a mesh whose triangles are the build's: one an edit wrote has other
+/// triangles than the maps were made of, and its caller does not ask (live/edits.rs `EditState::remade`).
pub fn adopt_runs(mine: &mut [crate::scene::Row], mesh: u32, instances: &[crate::scene::Instance], rows: &[crate::scene::Row]) {
if !mine.iter().any(|r| r[0] & ROW_CUTOUT != 0) {
return;
diff --git a/renderer/src/live/edits.rs b/renderer/src/live/edits.rs
index 568b3a1..e25835a 100644
--- a/renderer/src/live/edits.rs
+++ b/renderer/src/live/edits.rs
@@ -103,6 +103,9 @@ pub(super) struct EditState {
pub(super) users: std::collections::HashMap<u32, u32>,
pub(super) managed: std::collections::HashSet<u32>,
pub(super) dead_meshes: Vec<u32>,
+ /// The meshes whose triangles an edit wrote (a new mesh, a freed one's slot, one rewritten where it lies): the
+ /// scene's cutout maps (cutout.rs) are not of them, whatever an instance of the slot had (`cutout::adopt_runs`).
+ pub(super) remade: std::collections::HashSet<u32>,
/// Times the room grew (frame log `grows`), and whether the scene bind group must be made again.
pub(super) grows: u32,
pub(super) rebind: bool,
@@ -379,6 +382,7 @@ pub(super) fn make_mesh(cx: &mut Meshing, data: scene::MeshData, colored: bool,
(k, first, im)
}
};
+ cx.edit.remade.insert(k);
let t2 = Instant::now();
cx.w_vert.put((im.vfirst as usize * crate::indexed::VERTEX_BYTES) as u64, bytemuck::cast_slice(&scope.vertices));
cx.w_index.put((first * 12) as u64, bytemuck::cast_slice(&scope.indices));
@@ -3090,8 +3094,11 @@ impl LiveCore {
}
// (Its rows, the mesh's own, are placed with its record below.)
let mut mine = tables.retained.mesh_rows.get(&mesh).ok_or("a model's mesh without its rows")?.clone();
- // (A cutout section's maps: those the scene's instances of the mesh have, cutout.rs.)
- crate::cutout::adopt_runs(&mut mine, mesh, instances, rows);
+ // (A cutout section's maps: those the scene's instances of the mesh have, cutout.rs; of a mesh
+ // the build made, not one an edit did.)
+ if !edit.remade.contains(&mesh) {
+ crate::cutout::adopt_runs(&mut mine, mesh, instances, rows);
+ }
if glass_caster(&mine) {
more.set(more.get() | gpu::F_IGLASS);
}
@@ -3265,8 +3272,12 @@ impl LiveCore {
// (Its rows, which say its materials, are placed with its record below; its bits and whether it casts
// are theirs.)
let mut mine = scene::section_rows(im.sections(sections), &mats, &tables.materials);
- // (A cutout section's maps: those the scene's instances of the mesh have, cutout.rs.)
- crate::cutout::adopt_runs(&mut mine, mesh, instances, rows);
+ // (A cutout section's maps: those the scene's instances of the mesh have, cutout.rs; of a mesh the
+ // build made and no edit has written since: a geometry changed where it lies has other triangles
+ // under the same rows, and its cutout is one without maps until the scene is prepared again.)
+ if !edit.remade.contains(&mesh) {
+ crate::cutout::adopt_runs(&mut mine, mesh, instances, rows);
+ }
// (Shadow rays pass the glass among a caster's other sections under a kernel feature.)
if scene::rows_bits(&mine) & scene::INST_GLASS != 0 && scene::rows_cast(&mine, o.cast_shadow) && features & gpu::F_IGLASS == 0 {
more.set(more.get() | gpu::F_IGLASS);
diff --git a/renderer/src/live/load.rs b/renderer/src/live/load.rs
index 3cdec75..8e7f88c 100644
--- a/renderer/src/live/load.rs
+++ b/renderer/src/live/load.rs
@@ -222,6 +222,7 @@ pub(super) fn load_scene(g: &gpu::Gpu, world: &World, assets: &Path, presets: &P
users,
managed,
dead_meshes: vec![],
+ remade: Default::default(),
grows: 0,
rebind: false,
base: room_base,
diff --git a/tests/render/shadow-cutout-emitter-geometry-edit-live.ts b/tests/render/shadow-cutout-emitter-geometry-edit-live.ts
new file mode 100644
index 0000000..baace38
--- /dev/null
+++ b/tests/render/shadow-cutout-emitter-geometry-edit-live.ts
@@ -0,0 +1,57 @@
+// shadow/cutout-emitter-side's card with its texture coordinates mirrored at run time, where it lies (a
+// `dynamicGeometry` mesh, its sections and triangles as many as they were): the card is then cut out from x = -0.75 on
+// and solid before it. Its map (renderer/src/cutout.rs) was made of the coordinates it had, which let the panel's
+// light through to the plane's point 1.1 m to the left (the ray meets the card at x = 0.475) and stopped it for the
+// middle. A geometry an edit writes has no map: to an emitter's shadow ray the card is whole again, as a cutout was
+// before the maps (`APPROX.cutoutEmitters`), until the scene is prepared again, and the point to the left has none of
+// the panel's light. It is read against the point 1.1 m to the right, which a lamp under the card lights (0.5 m above
+// it; the card hides the panel from that point in every case but the true one): the lamp's own light at the left
+// point is 0.0024 of that, and the picture reads 0.003. With the old map still asked it read 0.25, under both
+// traversals; with the alpha tested (`THREERT_APPROX=0`), which is what a map made again would give, 0.085.
+import { Color, DataTexture, Mesh, MeshStandardMaterial, PlaneGeometry } from "@threert/scene";
+import { defineGame } from "@threert/gameplay";
+import { camera, lambert, plane, result, sceneWithSky, type TestMeta } from "./lib.ts";
+
+export const test: TestMeta = {
+ id: "shadow/cutout-emitter-geometry-edit-live", features: ["emissive", "alpha-test", "shadows", "edits"], reference: "analytic", temporal: true,
+ metric: { kind: "ratio", a: [0.1, 0.48, 0.14, 0.52], b: [0.86, 0.48, 0.9, 0.52], expected: 0, tolerance: 0.02 },
+ live: 120,
+ note: "the card's u mirrored after three frames, in place: no map of the old coordinates answers for it",
+};
+
+let elapsed = 0;
+let edited = false;
+export default defineGame<Record<string, never>>({
+ state: {},
+ setup: () => {
+ elapsed = 0;
+ edited = false;
+ const scene = sceneWithSky(0);
+ const panel = new Mesh(new PlaneGeometry(0.2, 0.2), new MeshStandardMaterial({ name: "panel", color: new Color(0, 0, 0), emissive: new Color(1, 1, 1), emissiveIntensity: 20000, roughness: 1 }));
+ panel.name = "panel";
+ panel.rotation.x = Math.PI / 2;
+ panel.position.set(2.05, 2, 0);
+ const texels = new Uint8Array(96 * 4);
+ for (let k = 0; k < 96; k++) texels.set([255, 255, 255, k >= 54 ? 255 : 0], k * 4);
+ const card = new Mesh(new PlaneGeometry(12, 12), new MeshStandardMaterial({ name: "card", color: 0x000000, map: new DataTexture(96, 1, texels), alphaTest: 0.5, roughness: 1, side: "double" }));
+ card.name = "card";
+ card.dynamicGeometry = true;
+ card.rotation.x = -Math.PI / 2;
+ card.position.set(0, 1, 0);
+ const lamp = new Mesh(new PlaneGeometry(0.2, 0.2), new MeshStandardMaterial({ name: "lamp", color: new Color(0, 0, 0), emissive: new Color(1, 1, 1), emissiveIntensity: 500, roughness: 1 }));
+ lamp.name = "lamp";
+ lamp.rotation.x = Math.PI / 2;
+ lamp.position.set(1.1, 0.5, 0);
+ return result(scene, camera(scene, [0, 0.6, 3], [0, 0, 0]), [panel, lamp, card, plane(20, lambert(0.5))]);
+ },
+ frame(f) {
+ elapsed += f.dt;
+ if (edited || elapsed <= 3 / 60) return;
+ edited = true;
+ const card = f.scene.getObjectByName("card") as Mesh;
+ const uv = card.geometry.attributes.uv;
+ for (let i = 0; i < uv.count; i++) uv.setX(i, 1 - uv.getX(i));
+ uv.needsUpdate = true;
+ },
+ handlers: {},
+});