docs(webgpu-rt): add RTVolume example (procedural spheres + any-hit cut-out)
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>
This commit is contained in:
parent
1628e1a58c
commit
5dd1086f08
10 changed files with 420 additions and 1 deletions
24
examples/RTVolume/anyhit.wgsl
Normal file
24
examples/RTVolume/anyhit.wgsl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// RTVolume any-hit shader (runs in TRACE on every candidate sphere hit,
|
||||
// because the geometry is registered non-opaque). Punches a spherical
|
||||
// checkerboard of holes: for half the cells it returns RT_ANYHIT_IGNORE,
|
||||
// so the ray passes straight through and the background / spheres behind
|
||||
// show through. Returning RT_ANYHIT_ACCEPT keeps the hit. This is the
|
||||
// visible proof the any-hit path runs — with it the spheres are perforated,
|
||||
// without it they would be solid.
|
||||
fn anyhit_main(ray: RayDesc, hit: HitInfo, payload: ptr<function, Payload>) -> u32 {
|
||||
// Object-space hit point on the unit sphere → its normal/direction.
|
||||
let posObj = hit.objectRayOrigin + hit.objectRayDirection * hit.t;
|
||||
let n = normalize(posObj);
|
||||
|
||||
let PI = 3.14159265;
|
||||
let longitude = atan2(n.z, n.x); // [-PI, PI]
|
||||
let latitude = asin(clamp(n.y, -1.0, 1.0)); // [-PI/2, PI/2]
|
||||
|
||||
let cu = i32(floor((longitude + PI) / PI * 6.0));
|
||||
let cv = i32(floor((latitude + PI * 0.5) / PI * 6.0));
|
||||
|
||||
if (((cu + cv) & 1) == 0) {
|
||||
return RT_ANYHIT_IGNORE; // cut-out cell — see through
|
||||
}
|
||||
return RT_ANYHIT_ACCEPT;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue