0.00
60.0 fps

Infinite Mandelbrot Zoom

? infinite ?

Log in to post a comment.

#version 300 es
#define pi 3.1415926
precision highp float;

uniform float iTime;
uniform vec2  iResolution;

out vec4 fragColor;

vec2 vpow2(vec2 v){
    return vec2(v.x * v.x - v.y * v.y, 2. * v.x * v.y);
}

vec2 rv(vec2 v, float r){
    float a = atan(v.y, v.x);
    a += r;
    return vec2(cos(a), sin(a)) * length(v);
}

float itr(vec2 c, vec2 z){
    int i = 0;
    
    while(length(z) < 8192. && i < 512){
        z = vpow2(z) + c;
        i++;
    }
    
    return float(i) + 1. - log(log(length(z))) / log(2.);
}

vec3 fcol(float it){
    if(it < 512.){
        return vec3(.5 + .5 * sin(it / 32.), .5 + .5 * sin(it / 48.), .5 + .5 * sin(it / 64.));
    }
    else{
        return vec3(0., 0., 0.);
    }
}

void main() {
    // Screen coordinate (from [-aspect, -1] to [aspect, 1])
    vec2 q   = (2. * gl_FragCoord.xy - iResolution) / iResolution.y;
    
    float mzoom = 1.e5;
    float ztime = log(mzoom) / log(2.);
    float zoom = pow(2., mod(iTime, ztime));
    float zphase = mod(iTime / ztime, 1.);
    float r = (4. * pi - 4.04) * zphase;
    
    vec2 fractalCoord = vec2(-0.13791936640142570099292214925261, -0.88460568100304538057472153704150);
    vec2 c = rv(q * (mzoom / 1.e5) / zoom, r) + fractalCoord;
    vec2 c2 = rv(q * mzoom / zoom, r + 4.04) + fractalCoord;
    vec2 z = vec2(0., 0.);
    
    float it = itr(c, z);
    float it2 = itr(c2, z);
    
    // Pixel color
    vec3 col;
    vec3 col2;
    float w = pow(zphase, 0.9);
    col = fcol(it) * (1. - w) * clamp(1. - .2 * it2, 0., 1.);
    col += fcol(it2) * w;
    
    // Output
    fragColor = vec4(col, 1.);
}