mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-12-11 13:21:10 +00:00
8228146ac0
I realized I'd need to get the particle counts out to the draw commands somehow, and this seemed to be the most natural way.
60 lines
1.2 KiB
Text
60 lines
1.2 KiB
Text
#version 450
|
|
|
|
layout (local_size_x = 32, local_size_y = 32) in;
|
|
|
|
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[];
|
|
};
|
|
|
|
//doubles as VkDrawIndirectCommand
|
|
layout(std140, set = 0, binding = 2) buffer ParticleSystem {
|
|
uint vertexCount;
|
|
uint particleCount; //instanceCount
|
|
uint firstVertex;
|
|
uint firstInstance;
|
|
};
|
|
|
|
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;
|
|
}
|