summaryrefslogtreecommitdiff
path: root/mandelbrot.glsl
diff options
context:
space:
mode:
authordavidovski <david@sendula.com>2021-04-23 09:26:10 +0100
committerdavidovski <david@sendula.com>2021-04-23 09:26:10 +0100
commitb5e820f7c361842aca1b53332f9e27b67eff18d4 (patch)
tree045045396877766245e170dd72fed395b65f3a01 /mandelbrot.glsl
initial commit
Diffstat (limited to 'mandelbrot.glsl')
-rw-r--r--mandelbrot.glsl45
1 files changed, 45 insertions, 0 deletions
diff --git a/mandelbrot.glsl b/mandelbrot.glsl
new file mode 100644
index 0000000..d3d0ee2
--- /dev/null
+++ b/mandelbrot.glsl
@@ -0,0 +1,45 @@
+#version 100
+precision highp float;
+
+uniform vec2 resolution;
+uniform vec2 location;
+uniform double zoom;
+
+uniform int max;
+
+vec2 compsquare(vec2 z) {
+ float temp = z.x;
+ z.x = z.x * z.x - z.y * z.y;
+ z.y = 2.0 * temp * z.y;
+ return z;
+}
+
+vec3 hsv2rgb(vec3 hue){
+ vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
+ vec3 p = abs(fract(hue.xxx + K.xyz) * 6.0 - K.www);
+ return hue.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), hue.y);
+}
+
+vec3 mandelbort(vec2 point){
+ vec2 z = vec2(0.0);
+ float iters = 0.0;
+ for (iters = 0.0; iters < float(max); ++iters)
+ {
+ z = compsquare(z) + point;
+ if(dot(z, z) > 4.0) break;
+ }
+ float hue = iters / float(max);
+ if(hue > 0.98) return vec3(0.0);
+ return hsv2rgb(vec3(hue, 1.0, 1.0));
+}
+
+void main()
+{
+ vec2 uv = gl_FragCoord.xy / resolution;
+ uv.x *= resolution.x / resolution.y;
+ uv -= vec2(0.7, 0.5);
+ uv *= zoom;
+ uv -= location;
+
+ gl_FragColor = vec4(mandelbort(uv), 1.0);
+}