uniform sampler2D texture;

// vec4 Desaturate(vec3 color, float Desaturation)
// {
//     vec3 grayXfer = vec3(0.3, 0.59, 0.11);
//     vec3 gray = vec3(dot(grayXfer, color));
//     return vec4(mix(color, gray, Desaturation), 1.0);
// }


// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150%
vec3 ContrastSaturationBrightness(vec3 color, float brt, float sat, float con)
{
    // Increase or decrease theese values to adjust r, g and b color channels seperately
    const float AvgLumR = 0.5;
    const float AvgLumG = 0.5;
    const float AvgLumB = 0.5;

    const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);

    vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);
    vec3 brtColor = color * brt;
    vec3 intensity = vec3(dot(brtColor, LumCoeff));
    vec3 satColor = mix(intensity, brtColor, sat);
    vec3 conColor = mix(AvgLumin, satColor, con);
    return conColor;
}

void main(void)
{
    vec4 color = texture2D(texture, gl_TexCoord[0].st);
    gl_FragColor = vec4(ContrastSaturationBrightness(color.rgb, 0.7, 0.7, 1.0), color.a);
}
