2026-05-31 16:24:41 +00:00
|
|
|
// WebGPU wavefront raygen. Runs in GENERATE: compute the pinhole camera
|
|
|
|
|
// ray and emit it as the pixel's primary ray. Shading happens later in
|
|
|
|
|
// SHADE (closesthit/miss). The Payload type is declared in closesthit.wgsl.
|
2026-05-18 18:43:30 +02:00
|
|
|
|
|
|
|
|
fn raygen_main(gid: vec3<u32>) {
|
2026-05-31 16:24:41 +00:00
|
|
|
if (gid.x >= wfParams.surfaceW || gid.y >= wfParams.surfaceH) { return; }
|
2026-05-18 18:43:30 +02:00
|
|
|
|
|
|
|
|
let pixel = vec2<f32>(f32(gid.x), f32(gid.y));
|
2026-05-31 16:24:41 +00:00
|
|
|
let resolution = vec2<f32>(f32(wfParams.surfaceW), f32(wfParams.surfaceH));
|
2026-05-18 18:43:30 +02:00
|
|
|
let uv = (pixel + vec2<f32>(0.5)) / resolution;
|
|
|
|
|
let ndc = uv * 2.0 - vec2<f32>(1.0);
|
|
|
|
|
|
|
|
|
|
let origin = vec3<f32>(0.0, 0.0, -300.0);
|
|
|
|
|
let aspect = resolution.x / resolution.y;
|
|
|
|
|
let fov = 60.0 * 3.14159265 / 180.0;
|
|
|
|
|
let tanHalfFov = tan(fov * 0.5);
|
|
|
|
|
|
|
|
|
|
let direction = normalize(vec3<f32>(
|
|
|
|
|
ndc.x * aspect * tanHalfFov,
|
|
|
|
|
-ndc.y * tanHalfFov,
|
|
|
|
|
1.0,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
var payload: Payload;
|
|
|
|
|
payload.color = vec3<f32>(0.0);
|
|
|
|
|
|
2026-05-31 16:24:41 +00:00
|
|
|
rtEmitPrimaryRay(
|
2026-05-18 18:43:30 +02:00
|
|
|
origin, 0.001,
|
|
|
|
|
direction, 10000.0,
|
2026-05-31 16:24:41 +00:00
|
|
|
0u, // ray flags
|
|
|
|
|
0xFFu, // cull mask
|
|
|
|
|
0u, 0u, // sbtRecordOffset, missIndex
|
|
|
|
|
payload);
|
2026-05-18 18:43:30 +02:00
|
|
|
}
|