dynamis-world 0.6.0

GPU-driven physics engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@group(0) @binding(0) var<uniform> params: StepParams;
@group(0) @binding(1) var<storage, read> body_states: array<BodyState>;
@group(0) @binding(2) var<storage, read> body_descs: array<BodyDescriptor>;
@group(0) @binding(3) var<storage, read_write> body_activity: array<u32>;
@group(0) @binding(4) var<storage, read_write> active_count: array<atomic<u32>>;

@compute @workgroup_size(WORKGROUP_SIZE)
fn main(@builtin(global_invocation_id) gid: vec3u) {
    let index = gid.y * (WORKGROUPS_PER_ROW * WORKGROUP_SIZE) + gid.x;
    if (index >= params.body_count) {
        return;
    }
    let moving = body_is_active(body_states[index], body_descs[index]);
    body_activity[index] = select(0u, 1u, moving);
    if (moving) {
        atomicStore(&active_count[0], 1u);
    }
}