pub const PARTICLE_COUNT_GLSL: &str = r#"
#version 430 core
layout(local_size_x = 256) in;
struct Particle { vec4 position; vec4 velocity; vec4 color; float size; float mass; uint flags; uint attractor; };
layout(std430, binding = 0) readonly buffer ParticleBuffer { Particle particles[]; };
layout(std430, binding = 1) buffer IndirectBuffer {
uint vertex_count;
uint instance_count;
uint first_vertex;
uint base_instance;
};
uniform uint num_particles;
shared uint local_count;
void main() {
if (gl_LocalInvocationID.x == 0) local_count = 0;
barrier();
uint idx = gl_GlobalInvocationID.x;
if (idx < num_particles && (particles[idx].flags & 1u) != 0u) {
atomicAdd(local_count, 1u);
}
barrier();
if (gl_LocalInvocationID.x == 0) {
atomicAdd(instance_count, local_count);
}
if (idx == 0) vertex_count = 4u; // Billboard quad = 4 verts
}
"#;Expand description
Indirect draw generation — count alive particles and build draw command.