nightshade 0.8.0

A cross-platform data-oriented game engine.
Documentation
struct PickOutput {
    depth: f32,
    entity_id: u32,
};

@group(0) @binding(0) var depth_texture: texture_depth_2d;
@group(0) @binding(1) var<storage, read_write> output: array<PickOutput>;
@group(0) @binding(2) var<uniform> params: PickParams;
@group(0) @binding(3) var entity_id_texture: texture_2d<f32>;

struct PickParams {
    center_x: u32,
    center_y: u32,
    sample_size: u32,
    _padding: u32,
}

@compute @workgroup_size(1, 1, 1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
    let half_size = params.sample_size / 2u;
    let px = params.center_x + global_id.x - half_size;
    let py = params.center_y + global_id.y - half_size;

    let dims = textureDimensions(depth_texture);

    var depth_value: f32 = 0.0;
    var entity_id_value: u32 = 0u;
    if px < dims.x && py < dims.y {
        depth_value = textureLoad(depth_texture, vec2<u32>(px, py), 0);
        let entity_id_float = textureLoad(entity_id_texture, vec2<u32>(px, py), 0).r;
        entity_id_value = bitcast<u32>(entity_id_float);
    }

    let index = global_id.y * params.sample_size + global_id.x;
    output[index].depth = depth_value;
    output[index].entity_id = entity_id_value;
}