nuclear-plant-sim/assets/shader/particles.comp

63 lines
1.5 KiB
Plaintext

#include "header.glsl"
#include "random.glsl"
layout (local_size_x = 32, local_size_y = 1, local_size_z = 1) in;
struct VertType {
vec4 pos;
vec4 colour;
vec2 uv;
float texid;
};
struct ParticleType {
vec4 pos; // xyz: pos, w: vel random scale
vec4 velocity; // xyz: vel, w: colour random scale
vec4 colour;
float time_start;
float duration;
float size;
int seed;
};
layout (binding = SSBO_PARTICLES_IN) readonly buffer ParticleBufferIn {
ParticleType particles_in[];
};
layout (binding = SSBO_PARTICLES_OUT) writeonly buffer ParticleBufferOut {
VertType vertices_out[];
};
layout (binding = UBO_PARTICLES_INFO) uniform ParticleInfo {
float p_time;
int p_size;
};
void main() {
ParticleType particle = particles_in[gl_WorkGroupID.x];
int seed = particle.seed;
rand_mix(seed, int(gl_LocalInvocationID.x));
float duration = clamp((p_time - particle.time_start) / particle.duration, 0, 1);
vec3 velocity = normalize(vec3(
rand_float(seed) * 2 - 1,
rand_float(seed) * 2 - 1,
rand_float(seed) * 2 - 1
)) * particle.pos.w + particle.velocity.xyz;
vec4 colour = normalize(vec4(
rand_float(seed) * 2 - 1,
rand_float(seed) * 2 - 1,
rand_float(seed) * 2 - 1,
rand_float(seed) * 2 - 1
)) * particle.velocity.w + particle.colour;
vec3 pos = particle.pos.xyz + velocity * duration;
colour.a *= (1 - duration);
uint v_id = gl_GlobalInvocationID.x;
vertices_out[v_id].pos = vec4(pos, 1);
vertices_out[v_id].colour = colour;
vertices_out[v_id].texid = TEXID_WHITE;
}