#version 330 core

uniform vec3 iResolution;
uniform float iTime;
uniform sampler2D iChannel0;

out vec4 FragColor;

// tinkering... i like the log polar stuff by @YoheiNishitsuji
// but too lazy to learn a new coord system atm :D
// inspo: https://fragcoord.xyz/s/cbbga4b9

void mainImage(out vec4 o, in vec2 fragCoord) {
    vec2 u = fragCoord;
    float i=0.0, d=0.0, s=0.0;
    float t = iTime/3.5;

    vec3 p = iResolution;
    vec3 D = normalize(vec3((u + u - p.xy)/p.y, .4));
    mat2 r = mat2(cos(t/2.+vec4(0,33,11,0)));

    for(o=vec4(0); i++<1e2;) {
        p = D *d; p.z -= 1e1;
        p.yz *= r;
        for(s = .01; s < 3.; s += s )
            p += cos(t-p.yzx/1e1)*.6,
            p -= abs(dot(sin(.03*p.z+t+p / s / 3.2), vec3(s)));
        p.xy /= 4.;
        d += s = .05+.4*abs(length(p)-3e1);
        o += vec4(4.1,2.3,1,0)/s*i + 2e1;
    }

    o = mix(o/=3e4, o.zyxw, smoothstep(.2, 1., length(u)/2.));
    o = 1.-exp(-o*o*o);
    o = pow(o, vec4(1./2.2));
}

void main()
{
    mainImage(FragColor, gl_FragCoord.xy);
}
