//The Bonk Image Post-Processing PIXEL

uniform sampler2D colorMap;
uniform vec4 ambientColor;
uniform float brightness;
uniform float saturation;
uniform float contrast;

// 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()
{
	vec4 color = texture2D(colorMap, gl_TexCoord[0].st);
	color.xyz = ContrastSaturationBrightness(color.xyz, brightness, saturation, contrast);
	gl_FragColor = color * ambientColor;
}
