summaryrefslogtreecommitdiffstats
path: root/examples/square-ring2.frag
diff options
context:
space:
mode:
Diffstat (limited to 'examples/square-ring2.frag')
-rw-r--r--examples/square-ring2.frag47
1 files changed, 47 insertions, 0 deletions
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);
+}