Crafter.Graphics/examples/RTVolume
catbot 0d1312ac09 example(RTVolume): GPU-written device-buffer procedural AABBs (#37)
A compute shader (aabbs.comp.{glsl,wgsl}) writes the procedural box into a
device buffer that BuildProcedural consumes by device address/handle with no
host copy; the WebGPU path also refits from it each frame so the box breathes.
Verified rendering on both Vulkan (native) and WebGPU (browser).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-16 14:12:12 +00:00
..
aabbs.comp.glsl example(RTVolume): GPU-written device-buffer procedural AABBs (#37) 2026-06-16 14:12:12 +00:00
aabbs.comp.wgsl example(RTVolume): GPU-written device-buffer procedural AABBs (#37) 2026-06-16 14:12:12 +00:00
anyhit.glsl test(vulkan-rt): port RTVolume example to native Vulkan (#33) 2026-06-13 00:17:37 +00:00
anyhit.wgsl docs(webgpu-rt): add RTVolume example (procedural spheres + any-hit cut-out) 2026-06-02 22:09:30 +00:00
closesthit.glsl test(vulkan-rt): port RTVolume example to native Vulkan (#33) 2026-06-13 00:17:37 +00:00
closesthit.wgsl docs(webgpu-rt): add RTVolume example (procedural spheres + any-hit cut-out) 2026-06-02 22:09:30 +00:00
intersection.glsl test(vulkan-rt): port RTVolume example to native Vulkan (#33) 2026-06-13 00:17:37 +00:00
intersection.wgsl docs(webgpu-rt): add RTVolume example (procedural spheres + any-hit cut-out) 2026-06-02 22:09:30 +00:00
main.cpp example(RTVolume): GPU-written device-buffer procedural AABBs (#37) 2026-06-16 14:12:12 +00:00
miss.glsl test(vulkan-rt): port RTVolume example to native Vulkan (#33) 2026-06-13 00:17:37 +00:00
miss.wgsl docs(webgpu-rt): add RTVolume example (procedural spheres + any-hit cut-out) 2026-06-02 22:09:30 +00:00
project.cpp example(RTVolume): GPU-written device-buffer procedural AABBs (#37) 2026-06-16 14:12:12 +00:00
raygen.glsl test(vulkan-rt): port RTVolume example to native Vulkan (#33) 2026-06-13 00:17:37 +00:00
raygen.wgsl docs(webgpu-rt): add RTVolume example (procedural spheres + any-hit cut-out) 2026-06-02 22:09:30 +00:00
README.md test(vulkan-rt): port RTVolume example to native Vulkan (#33) 2026-06-13 00:17:37 +00:00
resolve.wgsl docs(webgpu-rt): add RTVolume example (procedural spheres + any-hit cut-out) 2026-06-02 22:09:30 +00:00

RTVolume

Ray tracing of procedural (AABB) geometry with an any-hit cut-out on both backends — software WebGPU (issue #13) and native Vulkan hardware RT (issue #33).

A 3×3×3 grid of unit boxes is registered as an AABB BLAS (Mesh::BuildProceduralVK_GEOMETRY_TYPE_AABBS_KHR on Vulkan, the software AABB-leaf path on WebGPU). The hit group is procedural (RTShaderGroupType::ProceduralHitGroup / VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR) carrying:

  • intersection.wgsl / intersection.glsl — analytic raysphere test that turns each box into a radius-1 sphere (runs once per box the ray enters);
  • anyhit.wgsl / anyhit.glsl — ignores the intersection for half the cells of a spherical checkerboard, so the ray passes through and the background / spheres behind show through (the visible proof any-hit runs);
  • closesthit.wgsl / closesthit.glsl — normal-based Lambert shading, tinted per instance.

The geometry is registered non-opaque and the instances clear their force-opaque flag, which is what lets the any-hit shader run. Flip the instance flag to kRTGeometryInstanceForceOpaque (or build the mesh with opaque = true) to skip any-hit and see solid spheres.

WebGPU/DOM (free camera, WASD + mouse):

crafter-build --target=wasm32-wasip1 -r

Native Vulkan (fixed camera in raygen.glsl):

crafter-build -r