webgpu triangle

This commit is contained in:
Jorijn van der Graaf 2026-05-18 18:43:30 +02:00
commit 5553ded476
22 changed files with 2107 additions and 42 deletions

View file

@ -0,0 +1,39 @@
// WebGPU port of raygen.glsl. Mirrors the pinhole camera setup the
// Payload type is declared in closesthit.wgsl (concatenated earlier).
fn raygen_main(gid: vec3<u32>) {
if (gid.x >= hdr.surfaceW || gid.y >= hdr.surfaceH) { return; }
let pixel = vec2<f32>(f32(gid.x), f32(gid.y));
let resolution = vec2<f32>(f32(hdr.surfaceW), f32(hdr.surfaceH));
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);
traceRay(
0u, // tlasIdx (unused)
0u, // ray flags
0xFFu, // cull mask
0u, 0u, 0u, // sbtRecordOffset, sbtRecordStride, missIndex
origin, 0.001,
direction, 10000.0,
&payload,
);
textureStore(outImage,
vec2<i32>(i32(gid.x), i32(gid.y)),
vec4<f32>(payload.color, 1.0));
}