#version 330 core
out vec4 FragColor;

in vec2 TexCoords;

uniform sampler2D image;
uniform bool horizontal;
uniform float KernelWeights[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);

void main()
{             
    vec2 tex_offset = 1.0 / textureSize(image, 0);
    vec3 result = texture(image, TexCoords).rgb * KernelWeights[0];
    if(horizontal)
    {
        for(int i = 1; i < 5; ++i)
        {
            result += texture(image, TexCoords + vec2(tex_offset.x * i, 0.0)).rgb * KernelWeights[i];
            result += texture(image, TexCoords - vec2(tex_offset.x * i, 0.0)).rgb * KernelWeights[i];
        }
    }
    else
    {
        for(int i = 1; i < 5; ++i)
        {
            result += texture(image, TexCoords + vec2(0.0, tex_offset.y * i)).rgb * KernelWeights[i];
            result += texture(image, TexCoords - vec2(0.0, tex_offset.y * i)).rgb * KernelWeights[i];
        }
    }
    FragColor = vec4(result, 1.0);
}