aboutsummaryrefslogtreecommitdiff
path: root/src/shader
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader')
-rw-r--r--src/shader/compute.glsl34
-rw-r--r--src/shader/fragment.glsl5
-rw-r--r--src/shader/vertex.glsl8
3 files changed, 47 insertions, 0 deletions
diff --git a/src/shader/compute.glsl b/src/shader/compute.glsl
new file mode 100644
index 0000000..8b1deab
--- /dev/null
+++ b/src/shader/compute.glsl
@@ -0,0 +1,34 @@
+static const std::string COMPUTE_SHADER_CODE = R"(
+#version 430
+
+layout (local_size_x = 1) in;
+layout (std430, binding=1) buffer bufferA{ float data[]; };
+
+uniform vec2 world;
+
+float rand(vec2 co){
+ return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);
+}
+
+bool insideWorld(vec2 v) {
+ return v.x > -world.x/2.
+ && v.x < world.x/2.
+ && v.y > -world.y/2.
+ && v.y < world.y/2.;
+}
+
+void main() {
+ uint idx = 3*gl_GlobalInvocationID.x;
+ vec2 v = vec2(data[idx+0], data[idx+1]);
+
+ if ( data[idx+2] < 5. && insideWorld(v) ) {
+ data[idx+0] += 0.01 * cos(v.x*cos(v.y));
+ data[idx+1] += 0.01 * sin(v.x-v.y);
+ data[idx+2] += 0.01;
+ } else {
+ data[idx+0] = -(world.x/2.) + rand(vec2(data[idx+1], data[idx+0])) * world.x;
+ data[idx+1] = -(world.y/2.) + rand(vec2(data[idx+0], data[idx+1])) * world.y;
+ data[idx+2] = uint(rand(v) * 5.);
+ }
+}
+)";
diff --git a/src/shader/fragment.glsl b/src/shader/fragment.glsl
new file mode 100644
index 0000000..37e18bd
--- /dev/null
+++ b/src/shader/fragment.glsl
@@ -0,0 +1,5 @@
+static const std::string FRAGMENT_SHADER_CODE = R"(
+void main() {
+ gl_FragColor = gl_Color;
+}
+)";
diff --git a/src/shader/vertex.glsl b/src/shader/vertex.glsl
new file mode 100644
index 0000000..8ab6ccb
--- /dev/null
+++ b/src/shader/vertex.glsl
@@ -0,0 +1,8 @@
+static const std::string VERTEX_SHADER_CODE = R"(
+uniform mat4 MVP;
+
+void main() {
+ gl_Position = MVP * vec4(gl_Vertex.xy, 0.0, 1.0);
+ gl_FrontColor = vec4(max(1. - gl_Vertex.z/5., 0.1), 0., 0., 0.);
+}
+)";