| 1 |
#version 430 core |
| 2 |
|
| 3 |
uniform float time; |
| 4 |
|
| 5 |
layout (local_size_x = 1024) in; |
| 6 |
|
| 7 |
struct ParticleData |
| 8 |
{ |
| 9 |
vec4 position; |
| 10 |
vec4 color; |
| 11 |
}; |
| 12 |
|
| 13 |
// Particles from previouse frame |
| 14 |
layout (std430, binding = 0) coherent buffer Particles |
| 15 |
{ |
| 16 |
ParticleData particles[]; |
| 17 |
} data; |
| 18 |
|
| 19 |
void main(void) |
| 20 |
{ |
| 21 |
uint globalId = gl_GlobalInvocationID.x; |
| 22 |
|
| 23 |
// Retrieve current particle from previous frame |
| 24 |
ParticleData currentParticle = data.particles[globalId]; |
| 25 |
|
| 26 |
// New position = old position + sin(time) |
| 27 |
currentParticle.position = currentParticle.position + vec4(0.0, 1.0, 0.0, 0.0) * sin(time * globalId); |
| 28 |
|
| 29 |
// Save updated particle |
| 30 |
data.particles[globalId] = currentParticle; |
| 31 |
} |