summaryrefslogtreecommitdiffstats
path: root/examples/squares.frag
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-02-01 14:03:21 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-02-01 14:03:21 +0100
commit9d3cdc7f5ee96c3b2a9342e44b62102f5b05be3b (patch)
tree25493bd35211830753cfaa52283d5e040f782111 /examples/squares.frag
parent213e7046d1ceca7591dc6d66e68a227421a508c5 (diff)
downloadglslview-9d3cdc7f5ee96c3b2a9342e44b62102f5b05be3b.tar
glslview-9d3cdc7f5ee96c3b2a9342e44b62102f5b05be3b.zip
Add glslwrite tool and some examples
Diffstat (limited to 'examples/squares.frag')
-rw-r--r--examples/squares.frag42
1 files changed, 42 insertions, 0 deletions
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);
+}