Skip to content

Glass is a part of its mesh - #161

Merged
yujiaxu-ops merged 5 commits into
mainfrom
glass-on-instances
Nov 18, 2026
Merged

yujiaxu-ops merged 5 commits into
mainfrom
glass-on-instances

Conversation

@yujiaxu-ops

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

Copy link
Copy Markdown
Collaborator

The last reason to flatten a material's triangles at every placement goes: glass. Next part of ROADMAP § 6 step 3, after functions and mirrored placements (#160).

The experiment first

A shadow ray passes glass by the still scene's instance masks; an instance's glass sits in the same BLAS as its opaque triangles. Two structures were open: glass as a geometry of the mesh's BLAS that a shadow ray culls (RAY_FLAG_CULL_NO_OPAQUE), or glass split into a BLAS and an instance of its own. The kernel's notes had the cull flag as slow on Metal (Bistro +1.7 ms; its use for cutouts then). Measured again before building anything: every geometry flagged opaque and shadow rays with the cull flag instead of forced opacity, so that nothing may change.

  • Metal: 249 pictures, none changed. Vulkan (RTX 5090): 245, none changed but one live test within its own two outcomes.
  • GPU time over twelve live scenes: at most +0.5 % (Kabukicho 7.98 for 7.94 ms, three alternated runs), the rest within 0.3 %.

So: one BLAS a mesh, and a placement stays one instance.

What changes

  • The mesh. Its triangles are ordered opaque, cutout, glass; each kind that is there is a geometry of the BLAS, the glass one the only one not flagged opaque (InstMesh::parts). Cutout geometries and the still scene's groups are flagged opaque now: every other query forces opacity and sees no difference.
  • Shadow rays, a mesh that is all glass: its instance is out of their way by its mask, as the still scene's glass is (InstMesh::casts). No kernel feature, no cost.
  • Shadow rays, a mesh that mixes glass with other triangles: they cull the geometry that is not opaque (kernel feature F_IGLASS). Under software traversal a unit's glass triangles carry the no-shadow flag, as the flattened ones do. glass_tr weighs what the glass lets through as before.
  • A hit's triangle from its geometry and primitive: the instance's record has where the second and the third geometry start.
  • A mirrored glass instance: which side of a surface a ray meets goes by the instance's sign (Material functions and mirrored placements on instances #160 set it; glass is its first reader).
  • Edits: a mesh that is all glass is added in place; a material of instances' triangles that turns glass, or stops being glass, rebuilds.

Why two rules: the first version culled inside every glass mesh's BLAS, and a scene of 400 glass panes then traced 5.34 ms for main's 4.62; with the mask 4.45 (under the loop guard: a direction, not a timing; the pictures the same).

What still leaves a mesh and is flattened at a placement: triangles on exactly the same vertices (flatten_coincident: a cutout on an emitter, glass on whatever lies under it), and the emitters of a mesh that deforms. The rest arrays stay for those.

Tests

  • A shadow through an instance's glass, analytic: a mesh of its own offline, live exact and live (shadow/glass-tint-instance*), an instanced copy (shadow/glass-tint-instanced).
  • A model whose one mesh has an opaque, a cutout and a glass part (tests/render/data/frame-pane.glb): the light through the glass offline and live (shadow/glass-model, -live-exact), and the other two parts' shadows (-frame, -cutout).
  • glass/mirrored-instance: two slabs, mirror images, one placed with a negative scale, show the wall behind alike.
  • The model's build (three geometries, the record's two starts, the feature); a glass mesh added in place (no feature, no shadow mask), and a material turned glass.
  • Mutants, each failing on the path meant: the mask rule gone, the glass part flagged opaque, the feature never set, no third geometry's start, the units' walk without the skip, a unit's glass not flagged, the flattening's flags without glass, surface's normal without the instance's sign, the edit guard.
  • 177 unit tests, 258 render tests natively; under software traversal the branch and main fail the same 24 with the same values. Against main, natively: 230 of 258 pictures byte-identical, 25 within their run-to-run spread, three new glass tests differ by rounding (their glass is flattened on main).

Not covered

  • glass_at's normal under a mirroring instance (it decides total reflection where a volume's voxel rays cross glass): set by the same sign, no test reads it.
  • The cost of the cull inside a mixed mesh on a heavy scene: Bistro, Zero Day, Kabukicho and Tokyo have no model with glass (checked with THREERT_INSTANCING=log), so only the test model takes that path.

🤖 Generated with Claude Code


Note

High Risk
Changes hardware and software ray traversal, BLAS layout, and live-edit feature gating for glass—core path-tracing behavior with performance-sensitive shadow-ray culling.

Overview
Instanced meshes no longer flatten glass at every placement. Glass triangles stay in the shared model-space BLAS as a third geometry (opaque → cutout → glass), with only the glass geometry left non-opaque.

Shadow handling uses two paths: all-glass meshes skip shadow queries via instance masks (InstMesh::casts); mixed meshes enable kernel feature F_IGLASS so hardware RT uses RAY_FLAG_CULL_NO_OPAQUE on shadow rays and software traversal skips TRI_NO_SHADOW glass. Transmission weighting via glass_tr is unchanged. Hit triangle indexing and glass_at normals account for a third geometry offset in instance records and mirrored instance sign.

Build and live paths classify materials with mesh_class (glass = class 2), extend flatten_coincident for glass-on-coincident-vertices only, and allow adding all-glass meshes in place while rebuild when a fixed instanced material toggles glass. Docs and render/unit tests cover shadows through instance glass, mixed glTF meshes, and mirrored panes.

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

yujiaxu-ops and others added 5 commits November 18, 2026 17:41
The last reason to flatten a material's triangles at every placement goes
(ROADMAP § 6 step 3). A mesh's glass is a geometry of its BLAS beside the
opaque and the cutout one, the only one not flagged opaque; a placement
stays one instance.

- A shadow ray, which passed glass by the still scene's masks, culls the
  geometry that is not opaque where an instanced mesh has glass (kernel
  feature F_IGLASS); `glass_tr` weighs what the glass lets through as
  before. Software traversal: a flag a triangle (units), the flattening's
  flags.
- A hit's triangle from its geometry and primitive: two starts in the
  instance's record (`InstMesh::part_offsets`).
- Which side of a surface a ray meets goes by the instance's sign: a
  mirrored glass instance refracts as its mirror image does.
- A glass mesh is added in place where the kernel has the feature; a
  material of instances' triangles that turns glass, or stops, rebuilds.
- What still leaves a mesh: triangles on exactly the same vertices
  (`flatten_coincident`: a cutout on an emitter, glass on what lies under
  it), and the emitters of a mesh that deforms.

Measured first on Metal with every geometry flagged opaque and the cull
flag on shadow rays: the same pictures, at most 0.5 % of a frame's GPU time.

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

Culled inside its BLAS, a scene of many glass panes traced slower (400
instanced panes under a low sun: trace 5.34 ms for 4.62 with the panes
flattened). A mesh that is all glass needs no cull: its instances cast no
shadow, by the mask a shadow ray already goes by (`InstMesh::casts`); the
same scene reads 4.45 ms, the picture unchanged. The cull, and its kernel
feature, are left to a mesh that has glass among other triangles. A glass
mesh added in place needs nothing of the kernel.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Under software traversal its unit's glass triangles are skipped by their flag:
no live test read that (the all-glass ones go by the unit's own flag).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A mesh that is all glass is out of a shadow ray's way by its instance's mask; the cull and its kernel feature are
for a mesh that mixes glass with other triangles.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Every group's geometry is flagged opaque since glass went into its mesh; the size estimate asks with that flag too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@yujiaxu-ops
yujiaxu-ops merged commit 17c8e10 into main Nov 18, 2026
9 checks passed
@yujiaxu-ops
yujiaxu-ops deleted the glass-on-instances branch November 18, 2026 10:59
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