#version 330 core
out vec4 FragColor;
in vec2 vUV;
uniform vec3 iResolution;
uniform float iTime;
uniform float uAlpha;

// ported minimal mainImage
void mainImage(out vec4 o, vec2 u) {
    float i, d, s;
    vec3 p,r = iResolution,
         a = cos(vec3(2,3,1)+iTime);
    for(o*=i; i++<1e2;
        o += 6.*vec4(1,2,8,0)+(1.+cos(i*.6+vec4(2,1,0,0)))/s
          +  min(vec4(7,2,2,0)*d, 2e2)
    )
        p = vec3((u+u-r.xy)/r.y * d, d-6.),
        p = abs(a*dot(a,p)-cross(a,p)),
        s = max(p.x, max(p.y, p.z)) - .8 - .5*sin(sin(iTime/2.)+iTime/3.),
        p = abs(fract(p/s)*s - s*.5),
        s = min(max(p.x, p.y), min(max(p.x, p.z),max(p.y, p.z))) - s/12., 
        s = .001+.4*abs(s),
        d += s;
    o = tanh(o*o/6e8);
}

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