#version 330

in vec2 fragTexCoord;
uniform sampler2D texture0;
uniform float texelW;
uniform float threshold;

out vec4 finalColor;

void main() {
    vec3 bloom = vec3(0.0);
    float total = 0.0;
    for (int i = -24; i <= 24; i++) {
        float w = exp(-float(i * i) * 0.004);
        vec3 s = texture(texture0, fragTexCoord + vec2(float(i) * texelW, 0.0)).rgb;
        bloom += max(vec3(0.0), s - threshold) * w;
        total += w;
    }
    finalColor = vec4(bloom / total, 1.0);
}
