Skip to content

Scene step D, third part: emitters on instances, a mesh of its own - #152

Merged
yujiaxu-ops merged 21 commits into
mainfrom
emitters-own-meshes
Nov 17, 2026
Merged

yujiaxu-ops merged 21 commits into
mainfrom
emitters-own-meshes

Conversation

@yujiaxu-ops

@yujiaxu-ops yujiaxu-ops commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Scene step D, third part: emitters on instances, for a mesh of its own. Follows #147, #150, #151.

What

A mesh with its own BLAS whose material only emits was a case apart: its triangles written in world space at an identity placement, never shared, rebuilt to move. It is a mesh as any other now.

  • Build: in model space, shared by the objects of its geometry and material, placed by its instance's matrix; a body that drives it moves the instance. MeshKind::Emitter, InstMesh::emits and emitter_mesh_tris are gone.
  • The light list: a run an instance. Instance::first_emitter (carried in its record) and InstMesh::emitters (how many; the mesh's triangles are numbered in their attributes). Each emitter keeps its triangle in world space and names the instance that places it (GpuEmitterTri::inst, where the object was).
  • Kernel: a light sample still reads no matrix; it takes its attributes through the instance as a hit does (the object, the texture LOD's offset). A ray that hits an emitting triangle finds its emitter at the instance's first plus the triangle's number.
  • Moves: an instance that moves has its run filled by the fill pass through its matrix; the light tree's moving subtree is refit from the placed triangles.
  • Edits in place: a mesh added, given other triangles or removed works as before (the instance's run reused, or left at no weight).
  • Software traversal: a unit's two flags share a word; the word freed is every instance's first emitter.

A model's and an instanced object's emitters are still flattened (next parts: each has its own build arm and edit path).

Checked

  • cargo test 168 passed, test-render 240 pass. Under software traversal the same 25 tests fail before and after.
  • New render test geometry/emitter-instance: the weight of a ray that hits an instance's emitter, against its analytic value. No test saw that entry before: a kernel mutant that dropped the instance's first passed all 239.
  • The readback test covers instance emitters (as loaded, a driven one moved, the edits), each edit also against a fresh build's picture. Eight mutants, each caught (one survived first: a removed instance's emitters kept their weight unseen; the test now asserts it).
  • Pictures against the build before: the tests with such a mesh render other samples (13 outputs differ, sums within 1e-4, every verdict as before); the rest byte-identical or within their own spread.
  • The voxel night level (192 lamps, now instances of shared meshes): mean luminance the same to 0.15 % over a 4 x 4 grid; 0.4 MB less BLAS. The voxel level's destruction bench as before (no fallback, edit 0.7 ms).
  • Timing (Metal, 1280x720 at scale 0.75, trace p50, alternating runs on a quiet machine), main -> this: Bistro 7.174 -> 7.102 ms (-1.0 %), the crowd 7.331 -> 7.286 (-0.6 %; its commit 4.19 -> 4.09 ms), the voxel night level 4.163 -> 4.156 (-0.2 %). No cost.
  • Vulkan (RTX 5090), main against this: the same tests differ as on Metal (those with such a mesh, other samples); cargo test 168 passed; test-render fails the same tests as main there, natively (5) and under software traversal (25, value for value). The head against the commit first swept: 220 of 236 byte-identical, 16 within their own spread, 0 changed.
  • A light sample takes its instance's object and texture LOD offset alone (inst_x): it placed the whole attribute record (normals, tangent) at every candidate at first.

Found on the way

The edit path still placed an emitting mesh at identity above the triangles (a leftover of the world-space mesh); two render tests read 0.629 for 0.5. Fixed; the readback test did not see it (it held the list to the instance, not the instance to the node), hence the picture check.

🤖 Generated with Claude Code


Note

High Risk
Changes path-tracing light sampling, MIS, GPU light-list updates, and live edit paths for emissive geometry—core rendering and correctness-sensitive behavior.

Overview
Emissive own-BLAS meshes are no longer a separate world-space “emitter mesh” path (MeshKind::Emitter, emitter_mesh_tris, InstMesh::emits). They are built and shared like any instanced mesh in model space, with one run of light-list emitters per instance (Instance::first_emitter, InstMesh::emitters, numbered mesh triangles).

The emitter_fill pass and live fill_emitter_runs now transform those triangles through the instance matrix when instances move. GpuEmitterTri carries an inst index instead of embedding object id for placement; pathtrace uses emitter_attrs / inst_x and resolves MIS via instance first + triangle number.

Live geometry edits create or zero instance emitter runs the same way as before, without identity placement for emitting meshes. Software traversal packs unit flags into n1.w so n2.w can store first emitter on every instance record. Light-tree building takes world-space vertices via a callback so instance emitters tree correctly.

Adds render test geometry/emitter-instance and extends in-place readback/picture checks for driven and instance emitters.

Reviewed by Cursor Bugbot for commit 6658ec2. Bugbot is set up for automated code reviews on this repo. Configure here.

yujiaxu-ops and others added 21 commits November 17, 2026 04:55
Light sampling read an emitter's triangle from the triangles' table as world
space, so whatever emits had to be stored there in world space (flattened, or
a mesh of its own written in world space). The list now has its own copy, the
way real-time engines keep a light list: `Table::EmitterTris`, one
`GpuEmitterTri` an emitter (v0, e1, e2 in world space; its triangle, object
and light-tree path code). The kernel's emitter sampling, light LOD, cull and
`emit_mis` read it. A CDF entry names its emitter; a triangle's attributes
name its emitter entry (x.w, where the path code was).

The copies follow what moves (`move_emitters`: the emitters the CPU moves) and
what edits make (`write_emitters`). A particle's is still read where its pass
places it. Nothing is placed otherwise yet.

Cost: 48 B an emitter; the trace +0.07 to 0.10 ms where emitters are sampled
(Bistro 7.18 -> 7.29 ms, Tokyo 4.41 -> 4.42, none without emitters), not
attributed; 0.2 ms of CPU a frame for the crowd's 21,280 moving emitters, which
a GPU pass is to take over. Pictures: big scenes within main's own run-to-run
difference; 26 of the suite's 239 outputs differ in their last bits.

Test: `the_light_list_holds_its_triangles` reads the list and the triangles
back from the GPU after a load, a move and in-place edits.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
What moves an emitter after the list was written is copied into it by a pass
(`emitter_fill.wgsl`, what real-time engines call preparing the lights): a run
of the list an invocation row, each emitter's rows taken again from its
triangle.

- The emitters of the triangles the CPU reposes: filled after a commit that
  moved them, in place of the CPU's rewrite (0.2 ms a frame on the crowd).
- The particles': filled after their passes, so the kernel reads every emitter
  from the list; its particle case (`emitter_tri_of`) is gone.

`EmitterRuns` at prepare, `gpu::EmitterFills` a scene (with hardware ray
tracing), the pipeline made once.

Test: the readback test covers particles (collapsed as loaded, placed after a
frame) and the movers through the pass.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tters

prepare no longer reorders the list by the light tree's leaf order; the CDF's
order is the tree's then the rest (`emitter_order`), and an entry names its
emitter by index, as the slot for emitters added in place already did. So an
instance's emitters can be a run of the list (next).

No picture changes (render-identity: 219 byte-identical, 20 within their own
spread).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ributes through it; a unit's flags in one word

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…list's order

The test's movers lay along x in the list's order, so their leaf order was the
list's and an entry was its emitter: a lookup by the wrong index read the same
vertices and passed (found by review). They are placed out of order now, the
test asserts the orders differ, and reads each entry's vertices by its
emitter. A lookup by the tree entry fails it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ce of a shared mesh

A run of the light list an instance (its first in its record, n2.w; its mesh's
triangles numbered in their attributes); the rows through the instance's
matrix (prepare, the edits, the fill pass when it moves); the world-space
emitter mesh (MeshKind::Emitter, InstMesh::emits, emitter_mesh_tris) is gone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s picture; two stale mentions

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ance's emitter tested; a removed instance's emitters; docs

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t is (first_emitter)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`emitter_attrs` placed the whole attribute record by the instance (three
normals and the tangent normalised) at every candidate; a light sample reads
none of them. It patches `x` from the record's `info` (`inst_x`, which
`inst_attr` uses too).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@yujiaxu-ops
yujiaxu-ops merged commit eb115c9 into main Nov 17, 2026
9 checks passed
@yujiaxu-ops
yujiaxu-ops deleted the emitters-own-meshes branch November 17, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant