Repository navigation
Material functions and mirrored placements on instances - #160
Conversation
A function's inputs outside full shading (the alpha test of a candidate hit, an emitter's radiance in light sampling) read the triangle as world space, so a mesh with a function material was flattened at every placement. `mat_in_at` takes the instance and places the triangle as `surface` does; such a mesh is an instance like any other, its emitters in the light list. Tests: a function's emission and a function's alpha on a mesh of its own, far from the origin (analytic). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A mesh, a model, an instanced object's copy or a rigid model's node placed with a negative scale was flattened (a rigid node's mesh was built with its winding swapped instead). The instance's record now says that it mirrors (`INST_MIRRORED`), and the kernel's placement takes the sign: the geometric normal's side and the tangent frame's hand. The flattening path (software traversal without units, a model's glass part) swaps the second and third vertex of a mirroring instance's triangles, attributes and vertex colours alike. An instanced object's copy may become mirrored in place. Tests: the tangent frame's hand and the geometric normal through a function, vertex colours, a mirrored model's build, a copy mirrored in place; the flattening of an instance against the build's flattening, mirrored too. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
It rebuilt the scene. Each copy's emitters now come into the light list where its record is made (a run a copy at the list's end; a hidden copy's at no weight), as an instance's do. Tests: added, changed and removed in place against a build, with and without a light tree; an analytic live test. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
| let (mat, class, emits) = resolve(t.material.and_then(|i| doc.materials().nth(i)))?; | ||
| classed[if emits { 2 } else { class as usize }].push((k, mat)); | ||
| } | ||
| // Triangles flattened per placement (glass, emissive, functions): each model skinned alone. |
There was a problem hiding this comment.
Mirrored rigid rest triangles keep winding
Medium Severity
A rigid node's flattened rest (glass, coincident cutouts) is still transformed by the mirroring matrix without swapping the second and third vertex. Local triangles are no longer pre-flipped, so ng points inward and front is inverted. Static models already go through Instance::flat; pose updates re-transform rest_local the same way.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 5d126d4. Configure here.
…used `mat_in_at`'s placement by the instance cost a scene that has no material function on an instanced mesh: the kernel's compiler works it out for every call, taken or not (Kabukicho's 64,224 emitters with a function, none on an instance: frame GPU +2.7 %). A kernel feature, F_IFUNC, set by the build when an instanced mesh has a material function; an edit that would need it (such a mesh added in place, a material of instances' triangles that gets or loses its function) rebuilds. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit d8673aa. Configure here.
| // whether there is one, `gpu::F_IFUNC`, which the build decides.) | ||
| if (gm.tex1[3] != 0) != (self.materials[mi as usize].tex1[3] != 0) && self.fixed_mats.contains(&mi) { | ||
| return Ok(None); | ||
| } |
There was a problem hiding this comment.
Instance function edits skip rebuild
Medium Severity
A material function added after an instance is placed in place can skip the rebuild that turns on F_IFUNC. mat_in_at now places the triangle only when that bit is set, and the new guard only rebuilds if the material is already in fixed_mats from the original build. An own-BLAS or instanced mesh added in place with a shared non-function material is never recorded there, so attaching a function later leaves the kernel reading model space for alpha and light sampling.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit d8673aa. Configure here.
…terial is known Review findings, and one more of the same kind: - A rigid model's moving node no longer has its mesh pre-swapped, so what the build flattens of it (glass, a cutout on an emitter) faced inward under a mirroring node. Placed by `placed_tri` now, at the build and at a pose: the second and third vertex change places, an authored tangent's frame changes hand. - A mesh added in place puts its material among those of instances' triangles (`Tables::fixed_mats`): a function it gets later rebuilds (F_IFUNC). - The model loader's world-space triangles: an authored tangent's frame changes hand under a mirrored placement (it kept its sign). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>


Two more reasons to flatten a mesh at every placement go: a material function, and a placement that mirrors. Plus what #159 left: an emitting instanced object added in place. Next part of ROADMAP § 6 step 3; what the build still flattens at a placement after this is glass.
What changes
mat_in_at) read the triangle as world space, so a mesh with a function material was flattened. They now place the triangle by its instance, as full shading does.INST_MIRRORED), and the kernel's placement takes the sign for the geometric normal's side and the tangent frame's hand. A copy may become mirrored in place.Instance::flat,placed_tri).F_IFUNC: the placement inmat_in_atis compiled in only where an instanced mesh has a material function (below). An edit that would need it (such a mesh added in place, a material of instances' triangles that gets or loses its function) rebuilds.One picture changes: authored tangents under a mirrored placement
A model's authored tangent kept its sign when its placement mirrored (flattened, or a rigid node), so the tangent frame had the wrong hand there and a normal map read inverted. The hand is now set by the placement everywhere (the instance's sign; the model loader for what stays in world space). Seen on Zero Day: one object at the clip's start shades otherwise (with the instance's sign alone: 0.24 of 255 mean difference at 1 s, falling to 0.02 at 8 s); the scene's dE against its offline reference reads 3.67 for 3.63, the museum's 7.21 for 7.22 (the references were rendered before this change; not re-rendered here). No test asset has authored tangents: the hand is held by unit tests (the flattening of an instance against a triangle built from its world-space vertices and UVs; the loader's sign), not by a picture.
Cost
None measured. Twelve live scenes against main: GPU time the same, pictures the same but for the two above.
On the way: placing a function's inputs by the instance first cost Kabukicho +3.6 % of its frame's GPU time (7.96 -> 8.25 ms, alternated runs), though nothing there is on an instance: its 77,848 emitters, 64,224 with a function, are all in world space, and the kernel's compiler worked the untaken placement out for every light sample. With
F_IFUNCthe scene's kernel has no such code: 7.96 against main's 7.96.Tests
material/function-emitter-instance(light sampling),material/function-alpha-instance(the alpha test).material/function-mirrored(the tangent frame's hand),material/function-emitter-mirrored(the geometric normal in light sampling),material/vertex-colors-mirrored.geometry/emitter-instanced-added-live, and in place against a build: an emitting instanced object added, changed and removed; a copy mirrored.mat_in_atwithout the instance at either caller; the feature never set; the kernel's hand, the CPU's hand, the colours or the vertices not swapped, no flag in the record,mat_in_at's normal without the sign; no emitters or a hidden copy's power kept at the add; a mirrored node's flattened part not swapped, an added mesh's material not recorded, the loader's hand kept.Not covered
surface'sfrontunder a mirroring instance has no reader yet (glass and one-sided cards are never instances): right by the same sign, not tested until glass is on instances.placed_tri, with no test asset that has one.Left
Glass (shadow rays pass it): the last thing flattened at a placement.
🤖 Generated with Claude Code