#version 330 core

in vec2 vUV;
out vec4 FragColor;

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

const float PI = 4.0 * atan(1.0);
const float TAU = 2.0 * PI;

float b( in vec2 p, in float w, in float r )
{
    p = abs(p);
    return length(p - min(p.x + p.y, w) * 0.5) - r;
}

void mainImage( out vec4 O, in vec2 F )
{
    vec2 R = iResolution.xy;
    vec2 u = (F + F - R) / R.y;
    vec2 u0 = u;
    float i = 0.0;
    float l = length(u);

    // initialize O to zero
    O = vec4(0.0);

    for( O *= i; i++ < 3.0; 
        O += pow(0.04 / abs(tan(8.0 * ( length(u = fract(u * 1.2) - 0.5) + b(u, 1.0, 2.0) / exp(l) ) + iTime )), 1.2) * (1.0 + cos(6.0 * ( l + (i + iTime) * 0.4 + vec4(0.26,0.4,0.56,0) )) )
    );
}

void main()
{
    vec2 fragCoord = vUV * iResolution.xy;
    vec4 outCol;
    mainImage(outCol, fragCoord);
    outCol.a *= uAlpha;
    FragColor = outCol;
}
