summaryrefslogtreecommitdiffstats
path: root/tests/manual/compute-particles/shaders/gl43
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/compute-particles/shaders/gl43')
-rw-r--r--tests/manual/compute-particles/shaders/gl43/particles.comp41
-rw-r--r--tests/manual/compute-particles/shaders/gl43/particles.frag33
-rw-r--r--tests/manual/compute-particles/shaders/gl43/particles.vert27
3 files changed, 101 insertions, 0 deletions
diff --git a/tests/manual/compute-particles/shaders/gl43/particles.comp b/tests/manual/compute-particles/shaders/gl43/particles.comp
new file mode 100644
index 000000000..af993bbe2
--- /dev/null
+++ b/tests/manual/compute-particles/shaders/gl43/particles.comp
@@ -0,0 +1,41 @@
+#version 430 core
+
+uniform float particleStep;
+uniform float finalCollisionFactor;
+
+layout (local_size_x = 1024) in;
+
+struct ParticleData
+{
+ vec4 position;
+ vec4 direction;
+ 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 + 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;
+}
diff --git a/tests/manual/compute-particles/shaders/gl43/particles.frag b/tests/manual/compute-particles/shaders/gl43/particles.frag
new file mode 100644
index 000000000..3f11b9868
--- /dev/null
+++ b/tests/manual/compute-particles/shaders/gl43/particles.frag
@@ -0,0 +1,33 @@
+#version 430 core
+
+out vec4 color;
+
+in VertexBlock
+{
+ flat vec3 color;
+ vec3 pos;
+ vec3 normal;
+} frag_in;
+
+const vec4 lightPosition = vec4(0.0, 0.0, 0.0, 0.0);
+const vec3 lightIntensity = vec3(1.0, 1.0, 1.0);
+const vec3 ka = vec3(0.1, 0.1, 0.1);
+const vec3 ks = vec3(0.8, 0.8, 0.8);
+const float shininess = 50.0;
+
+vec3 ads()
+{
+ vec3 n = normalize( frag_in.normal);
+ vec3 s = normalize( vec3(lightPosition) - frag_in.pos );
+ vec3 v = normalize( -frag_in.pos );
+ vec3 h = normalize( v + s );
+ return lightIntensity * (ka +
+ frag_in.color * max( dot(s, frag_in.normal ), 0.0 ) +
+ ks * pow( max( dot( h, n ), 0.0 ), shininess ) );
+}
+
+
+void main(void)
+{
+ color = vec4(ads(), 1.0);
+}
diff --git a/tests/manual/compute-particles/shaders/gl43/particles.vert b/tests/manual/compute-particles/shaders/gl43/particles.vert
new file mode 100644
index 000000000..5f2da2a00
--- /dev/null
+++ b/tests/manual/compute-particles/shaders/gl43/particles.vert
@@ -0,0 +1,27 @@
+#version 430 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+
+in vec3 particlePosition;
+in vec3 particleColor;
+
+out VertexBlock
+{
+ flat vec3 color;
+ vec3 pos;
+ vec3 normal;
+} v_out;
+
+uniform mat4 mvp;
+uniform mat3 modelViewNormal;
+uniform mat4 modelView;
+
+void main(void)
+{
+ vec4 pos = vec4(vertexPosition.xyz, 1.0) + vec4(particlePosition, 0.0);
+ gl_Position = mvp * pos;
+ v_out.pos = vec4(modelView * pos).xyz;
+ v_out.normal = normalize(modelViewNormal * vertexNormal);
+ v_out.color = mix(particleColor * 0.2, particleColor, smoothstep(0.5, 0.8, abs(v_out.normal).z));
+}