(https://mathr.co.uk/misc/2016-11-20_bubble_tea.jpg) (https://mathr.co.uk/misc/2016-11-20_bubble_tea.jpg)
// Created: Sun Nov 20 06:09:53 2016
#include "Progressive2D.frag"
#include "Complex.frag"
#info Rational Mandelbrot or Julia with Distance Estimation and Atom Domains
#group Mandelbrot
uniform int Iterations; slider[10,200,5000]
uniform bool Julia; checkbox[false]
uniform float JuliaX; slider[-10,0,10]
uniform float JuliaY; slider[-10,0,10]
// dual complex numbers for automatic differentiation
vec4 mul(vec4 a, vec4 b) {
return vec4(cMul(a.xy, b.xy), cMul(a.xy, b.zw) + cMul(a.zw, b.xy));
}
vec4 div(vec4 a, vec4 b) {
return vec4(cDiv(a.xy, b.xy), cDiv(cMul(a.zw, b.xy) - cMul(a.xy, b.zw), cMul(b.xy, b.xy)));
}
// from http://gamedev.stackexchange.com/a/59808
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
vec3 color(vec2 p) {
// critical point
/*
vec2 z0 = vec2(0.0);
*/
vec2 z0 = vec2(pow(0.009/2.0, 1.0/3.0), 0.0);
// initialisation
vec4 c = Julia ? vec4(JuliaX, JuliaY, 0.0, 0.0) : vec4(p, dFdx(p));
vec4 z = Julia ? vec4(p, dFdx(p)) : vec4(z0, 1.0, 0.0);
int i = 0;
int j = 0;
float minl = 1.0 / 0.0;
// main loop
for (i = 0; i < Iterations; i++) {
// iteration formula
/*
z = mul(z, z) + c;
*/
z = mul(z, z) + div(vec4(0.009, 0.0, 0.0, 0.0), z) + c;
// atom domains
float l = dot(z.xy,z.xy);
if (l < minl) {
j = i;
minl = l;
}
// bailout
if (l > 1.0e10) break;
}
if (i == Iterations) return vec3(0.0, 0.0, 0.0);
// distance estimator shading with atomain colour
float r = length(z.xy);
float dr = length(z.zw);
float de = 2.0 * r * log2(r) / dr;
return vec3(tanh(clamp(de, 0.0, 4.0))) * hsv2rgb(vec3(float(j) * 0.05, 0.5, 1.0));
}
#preset Default
Gamma = 2.08335
Brightness = 1
Contrast = 1
Saturation = 1
Center = 0.00018,-0.1439975
Zoom = 132
ToneMapping = 1
Exposure = 1
AARange = 2
AAExp = 1
GaussianAA = true
Iterations = 5000
JuliaX = -1.059908
JuliaY = -0.0460829
Julia = true
#endpreset
Inspired by https://en.wikibooks.org/wiki/Pictures_of_Julia_and_Mandelbrot_Sets/Computer_programs