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
34
examples/RTVolume/raygen.wgsl
Normal file
34
examples/RTVolume/raygen.wgsl
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// RTVolume raygen (runs in GENERATE). Host-driven pinhole camera at
|
||||
// @group(3) (groups 0..2 are reserved by the wavefront pipeline:
|
||||
// 0 = WfParams, 1 = data heaps, 2 = indirect args).
|
||||
struct Camera {
|
||||
origin: vec3<f32>,
|
||||
pad0: f32,
|
||||
right: vec3<f32>,
|
||||
tanHalf: f32,
|
||||
up: vec3<f32>,
|
||||
aspect: f32,
|
||||
forward: vec3<f32>,
|
||||
pad1: f32,
|
||||
};
|
||||
@group(3) @binding(0) var<storage, read> camera : Camera;
|
||||
|
||||
fn raygen_main(gid: vec3<u32>) {
|
||||
if (gid.x >= wfParams.surfaceW || gid.y >= wfParams.surfaceH) { return; }
|
||||
|
||||
let pixelf = vec2<f32>(f32(gid.x), f32(gid.y));
|
||||
let res = vec2<f32>(f32(wfParams.surfaceW), f32(wfParams.surfaceH));
|
||||
let uv = (pixelf + vec2<f32>(0.5)) / res;
|
||||
let ndc = uv * 2.0 - vec2<f32>(1.0);
|
||||
|
||||
let direction = normalize(
|
||||
camera.right * (ndc.x * camera.aspect * camera.tanHalf) +
|
||||
camera.up * (-ndc.y * camera.tanHalf) +
|
||||
camera.forward);
|
||||
|
||||
var p: Payload;
|
||||
p.color = vec3<f32>(0.0);
|
||||
|
||||
rtEmitPrimaryRay(camera.origin, 0.01, direction, 100000.0,
|
||||
0u, 0xFFu, 0u, 0u, p);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue