summaryrefslogtreecommitdiffstats
path: root/tests/manual/compute-manual/particles.comp
blob: b05e49c1d2a64f2a06bd078d5b3eb7c64869bbd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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;
}