#define TAU 6.283185307179586
#define phi3 vec3(0.0, 2.0943951023931953, 4.1887902047863905)
#define gamma vec3(2.2)
#define igamma vec3(0.454545)

vec3 florp(float a, float p) {
    // this one maps the color
    // a = brightness
    // p = mushrooms
    float b = clamp(2.*a - 1.,0.,1.);
    b *= b; b *= b; b *= b;
    vec3 res = pow(vec3(2.*a - a * a, a * a, b), gamma); // sRGB stands for stupid RGB
    vec3 f = (1. + sin(phi3 + p)) * 0.333333333;
    return pow(res.rgb * f.x + res.gbr * f.y + res.bgr * f.z, igamma);
}

float onk(vec2 uv, float t) {
    // this one makes a wobbly function over t
    // ranged -1 .. 1
    float bx = uv.x * -3.13 + 2.04 * sin(uv.y * -2.3 + 1.3 * t) - 0.5* t;
    float by = uv.y * 4.17 - 1.73 * sin(uv.x * 2.5 - 0.7 * t) + 0.9 * t;
    return .5 * (sin(bx) + sin(by));
}

float unk(vec2 uv, float t) {
    // this one ALSO makes a wobbly function over t
    // ranged 0 .. 1
    float cx = uv.x * 2.23 - 3.33 * sin(uv.y * -1.3 + 0.3 * t) - 0.4* t;
    float cy = uv.y * -1.41 + 3.15 * sin(uv.x * 1.5 + 0.4 * t) + 0.1 * t;
    return .5 + .25 * (sin(cx) + sin(cy));
}

const vec2 cos_plz = vec2(0, 0.25); // cos ur face is 15 mins late
const vec2 flap = vec2(1., -1.);    // flap to flip not flop

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Normalized pixel coordinates (from 0 to 1) (??)
    // this is how to get the pixels straight
    vec2 aspect = iResolution.xy / iResolution.y;
    vec2 uv = (fragCoord/iResolution.xy - 0.5) * aspect;
    // and slightly bigger
    uv *= 1.5;
    float t = iTime * 0.5; // half speed is best speed
    vec2 ee = vec2(4.35, -5.33); // bonus numbers
    float c = unk(uv * vec2(0.43, -0.53), t); // weirdness amount
    vec2 trun = sin(cos_plz + c * 8. + t * 0.61);
    vec2 wp = uv + trun;
    vec2 wq = uv - trun;
    float lava = onk(wp, t) * (1. + onk((wq + ee * c) * 0.618, t * .7)); // left as exercise for the reader
    float hi = 1.000420 + .7 * c; // how high we are
    float a = smoothstep(-1., hi, lava); // brightness
    float hole = smoothstep(hi + .02, hi, lava); // no more brightness

    vec3 col = florp(a, c * 12. + 2.5 * t).bgr * hole; // put everything together

    // Output to screen
    fragColor = vec4(pow(col, vec3(1.)),1.0);
}
