
float luminance(in vec3 srgb)
{
    return dot(srgb, vec3(0.2126, 0.7152, 0.0722));
}

float falloff(in float lum)
{
    float sq = lum * lum;
    return sq * sq - 2.0 * sq + 1.0;
}

vec3 mix_with_noise(inout vec3 col, in vec2 uv)
{
    vec3 noise = texture(iChannel1, uv).rgb;

    float fac = falloff(luminance(col) * 2.0 - 1.0);

    return mix(col, noise, fac * 0.5) * pow(noise, vec3(0.2));
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord/iResolution.xy;

    vec3 imageCol = texture(iChannel0, uv).rgb;

    vec3 col = pow(imageCol * mix_with_noise(imageCol, uv * 2.0), vec3(0.5));

    fragColor = vec4(col, 1.0);
}
