feat(webgpu-rt): any-hit + AABB (procedural) geometry support #14

Merged
catbot merged 4 commits from claude/issue-13 into master 2026-06-03 00:10:17 +02:00
Member

Adds the two missing WebGPU ray-tracing capabilities from #13: any-hit shaders and an equivalent to VK_GEOMETRY_TYPE_AABBS_KHR (procedural / AABB geometry with intersection shaders).

What changed

Type surface (cross-backend)

  • RTShaderGroupType::ProceduralHitGroup + RTShaderGroup::intersectionShader (mirror VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR).
  • WebGPURTStage::Intersection for AABB intersection shaders.
  • Mesh::BuildProcedural(span<RTAabb>, opaque) — the WebGPU analog of an AABB geometry BLAS.

Codegen (PipelineRTWebGPU)

  • Emits a runIntersection mega-switch alongside the existing runAnyHit switch, plus RT_HAS_ANYHIT / RT_HAS_INTERSECTION consts and the @CRAFTER_RT_TRACE_USER marker.

WGSL library (dom-webgpu.js)

  • TRACE-stage BLAS descent now threads the payload through and runs the any-hit shader for non-opaque candidates, with full DXR/VK opacity resolution (ray FORCE flags → instance FORCE flags → geometry opaque bit).
  • AABB leaves dispatch to the intersection shader; MeshRecord grows to 64 bytes (geomType + opaque).
  • When any-hit/intersection are registered, TRACE adopts the user bind-group layout so those shaders can sample @group(3+) resources. Opaque triangle-only scenes are unchanged — the user-callback branches const-fold away and TRACE keeps its zero-user-code footprint.
  • rayQuery stays triangle-only (skips AABB leaves rather than misreading them).

Mesh build — SAH BVH2 over AABB primitives, uploaded in primitive order so the intersection shader fetches the right box.

Testing

  • crafter-build test — clean (the library defines no automated tests; this RT path is browser-verified, as with #8 / #11).
  • New examples/RTVolume: 27 procedural spheres via an analytic ray-sphere intersection shader, perforated by an any-hit spherical-checkerboard cut-out — verified rendering in Firefox/WebGPU (screenshot below).
  • Regression: rebuilt + re-ran RTStress (opaque triangle path) in Firefox — renders identically, no console errors.

Screenshots

RTVolume

Resolves #13

Adds the two missing WebGPU ray-tracing capabilities from #13: **any-hit shaders** and an equivalent to **`VK_GEOMETRY_TYPE_AABBS_KHR`** (procedural / AABB geometry with intersection shaders). ## What changed **Type surface (cross-backend)** - `RTShaderGroupType::ProceduralHitGroup` + `RTShaderGroup::intersectionShader` (mirror `VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR`). - `WebGPURTStage::Intersection` for AABB intersection shaders. - `Mesh::BuildProcedural(span<RTAabb>, opaque)` — the WebGPU analog of an AABB geometry BLAS. **Codegen (`PipelineRTWebGPU`)** - Emits a `runIntersection` mega-switch alongside the existing `runAnyHit` switch, plus `RT_HAS_ANYHIT` / `RT_HAS_INTERSECTION` consts and the `@CRAFTER_RT_TRACE_USER` marker. **WGSL library (`dom-webgpu.js`)** - TRACE-stage BLAS descent now threads the payload through and runs the any-hit shader for **non-opaque** candidates, with full DXR/VK opacity resolution (ray FORCE flags → instance FORCE flags → geometry opaque bit). - AABB leaves dispatch to the intersection shader; `MeshRecord` grows to 64 bytes (`geomType` + `opaque`). - When any-hit/intersection are registered, TRACE adopts the user bind-group layout so those shaders can sample `@group(3+)` resources. **Opaque triangle-only scenes are unchanged** — the user-callback branches const-fold away and TRACE keeps its zero-user-code footprint. - rayQuery stays triangle-only (skips AABB leaves rather than misreading them). **Mesh build** — SAH BVH2 over AABB primitives, uploaded in primitive order so the intersection shader fetches the right box. ## Testing - `crafter-build test` — clean (the library defines no automated tests; this RT path is browser-verified, as with #8 / #11). - **New `examples/RTVolume`**: 27 procedural spheres via an analytic ray-sphere intersection shader, perforated by an any-hit spherical-checkerboard cut-out — verified rendering in Firefox/WebGPU (screenshot below). - **Regression**: rebuilt + re-ran `RTStress` (opaque triangle path) in Firefox — renders identically, no console errors. ## Screenshots ![RTVolume](https://forgejo.catcrafts.net/attachments/e7098b1f-ab73-41e2-b30a-52a2f142bdf2) Resolves #13
Extends the cross-backend RT type surface for procedural geometry +
any-hit on the WebGPU path:

- RTShaderGroupType::ProceduralHitGroup + RTShaderGroup::intersectionShader
  (mirror VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR).
- WebGPURTStage::Intersection for AABB intersection shaders.
- Mesh::BuildProcedural(span<RTAabb>, opaque) — the WebGPU analog of a
  VK_GEOMETRY_TYPE_AABBS_KHR geometry.
- wgpuRegisterMeshBLAS gains geomType / opaqueFlag / primCount.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
PipelineRTWebGPU emits a runIntersection mega-switch and the
RT_HAS_ANYHIT / RT_HAS_INTERSECTION consts (+ the @CRAFTER_RT_TRACE_USER
marker) that gate the library's new TRACE-stage user callbacks, so an
opaque triangle-only scene still const-folds them away. Mesh-WebGPU
builds a SAH BVH2 over AABB primitives and uploads them in primitive
order for the intersection shader to fetch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The TRACE-stage BLAS descent now threads the payload through, runs the
any-hit shader for non-opaque candidates (DXR/VK opacity resolution:
ray FORCE flags > instance FORCE flags > geometry opaque bit), and
handles AABB leaves via the intersection shader. MeshRecord grows to 64
bytes with geomType + opaque. When any-hit/intersection are present the
TRACE pipeline takes the user bind-group layout so those shaders can
sample @group(3+) resources; otherwise TRACE keeps its zero-user-code
path unchanged. rayQuery stays triangle-only (skips AABB leaves).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A 3x3x3 grid of AABB-geometry spheres rendered through an analytic
ray-sphere intersection shader, with an any-hit spherical-checkerboard
cut-out so the background shows through. Exercises both features end to
end on the WebGPU wavefront tracer.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit b9f65f5273 into master 2026-06-03 00:10:17 +02:00
catbot deleted branch claude/issue-13 2026-06-03 00:10:17 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Catcrafts/Crafter.Graphics!14
No description provided.