#version 330 core
layout (std140) uniform uPostProcess {
    int curTime;

    int dt;
    vec3 colorMod;
    float blurIntensity;
    float blurDuration;
    float shakeIntensity;
    float shakeDuration;
    int effects;

    vec3 colorMod_hud;
    float blurIntensity_hud;
    float blurDuration_hud;
    float shakeIntensity_hud;
    float shakeDuration_hud;
    int effects_hud;
};
out vec4 FragColor;

in vec2 texCoord;

uniform int edge_kernel[9];
uniform float blur_kernel[9];

const float offset = 1.0 / 300.0;  

uniform sampler2D screenTexture;
uniform bool worldOrHud;

void main()
{
    if (worldOrHud == false)
    {
        if ((effects & 1) != 0) // BLUR
        {
            vec4 result = vec4(0.0);
            vec2 offsets[9] = vec2[](
                vec2(-offset,  offset), // top-left
                vec2( 0.0f,    offset), // top-center
                vec2( offset,  offset), // top-right
                vec2(-offset,  0.0f),   // center-left
                vec2( 0.0f,    0.0f),   // center-center
                vec2( offset,  0.0f),   // center-right
                vec2(-offset, -offset), // bottom-left
                vec2( 0.0f,   -offset), // bottom-center
                vec2( offset, -offset)  // bottom-right    
            );
            vec4 sampleTex[9];
            for (int i = 0; i < 9; i++)
            {
                sampleTex[i] = vec4(texture(screenTexture, texCoord.st + offsets[i]));
            }
            for (int i = 0; i < 9; i++)
                result += sampleTex[i] * blur_kernel[i];
            //FragColor = mix(texture(screenTexture, texCoord), vec4(1.0, 0.8, 0.0, 1.0), 0.3 - (1.0 / shakeTime) * shakeIntensity);
            //FragColor = vec4(1.0 / blurDuration, 1.0, 0.0, 1.0);
            FragColor = vec4(result);
        }
        else
        {
            //FragColor = vec4(1.0, 0.0, 1.0 / blurDuration, 1.0);
            FragColor = texture(screenTexture, texCoord);
        }
    }
}