2014-11-15 14:43:44 -05:00
|
|
|
uniform sampler2D source;
|
2014-11-15 15:02:24 -05:00
|
|
|
uniform layout(r32f) restrict writeonly image2D dest;
|
2014-11-15 14:43:44 -05:00
|
|
|
uniform vec2 pixel;
|
|
|
|
uniform float sigma;
|
|
|
|
|
|
|
|
// Gaussian separated blur with radius 6.
|
|
|
|
|
|
|
|
layout (local_size_x = 8, local_size_y = 8) in;
|
|
|
|
|
|
|
|
shared float local_src[8][8 + 2 * 6];
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
int x = int(gl_LocalInvocationID.x), y = int(gl_LocalInvocationID.y);
|
|
|
|
ivec2 iuv = ivec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y);
|
|
|
|
vec2 uv_m = (iuv - ivec2(0, 6)) * pixel;
|
|
|
|
vec2 uv = iuv * pixel;
|
|
|
|
vec2 uv_p = (iuv + ivec2(0, 6)) * pixel;
|
|
|
|
|
|
|
|
local_src[x][y] = texture(source, uv_m).x;
|
|
|
|
local_src[x][y + 6] = texture(source, uv).x;
|
|
|
|
local_src[x][y + 12] = texture(source, uv_p).x;
|
|
|
|
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
float g0, g1, g2;
|
|
|
|
g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma);
|
|
|
|
g1 = exp(-0.5 / (sigma * sigma));
|
|
|
|
g2 = g1 * g1;
|
2014-11-15 15:02:24 -05:00
|
|
|
float sum = local_src[x][y + 6] * g0;
|
2014-11-15 14:43:44 -05:00
|
|
|
g0 *= g1;
|
|
|
|
g1 *= g2;
|
|
|
|
for (int i = 1; i < 6; i++) {
|
|
|
|
sum += local_src[x][6 + y - i] * g0;
|
|
|
|
sum += local_src[x][6 + y + i] * g0;
|
|
|
|
g0 *= g1;
|
|
|
|
g1 *= g2;
|
|
|
|
}
|
|
|
|
|
|
|
|
imageStore(dest, iuv, vec4(sum));
|
|
|
|
}
|