summaryrefslogtreecommitdiff
path: root/src/effects/particle_compute.wgsl
blob: 148a2c3c1d38edc2c3da436fb954f13675574faa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Particle simulation (compute shader) - V2
#include "particle_common"
#include "sequence_uniforms"

@group(0) @binding(0) var<storage, read_write> particles: array<Particle>;
@group(0) @binding(1) var<uniform> uniforms: UniformsSequenceParams;

@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) id: vec3u) {
    let i = id.x;
    if (i >= arrayLength(&particles)) {
        return;
    }
    var p = particles[i];
    let new_pos = p.pos.xyz + p.vel.xyz * 0.016;
    p.pos = vec4f(new_pos, p.pos.w);
    p.vel.y = p.vel.y - 0.01 * (1.0 + uniforms.audio_intensity * 5.0);
    p.rot.x = p.rot.x + p.rot.y * 0.016;
    if (p.pos.y < -1.5) {
        // Stagger respawn height by index (golden ratio) to break synchronization
        p.pos.y = 1.5 + fract(f32(i) * 0.6180339) * 3.0;
        p.pos.x = (f32(i % 100u) / 50.0) - 1.0 + (uniforms.audio_intensity * 0.5);
        p.vel.y = 0.0;
    }
    particles[i] = p;
}