Skip to main content

INTEGRATE_WGSL

Constant INTEGRATE_WGSL 

Source
pub const INTEGRATE_WGSL: &str = r#"
pub(super) struct Particle { pos: vec4<f32>, vel: vec4<f32>, }
pub(super) struct IntegParams { dt: f32, gravity_y: f32, n: u32, _pad: u32, }

@group(0) @binding(0) var<storage, read_write> particles: array<Particle>;
@group(0) @binding(1) var<storage, read> forces: array<vec4<f32>>;
@group(0) @binding(2) var<uniform> params: IntegParams;

@compute @workgroup_size(64)
pub(super) fn main(@builtin(global_invocation_id) id: vec3<u32>) {
    let i = id.x;
    if (i >= params.n) { return; }

    var p = particles[i];
    let f = forces[i].xyz + vec3<f32>(0.0, params.gravity_y, 0.0);
    p.vel = vec4<f32>(p.vel.xyz + f * params.dt, 0.0);
    p.pos = vec4<f32>(p.pos.xyz + p.vel.xyz * params.dt, 1.0);
    particles[i] = p;
}
"#;
Expand description

WGSL shader for particle integration (velocity Verlet half-step).