2021-12-16 14:17:01 +00:00
|
|
|
#version 450
|
|
|
|
|
2022-11-28 02:09:20 +00:00
|
|
|
layout (local_size_x = 1, local_size_y = 1) in;
|
2021-12-16 14:17:01 +00:00
|
|
|
|
|
|
|
struct Particle {
|
|
|
|
vec4 pos;
|
|
|
|
vec4 vel;
|
|
|
|
vec4 color;
|
|
|
|
float tex;
|
|
|
|
float ramp;
|
|
|
|
float scale;
|
|
|
|
float live;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Parameters {
|
|
|
|
vec4 drag; // [dx, dy, dz, grav scale]
|
|
|
|
vec4 ramp; // [rate, max, alpha rate, scale rate]
|
|
|
|
};
|
|
|
|
|
|
|
|
layout(std140, set = 0, binding = 0) buffer ParticleStates {
|
|
|
|
Particle particles[];
|
|
|
|
};
|
|
|
|
|
|
|
|
layout(std140, set = 0, binding = 1) buffer ParticleParameters {
|
|
|
|
Parameters parameters[];
|
|
|
|
};
|
|
|
|
|
2021-12-16 15:18:25 +00:00
|
|
|
//doubles as VkDrawIndirectCommand
|
2021-12-16 14:17:01 +00:00
|
|
|
layout(std140, set = 0, binding = 2) buffer ParticleSystem {
|
2021-12-16 15:18:25 +00:00
|
|
|
uint vertexCount;
|
|
|
|
uint particleCount; //instanceCount
|
|
|
|
uint firstVertex;
|
|
|
|
uint firstInstance;
|
2021-12-16 14:17:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
layout (push_constant) uniform PushConstants {
|
|
|
|
vec4 gravity;
|
|
|
|
float dT;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
main ()
|
|
|
|
{
|
|
|
|
uint ind = gl_GlobalInvocationID.x;
|
|
|
|
if (ind >= particleCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Particle part = particles[ind];
|
|
|
|
Parameters parm = parameters[ind];
|
|
|
|
|
|
|
|
part.pos += dT * part.vel;
|
|
|
|
part.vel += dT * (part.vel * parm.drag + gravity * parm.drag.w);
|
|
|
|
|
|
|
|
part.ramp += dT * parm.ramp.x;
|
|
|
|
part.scale += dT * parm.ramp.z;
|
|
|
|
part.color.a -= dT * parm.ramp.a;
|
|
|
|
part.live -= dT;
|
|
|
|
|
|
|
|
particles[ind] = part;
|
|
|
|
}
|