Skip to content

A cutout's map answers an emitter's shadow ray - #304

Merged
wryyx merged 3 commits into
meshy-dev:mainfrom
wryyx:cutout-maps
Dec 2, 2026
Merged

wryyx merged 3 commits into
meshy-dev:mainfrom
wryyx:cutout-maps

Conversation

@wryyx

@wryyx wryyx commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

To an emitter's shadow ray every alpha-cutout was opaque (A_CUTOUT_EMITTERS): the leaves of a tree blocked as whole cards. A cutout's triangles now have maps, and those rays ask them, in the one query they are.

Why

Measured against offline renders of the same pose (all figures: Apple M4, half resolution): beside the potted bushes and the hedge of Bistro's walk the picture had 0.78 and 0.71 of the offline light, moving or held. With their alpha tested instead: 0.97 and 0.99, for 18 % more of the frame at the street's first view and 24 % over the walk.

Where that cost lies: Bistro has 285,355 cutout triangles (a tenth of the scene; 3,195 with texture coordinates of their own), 2,200 texels across in the median and three fifths hole. A shadow ray through a crown crosses dozens of cards through their holes, and on the hardware path each hole was a new query from where the last ended. With maps in place of the alpha's reads but the stepping kept, the frame cost what the test costs (18.3 and 20.8 ms for 18.2 and 20.6); one query with the alpha tested in its candidate loop had saved nothing earlier (docs/RUNTIME.md). Both had to go: the reads and the queries.

What

  • Maps (renderer/src/cutout.rs). A cutout's triangle is laid over with a lattice of cells about two texels of its base texture wide (4^7 at most), a cell's state two bits: nothing there, all there, or a part with which is the larger. Made where the scene is prepared, in parallel; triangles with the same texture coordinates and material share one. A stream of the words' heap; an instance's row says where its section's begin.
  • Hardware traversal. The sections that have maps are not flagged opaque. Every other ray forces opacity, as all did; an emitter's shadow ray at a camera hit does not, is handed each such triangle in its one query, and confirms it or passes it by its map. No corner, material or texture is read, and no second query starts past a hole.
  • Software traversal asks the map where it tested the alpha.
  • Edits. A material or texture changed in place drops the maps of the rows drawn with it (the cutout is then opaque to these rays, as before, until the scene is prepared again); an instance placed at run time takes its mesh's.
  • Offline rendering tests the alpha as ever.

Results

before by the maps alpha tested
the bushes' light over offline (kernel samples) 0.78 0.97 0.97
the hedge's 0.71 0.99 0.99
frame GPU p50, the street's first view 15.4-15.5 ms 16.0-16.1 18.2
over the walk 16.7-16.9 ms 17.9-18.1 20.6
  • Offline with every emitter ray by the maps, against the alpha test: the foliage reads 0.9999 and 0.9994 of its light.
  • Bistro recorded while the camera moves, ΔE against offline renders of the same instants: standing still 2.15 → 2.05, mid-strafe 3.18 → 3.11, at a stop 3.60 → 3.52, walking 3.86 → 3.77, 3.98 → 3.73, 4.79 → 4.64.
  • Twelve clips against offline: a night street with its crowd ΔE 3.41 → 3.34; the others within 0.01.
  • Bistro's maps are 7.8 MB; scenes are prepared in the time they took (Bistro 1.5 s, a city of 23 million triangles 11 s).

What it costs

  • 3.6 % of the frame at Bistro's first view and 7 % over its walk; on the twelve clips the street with its crowd +4.5 %, the others within 2 %.
  • bench-object-ghosting and bench-ghosting --quick --check as they were.

The candidate loop on Metal

trace_hw.wgsl records that the ray query's candidate loop lost hits on Metal when every ray's cutouts went through it with their alpha tested (0.1 % of rays near foliage, differently from run to run). In this form (these rays only, the sections with maps only): two offline renders of Bistro's walk pose, 64 samples, every emitter ray by the maps, differ in 2 of 921,600 pixels (with the alpha tested and stepped: 32), and from the same rays stepped in order in 0.19 % of the pixels, their mean within 1e-5.

Validation

  • Unit suite 296 pass (4 new). Render suite 276 of 276 (3 new: shadow/cutout-emitter-live, shadow/cutout-emitter-side, shadow/cutout-emitter-side-live; on main the two live ones read black). The cutout tests pass under software traversal too.
  • npm run typecheck; npm test 324 pass, 1 skipped.
  • Twelve clips against offline: all pass, as above.

Not done

  • The rays of deeper vertices still take a cutout as a card (A_CUTOUT_PATHS); the analytic lights' and the sky's shadow rays at a camera hit still test the alpha and step. Both could go by the maps.
  • A cell is found to be a part by six points: where the levels' limit makes a cell wide (17 texels on Bistro's cards) a twig thinner than their spacing can leave its cell whole or empty. Deciding every cell exactly is work at the rate of the texture's texels, for a bake that does not hold up the scene's preparation.
  • Found beside it, not part of this: in Bistro's walking frame the upper middle of the picture (lamps, a string of lights) has 0.67 of the offline light after the upscaler, before and after this change.
  • Not checked on Vulkan, nor in a browser. The recordings and their measures were made outside the repository.

🤖 Generated with Claude Code

wryyx and others added 3 commits December 2, 2026 20:35
To an emitter's shadow ray every alpha-cutout was opaque (`A_CUTOUT_EMITTERS`): the leaves of a tree blocked as whole
cards. Testing their alpha instead costs a read of each triangle's corners, material and texture, and, on the
hardware path, a new query past every hole.

A cutout's triangles now have maps (cutout.rs): a lattice of cells about two texels wide, each solid, a hole, or a
part of both with its larger part, made once from the base texture's alpha where the scene is prepared; triangles
with the same texture coordinates and material share one. They are a stream of the words' heap, and an instance's
row says where its section's begin.

- Hardware traversal: the sections that have maps are not flagged opaque. Every other ray forces opacity as before;
  an emitter's shadow ray at a camera hit does not, is handed each such triangle in its one query, and confirms it or
  passes it by the map.
- Software traversal asks the map where it tested the alpha.
- A material or texture edited in place drops its rows' maps (the cutout is then opaque to these rays, as before);
  an instance placed at run time takes its mesh's.

Offline rendering tests the alpha as ever.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@wryyx
wryyx merged commit 1296b99 into meshy-dev:main Dec 2, 2026
10 checks passed
@wryyx
wryyx deleted the cutout-maps branch December 2, 2026 13:22
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