aboutsummaryrefslogtreecommitdiff
path: root/src/shader/code
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-25 23:47:27 +0200
committerAdrian Kummerlaender2018-05-25 23:48:59 +0200
commitf728e4c8d202de241673a13ce61570b6acb4bba7 (patch)
treea7e29c4319f0e6d667b98f359ddf089c0565c15a /src/shader/code
parent5157658ec0cc07d2c56c978ca010cbb78236439f (diff)
downloadcomputicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.gz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.bz2
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.lz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.xz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.zst
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.zip
Restructure source directory
Diffstat (limited to 'src/shader/code')
-rw-r--r--src/shader/code/compute.glsl62
-rw-r--r--src/shader/code/display_fragment.glsl15
-rw-r--r--src/shader/code/display_vertex.glsl12
-rw-r--r--src/shader/code/fragment.glsl5
-rw-r--r--src/shader/code/vertex.glsl8
5 files changed, 102 insertions, 0 deletions
diff --git a/src/shader/code/compute.glsl b/src/shader/code/compute.glsl
new file mode 100644
index 0000000..eaf5579
--- /dev/null
+++ b/src/shader/code/compute.glsl
@@ -0,0 +1,62 @@
+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;
+
+// ODE solver
+
+vec2 f(vec2); // field definition is to be appended
+
+vec2 explicitEuler(float h, vec2 v) {
+ return v + h * f(v);
+}
+
+vec2 classicalRungeKutta(float h, vec2 v) {
+ const vec2 k1 = f(v);
+ const vec2 k2 = f(v + h/2. * k1);
+ const vec2 k3 = f(v + h/2. * k2);
+ const vec2 k4 = f(v + h * k3);
+
+ return v + h * (1./6.*k1 + 1./3.*k2 + 1./3.*k3 + 1./6.*k4);
+}
+
+// pseudo random numbers for particle placement
+
+float rand(vec2 v){
+ return fract(sin(dot(v, vec2(12.9898,78.233))) * 43758.5453);
+}
+
+float mapUnitToWorldX(float s) {
+ return -(world.x/2.) + s * world.x;
+}
+
+float mapUnitToWorldY(float s) {
+ return -(world.y/2.) + s * world.y;
+}
+
+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() {
+ const uint i = 3*gl_GlobalInvocationID.x;
+ const vec2 v = vec2(data[i+0], data[i+1]);
+ const vec2 w = classicalRungeKutta(0.01, v);
+
+ if ( data[i+2] < 5. && insideWorld(v) ) {
+ data[i+0] = w.x;
+ data[i+1] = w.y;
+ data[i+2] += 0.01;
+ } else {
+ data[i+0] = mapUnitToWorldX(rand(v));
+ data[i+1] = mapUnitToWorldY(rand(w));
+ data[i+2] = rand(v+w) * 5.;
+ }
+}
+)";
diff --git a/src/shader/code/display_fragment.glsl b/src/shader/code/display_fragment.glsl
new file mode 100644
index 0000000..b731ebe
--- /dev/null
+++ b/src/shader/code/display_fragment.glsl
@@ -0,0 +1,15 @@
+static const std::string DISPLAY_FRAGMENT_SHADER_CODE = R"(
+#version 460
+
+out vec4 FragColor;
+in vec2 TexCoords;
+
+uniform sampler2D screen_textures[64];
+uniform int screen_textures_size;
+
+void main() {
+ for ( int i = 0; i < screen_textures_size; ++i ) {
+ FragColor += (1.0 - i*1.0/screen_textures_size) * texture(screen_textures[i], TexCoords);
+ }
+}
+)";
diff --git a/src/shader/code/display_vertex.glsl b/src/shader/code/display_vertex.glsl
new file mode 100644
index 0000000..60bbfc7
--- /dev/null
+++ b/src/shader/code/display_vertex.glsl
@@ -0,0 +1,12 @@
+static const std::string DISPLAY_VERTEX_SHADER_CODE = R"(
+#version 330 core
+
+layout (location = 0) in vec2 screen_vertex;
+layout (location = 1) in vec2 texture_vertex;
+out vec2 TexCoords;
+
+void main() {
+ gl_Position = vec4(screen_vertex, 0.0, 1.0);
+ TexCoords = texture_vertex;
+}
+)";
diff --git a/src/shader/code/fragment.glsl b/src/shader/code/fragment.glsl
new file mode 100644
index 0000000..37e18bd
--- /dev/null
+++ b/src/shader/code/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/code/vertex.glsl b/src/shader/code/vertex.glsl
new file mode 100644
index 0000000..4c307d8
--- /dev/null
+++ b/src/shader/code/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(1., 0., 0., 0.);
+}
+)";