// RTMultiShadow 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);
    p.shadowRay = 0u;

    rtEmitPrimaryRay(camera.origin, 0.01, direction, 100000.0,
                     0u, 0xFFu, 0u, 0u, p);
}
