| 7 |
| vec2 velocity; |
| 8 | float time; |
| 9 | float duration; |
| 10 | }; |
| 11 |
| 12 | layout(std430, binding = 0) buffer ParticleBuffer { |
| 13 | Particle particles[]; |
| 14 | }; |
| 15 |
| 16 | uniform float deltaTime; |
| 17 | uniform vec2 size; |
| 18 |
| 19 | void main() { |
| 20 | uint id = gl_GlobalInvocationID.x; |
| 21 |
| 22 | if (id >= uint(particles.length())) |
| 23 | return; |
| 24 |
| 25 | Particle p = particles[id]; |
| 26 |
| 27 | p.time += deltaTime * p.duration; |
| 28 | if (p.time >= 1.0) { |
| 29 | p.time = 0.0; |
| 30 | } |
| 31 |
| 32 | p.velocity += vec2(.5, .5); |
| 33 | p.velocity *= .99; |
| 34 |
| 35 | p.position += p.velocity; |
| 36 | p.position = fract(p.position / size) * size; |
| 37 |
| 38 | particles[id] = p; |
| 39 | } |
| 40 |