summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-02-02 05:35:00 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-02-02 05:48:42 +0100
commit4b03ea2a9c8b66bad704e9cef026801786aa3517 (patch)
tree7456da1e2c37f65213afaaec6a31fe31089595a5
parent984b02a874d77d9b79a80cc09f6b9b56dd12ca31 (diff)
downloadglslview-4b03ea2a9c8b66bad704e9cef026801786aa3517.tar
glslview-4b03ea2a9c8b66bad704e9cef026801786aa3517.zip
Add two more examples
-rw-r--r--examples/checkers.frag39
-rw-r--r--examples/symmetry.frag41
2 files changed, 80 insertions, 0 deletions
diff --git a/examples/checkers.frag b/examples/checkers.frag
new file mode 100644
index 0000000..c9b56ff
--- /dev/null
+++ b/examples/checkers.frag
@@ -0,0 +1,39 @@
+#version 330
+
+out vec4 fragColor;
+
+uniform vec2 res;
+uniform float time;
+
+const float sharpness = 300;
+
+const float PI = 3.14159265358979323846;
+
+
+mat2 rot(float a) {
+ return mat2(
+ cos(a), -sin(a),
+ sin(a), cos(a)
+ );
+}
+
+void main(void) {
+ vec2 m = res/2;
+ float s = min(m.x, m.y);
+ vec2 p = (gl_FragCoord.xy - m) / s;
+
+ float repeat = 8.0;
+ float time_mod = mod(time / 200, repeat);
+ float w = 20 * pow(2, time_mod);
+
+ float f = time_mod / repeat;
+ vec2 pr = p * rot(f * PI/2);
+
+ float tp = mod(floor(log2(abs(pr.x/w)) + floor(log2(abs(pr.y/w)))), 2);
+
+ float darken = min(min(abs(pr.x), abs(pr.y)) / 0.01, 1.0);
+
+ float scene = tp * darken;
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}
diff --git a/examples/symmetry.frag b/examples/symmetry.frag
new file mode 100644
index 0000000..0fb9cd1
--- /dev/null
+++ b/examples/symmetry.frag
@@ -0,0 +1,41 @@
+#version 330
+
+out vec4 fragColor;
+
+uniform vec2 res;
+uniform float time;
+
+const float sharpness = 300;
+
+const float PI = 3.14159265358979323846;
+
+
+mat2 rot(float a) {
+ return mat2(
+ cos(a), -sin(a),
+ sin(a), cos(a)
+ );
+}
+
+float square(vec2 m, float a, float r, vec2 p) {
+ vec2 diff = abs((m - p) * rot(r));
+ float d = max(diff.x, diff.y);
+
+ return clamp((a - d)*sharpness, 0.0, 1.0);
+}
+
+void main(void) {
+ vec2 m = res/2;
+ float s = min(m.x, m.y);
+ vec2 p = (gl_FragCoord.xy - m) / s;
+
+ float scene = 0;
+
+ int n = 24;
+ for (int i = 0; i < n; i++) {
+ float c = square(vec2(0.5, 0) * rot(PI/2*(4.0*i/n)) * vec2(1, 1), 0.3, PI/2*(24.0*i/n - time/800), p);
+ scene = abs(scene - c);
+ }
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}