#version 330 core
out vec4 FragColor;

uniform vec3 iResolution;
uniform float iTime;
uniform float uAlpha;

void mainImage(out vec4 O, vec2 C)
{
    O = vec4(0.0);

    vec3 p;
    vec4 P;

    float i = 0.0;
    float d = 0.0;
    float z = 0.0;

    for (; ++i < 77.0; z += 0.6 * d)
    {
        p = z * normalize(vec3(C + C, 0.0) - iResolution.xyy);
        p.xy *= mat2(cos((p.z -= 0.5 * iTime) + vec4(0.0, 11.0, 33.0, 0.0)));
        P = 1.0 + sin(5.0 * p.x + p.z + vec4(2.0, 1.0, 0.0, 2.0));
        d = abs(length(fract(p) - 0.5) - 0.5) + 1e-3;
        O += P.w / d * P;
    }

    O = tanh(O / 2e4);
    O.a *= uAlpha;
}

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