#version 440 core
out vec4 FragColor;

in vec2 TexCoords;

uniform sampler2D scene;
uniform sampler2D bloomBlur;
uniform bool bloom;
uniform float exposure;
uniform bool invertColors; // New uniform for color inversion
uniform float gamma;


void main()
{             
    //const float gamma = 2.2;
    vec3 hdrColor = texture(scene, TexCoords).rgb;      
    vec3 bloomColor = texture(bloomBlur, TexCoords).rgb;
    if(bloom)
        hdrColor += bloomColor; // additive blending
    // tone mapping
    vec3 result = vec3(1.0) - exp(-hdrColor * exposure);

    result = pow(result, vec3(1.0 / gamma));

    // color inversion if the uniform is set to true
    if(invertColors)
    {
        // convert to grayscale
        float gray = dot(result, vec3(0.299, 0.587, 0.114));
        // apply green tint
        gray *= 5.f; // Adjust this factor as needed
        result = vec3(0.0, gray, 0.0);
        // enhance contrast (optional)
        result = pow(result, vec3(2.0));
    }
        

    FragColor = vec4(result, 1.0);
}