Forked from "Basic Mandelbrot" by llemarie. Edge detection test
Log in to post a comment.
#version 300 es #define PIXEL 1. / iResolution.y * 2. precision highp float; // Forked from "Basic Mandelbrot" by llemarie // https://oneshader.net/shader/b46e4cd625 uniform float iTime; uniform float iLoop; uniform vec2 iResolution; out vec4 fragColor; uniform float m_scale; // value=-1, min = -1, max = 14, step = 0.001 uniform float offset_x; // value = 0.5, min = -2, max = 2, step = 0.0001 uniform float offset_y; // value = 0, min = -2, max = 2, step = 0.0001 uniform float offset_x_f; // value = 0, min = -2, max = 2, step = 0.0001 uniform float offset_y_f; // value = 0, min = -2, max = 2, step = 0.0001 uniform float max_iterations; // value=60, min=1, max=1000, step=1 float mandelbrot(vec2 pos) { vec2 c = pos; vec2 z = vec2(0.); float iterations = 0.; while (z.x * z.x + z.y * z.y < 4.) { z = vec2(z.x * z.x - z.y * z.y + c.x, 2. * z.x * z.y + c.y); iterations++; if (iterations >= max_iterations) break; } return iterations; //return iterations; } vec3 HSVtoRGB(float h, float s, float v) { float r, g, b, f, p, q, t; int i; i = int(h * 6.); f = h * 6. - float(i); p = v * (1. - s); q = v * (1. - f * s); t = v * (1. - (1. - f) * s); switch (i % 6) { case 0: r = v, g = t, b = p; break; case 1: r = q, g = v, b = p; break; case 2: r = p, g = v, b = t; break; case 3: r = p, g = q, b = v; break; case 4: r = t, g = p, b = v; break; case 5: r = v, g = p, b = q; break; } return vec3(r, g, b); } vec3 mandelImage(vec2 pos){ float m_scale2 = pow(2., m_scale); vec2 off = vec2(offset_x, offset_y) + vec2(offset_x_f, offset_y_f) / 100.; vec2 m = vec2(pos.x / m_scale2 - off.x, pos.y / m_scale2 - off.y); float iterations = mandelbrot(m); float value = 1. - iterations / max_iterations; float h = iterations * 0.2; float s = (iterations < max_iterations) && iterations >= 2. ? 1. : 0.; float v = (iterations < max_iterations) ? 1. : 1.; vec3 col = HSVtoRGB(h, s, v); return col; } void main() { // Screen coordinate (from [-aspect, -1] to [aspect, 1]) vec2 pos = (2. * gl_FragCoord.xy - iResolution) / iResolution.y; vec3 col = -8. * mandelImage(pos); col += mandelImage(pos - vec2(-PIXEL)) + mandelImage(pos - vec2(-PIXEL, 0)) + mandelImage(pos - vec2(-PIXEL, PIXEL)) + mandelImage(pos - vec2(0, -PIXEL)) + mandelImage(pos - vec2(0, PIXEL)) + mandelImage(pos - vec2(PIXEL, -PIXEL)) + mandelImage(pos - vec2(PIXEL, 0)) + mandelImage(pos - vec2(PIXEL)); float l = 1. - (length(col) * 100.); fragColor = vec4(normalize(vec3(l)) * mandelImage(pos) * 2., 1.); }