summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/polygon.frag54
-rw-r--r--examples/snail.frag41
-rw-r--r--examples/square-in-circle.frag66
-rw-r--r--examples/square-in-square.frag74
-rw-r--r--examples/square-ring.frag41
-rw-r--r--examples/square-ring2.frag47
-rw-r--r--examples/squares.frag42
-rw-r--r--examples/supersnail.frag37
-rw-r--r--examples/torus.frag41
9 files changed, 443 insertions, 0 deletions
diff --git a/examples/polygon.frag b/examples/polygon.frag
new file mode 100644
index 0000000..20d5cdc
--- /dev/null
+++ b/examples/polygon.frag
@@ -0,0 +1,54 @@
+#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 poly(float n, vec2 m, float r, float rt, vec2 p) {
+ vec2 diff = (m - p) * rot(rt);
+ float d = length(diff);
+ float alpha = PI / n;
+ float gamma = mod(abs(atan(diff.x, diff.y)), alpha*2);
+
+ if (gamma > alpha)
+ gamma -= 2*alpha;
+
+ float r2 = r * cos(alpha) / cos(gamma);
+
+ return clamp((r2 - d)*sharpness, 0.0, 1.0);
+}
+
+float poly_d(float n, vec2 m, float r, float rt, vec2 p) {
+ return poly(n, m, r, rt, p) - poly(n, m, r - 1/sharpness, rt, p);
+}
+
+void main(void) {
+ vec2 m = res/2;
+ float s = min(m.x, m.y);
+ vec2 p = (gl_FragCoord.xy - m) / s;
+
+ float scene = 0;
+
+ float c;
+
+ c = poly_d(5 - 3*cos(time/1000), vec2(0, 0), 0.5, PI * time/1000, p);
+ scene = abs(scene - c);
+
+ c = poly_d(5 - 3*cos(time/1000), vec2(0, 0), 0.5, -PI * time/1000, p);
+ scene = abs(scene - c);
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}
diff --git a/examples/snail.frag b/examples/snail.frag
new file mode 100644
index 0000000..491c53a
--- /dev/null
+++ b/examples/snail.frag
@@ -0,0 +1,41 @@
+#version 330
+
+out vec4 fragColor;
+
+uniform vec2 res;
+uniform float time;
+
+const float sharpness = 300;
+
+mat2 rot(float a) {
+ return mat2(
+ cos(a), -sin(a),
+ sin(a), cos(a)
+ );
+}
+
+float circle(vec2 m, float r, vec2 p) {
+ vec2 diff = m - p;
+ float d = sqrt(dot(diff, diff));
+
+ return clamp((r - d)*sharpness, 0.0, 1.0);
+}
+
+float circle_d(vec2 m, float r, vec2 p) {
+ return circle(m, r, p) - circle(m, r - 1/sharpness, p);
+}
+
+void main(void) {
+ vec2 m = res/2;
+ float s = min(m.x, m.y);
+ vec2 p = (gl_FragCoord.xy - m) / s;
+
+ float scene = 0;
+
+ for (int i = 1; i <= 50; i++) {
+ float c = circle_d(vec2(0.5, 0) * rot(time/500/i), 0.1 + 0.005*i, p);
+ scene = abs(scene - c);
+ }
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}
diff --git a/examples/square-in-circle.frag b/examples/square-in-circle.frag
new file mode 100644
index 0000000..ad6c615
--- /dev/null
+++ b/examples/square-in-circle.frag
@@ -0,0 +1,66 @@
+#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 circle(vec2 m, float r, vec2 p) {
+ vec2 diff = m - p;
+ float d = sqrt(dot(diff, diff));
+
+ return clamp((r - d)*sharpness, 0.0, 1.0);
+}
+
+float circle_d(vec2 m, float r, vec2 p) {
+ return circle(m, r, p) - circle(m, r - 1/sharpness, p);
+}
+
+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 = 20;
+ float b = 1;
+ float alpha = 0;
+ for (int i = 0; i < n; i++) {
+ float c;
+
+ c = circle_d(vec2(0, 0), b, p);
+ scene = abs(scene - c);
+
+ float delta = mod(time/5000, PI/2);
+ alpha = mod(alpha + delta, PI/2);
+ b /= sqrt(2);
+
+ c = square(vec2(0, 0), b, alpha, p);
+ scene = abs(scene - c);
+
+ c = square(vec2(0, 0), b, -alpha, p);
+ scene = abs(scene - c);
+ }
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}
diff --git a/examples/square-in-square.frag b/examples/square-in-square.frag
new file mode 100644
index 0000000..cc00388
--- /dev/null
+++ b/examples/square-in-square.frag
@@ -0,0 +1,74 @@
+#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 circle(vec2 m, float r, vec2 p) {
+ vec2 diff = m - p;
+ float d = sqrt(dot(diff, diff));
+
+ return clamp((r - d)*sharpness, 0.0, 1.0);
+}
+
+float circle_d(vec2 m, float r, vec2 p) {
+ return circle(m, r, p) - circle(m, r - 1/sharpness, p);
+}
+
+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);
+}
+
+float square_d(vec2 m, float a, float r, vec2 p) {
+ return square(m, a, r, p) - square(m, a - 1/sharpness, r, p);
+}
+
+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 = 20;
+ float b = 1;
+ float alpha = 0;
+ for (int i = 0; i < n; i++) {
+ float delta = mod(time/5000, PI/2);
+ alpha = mod(alpha + delta, PI/2);
+ b /= (sin(delta) + cos(delta));
+
+ float c = square(vec2(0, 0), b, alpha, p);
+ scene = abs(scene - c);
+ }
+
+
+ b = 1;
+ alpha = 0;
+ for (int i = 0; i < n; i++) {
+ float delta = mod(-time/5000, PI/2);
+ alpha = mod(alpha + delta, PI/2);
+ b /= (sin(delta) + cos(delta));
+
+ float c = square(vec2(0, 0), b, alpha, p);
+ scene = abs(scene - c);
+ }
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}
diff --git a/examples/square-ring.frag b/examples/square-ring.frag
new file mode 100644
index 0000000..1ef1c2c
--- /dev/null
+++ b/examples/square-ring.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 = 10;
+ for (int i = 1; i <= n; i++) {
+ float c = square(vec2(0, 0), 0.5, PI/2*i/n - time/500, p);
+ scene = abs(scene - c);
+ }
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}
diff --git a/examples/square-ring2.frag b/examples/square-ring2.frag
new file mode 100644
index 0000000..e90b633
--- /dev/null
+++ b/examples/square-ring2.frag
@@ -0,0 +1,47 @@
+#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 = 5;
+ for (int i = 1; i <= n; i++) {
+ float c = square(vec2(0, 0), 0.5, PI/2*i/n - time/3000, p);
+ scene = abs(scene - c);
+ }
+
+ n = 5;
+ for (int i = 1; i <= n; i++) {
+ float c = square(vec2(0, 0), 0.5, PI/2*i/n + time/3000, p);
+ scene = abs(scene - c);
+ }
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}
diff --git a/examples/squares.frag b/examples/squares.frag
new file mode 100644
index 0000000..fd5dc94
--- /dev/null
+++ b/examples/squares.frag
@@ -0,0 +1,42 @@
+#version 330
+
+out vec4 fragColor;
+
+uniform vec2 res;
+uniform float time;
+
+const float sharpness = 500;
+
+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 a = atan(p.x, p.y);
+
+ float x = mod(p.x, 0.1);
+ float y = mod(p.y, 0.1);
+
+ float scene = 0;
+
+ for (int i = 1; i <= 50; i++) {
+ float c = square(vec2(0.5, 0) * rot(time/500/i), 0.1 + 0.005*i, time/500/i + time/(100*i), p);
+ scene = abs(scene - c);
+ }
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}
diff --git a/examples/supersnail.frag b/examples/supersnail.frag
new file mode 100644
index 0000000..154652a
--- /dev/null
+++ b/examples/supersnail.frag
@@ -0,0 +1,37 @@
+#version 330
+
+out vec4 fragColor;
+
+uniform vec2 res;
+uniform float time;
+
+const float sharpness = 300;
+
+mat2 rot(float a) {
+ return mat2(
+ cos(a), -sin(a),
+ sin(a), cos(a)
+ );
+}
+
+float circle(vec2 m, float r, vec2 p) {
+ vec2 diff = m - p;
+ float d = sqrt(dot(diff, diff));
+
+ return clamp((r - 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;
+
+ for (int i = 1; i <= 100; i++) {
+ float c = circle(vec2(0.5, 0) * rot(time/200/i), 0.1 + 0.002*i, p);
+ scene = abs(scene - c);
+ }
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}
diff --git a/examples/torus.frag b/examples/torus.frag
new file mode 100644
index 0000000..9758e1d
--- /dev/null
+++ b/examples/torus.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 = 48;
+ for (int i = 1; i <= n; i++) {
+ float c = square(vec2(0.5, 0) * rot(PI/2*(time/8000 + 4.0*i/n)) * vec2(1, 0.5), 0.1, PI/2*(24.0*i/n - time/800), p);
+ scene = abs(scene - c);
+ }
+
+ fragColor = vec4(vec3(1, 1, 1) * scene, 1);
+}