#version 430 core

uniform float time;

layout (local_size_x = 1024) in;

struct ParticleData
{
    vec4 position;
    vec4 color;
};

// Particles from previouse frame
layout (std430, binding = 0) coherent buffer Particles
{
    ParticleData particles[];
} data;

void main(void)
{
    uint globalId = gl_GlobalInvocationID.x;

    // Retrieve current particle from previous frame
    ParticleData currentParticle = data.particles[globalId];

    // New position = old position + sin(time)
    currentParticle.position = currentParticle.position + vec4(0.0, 1.0, 0.0, 0.0) * sin(time * globalId);

    // Save updated particle
    data.particles[globalId] = currentParticle;
}
