summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/compute-particles/shaders/gl45/particles.comp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qt3d/compute-particles/shaders/gl45/particles.comp')
-rw-r--r--examples/qt3d/compute-particles/shaders/gl45/particles.comp43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/qt3d/compute-particles/shaders/gl45/particles.comp b/examples/qt3d/compute-particles/shaders/gl45/particles.comp
new file mode 100644
index 000000000..9a6f74cfc
--- /dev/null
+++ b/examples/qt3d/compute-particles/shaders/gl45/particles.comp
@@ -0,0 +1,43 @@
+#version 450 core
+
+layout(std140, binding=3) uniform particle_uniforms {
+ float particleStep;
+ float finalCollisionFactor;
+};
+
+layout (local_size_x = 1024) in;
+
+struct ParticleData
+{
+ vec4 position;
+ vec4 direction;
+ vec4 color;
+};
+
+// Particles from previouse frame
+layout (std430, binding = 5) 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 + distance traveled over step duration
+ currentParticle.position = currentParticle.position + currentParticle.direction * particleStep;
+
+ // Make acceleration more or less point toward the center of the scene
+ vec4 acceleration = normalize(vec4(0.0) - currentParticle.position) * finalCollisionFactor;
+
+ // New velocity = old velocity + acceleration over step duration
+ currentParticle.direction = currentParticle.direction + acceleration * particleStep;
+
+
+
+ // Save updated particle
+ data.particles[globalId] = currentParticle;
+}