#version 300 es
@builtin_ext@
@builtin@

precision mediump float;

uniform sampler2D in_tex;
out vec4 out_color;
in mediump vec2 uvpos;
uniform float progress;

// Shader adapted from: https://www.shadertoy.com/view/Xltfzj

float PI_2 = 6.28318530718;

// GAUSSIAN BLUR SETTINGS
float directions = 32.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)
float quality = 3.0; // BLUR QUALITY (Default 4.0 - More is better but slower)
float radius = 8.0; // BLUR SIZE (Radius)

void main()
{
    ivec2 size = textureSize(in_tex, 0);
    vec2 s = vec2(size);
    vec2 r = radius / s;
    vec2 uv = uvpos;
    vec4 c = get_pixel(uv);
    vec4 oc = c;

    for (float d = 0.0; d < PI_2; d += PI_2 / directions)
    {
        for(float i = 1.0 / quality; i <= 1.0; i += 1.0 / quality)
        {
            c += get_pixel(uv + vec2(cos(d), sin(d)) * r * i);
        }
    }

    c /= quality * directions - 15.0;
    out_color = mix(oc, c, progress);
}