vec3 palette( float t )
{
    vec3 a = vec3(0.878, 0.268, 0.658);
    vec3 b = vec3(0.916, 0.609, 0.456);
    vec3 c = vec3(0.497, 0.497, 0.379);
    vec3 d = vec3(2.406, 2.346, 0.036);
    return a + b*cos( 6.28318*(c*t+d) );
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = fragCoord/iResolution.xy;
    uv -= 0.5f;
    uv *= 2.0f;
    uv.x *= iResolution.x / iResolution.y;
    vec2 uv0 = uv;

    vec3 t = vec3(0.0f);

    for (float i=1.0f; i<=3.0f; i++) {
        uv = vec2(fract(uv));
        uv -= 0.5f;
        uv *= -0.5f + (length(uv0) + sin(iTime * 0.7) + cos(iTime * 0.56) + 0.5f);
        vec3 color = palette(length(uv * i * 0.3) + length(uv0) + iTime * 0.3f + i*0.4f);
        float d = abs(sin(length(uv * i * 0.7) * i + length(uv0) * 0.3f + iTime * 0.5f));
        d = pow(0.2 / d, 1.2f);
        d *= smoothstep(0.9f, 3.0f, i);
        d *= smoothstep(1.0f, 2.0f, 2.0f - length(uv0));
        t += color * d;
    }

    // Output to screen
    fragColor = vec4(vec3(t), 1.0);
}
