#version 450

layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

layout(set = 0, binding = 0, r16f) uniform writeonly image2D FilterOutput;
layout(set = 0, binding = 1, r16f) uniform readonly image2D Input;
layout(set = 0, binding = 2) uniform Dir {
    ivec2 Direction;
};

void main()
{
    const ivec2 pixel = ivec2(gl_GlobalInvocationID.xy);
    const ivec2 image_size = imageSize(Input).xy;
    if (pixel.x >= image_size.x || pixel.y >= image_size.y) {
        return;
    }

    vec4 color = vec4(0.0);
    const vec2 off1 = vec2(1.411764705882353) * Direction;
    const vec2 off2 = vec2(3.2941176470588234) * Direction;
    const vec2 off3 = vec2(5.176470588235294) * Direction;

    const vec2 fpixel = vec2(pixel);

    color += imageLoad(Input, pixel) * 0.1964825501511404;
    color += imageLoad(Input, ivec2(fpixel + off1)) * 0.2969069646728344;
    color += imageLoad(Input, ivec2(fpixel - off1)) * 0.2969069646728344;
    color += imageLoad(Input, ivec2(fpixel + off2)) * 0.09447039785044732;
    color += imageLoad(Input, ivec2(fpixel - off2)) * 0.09447039785044732;
    color += imageLoad(Input, ivec2(fpixel + off3)) * 0.010381362401148057;
    color += imageLoad(Input, ivec2(fpixel - off3)) * 0.010381362401148057;

    imageStore(FilterOutput, pixel, color);
}