2017-12-28 15:41:32 +00:00
|
|
|
uniform float u_blur_radius = 40.0;
|
|
|
|
uniform vec2 u_blur_size = vec2(393, 393);
|
2017-11-25 07:56:50 +00:00
|
|
|
|
2017-12-28 15:41:32 +00:00
|
|
|
float Gaussian (float sigma, float x) {
|
2017-11-25 07:56:50 +00:00
|
|
|
return exp ( - (x * x) / (2.0 * sigma * sigma));
|
|
|
|
}
|
|
|
|
|
2017-12-28 15:41:32 +00:00
|
|
|
vec4 blur_pixel (in vec2 uv) {
|
2017-11-25 07:56:50 +00:00
|
|
|
float total = 0.0;
|
|
|
|
vec4 ret = vec4 (0);
|
2017-11-30 17:47:55 +00:00
|
|
|
float pixel_size_x = (1.0 / u_blur_size.x);
|
|
|
|
float pixel_size_y = (1.0 / u_blur_size.y);
|
2017-11-25 07:56:50 +00:00
|
|
|
|
2017-12-28 15:41:32 +00:00
|
|
|
// XXX The magic value here is GAUSSIAN_SCALE_FACTOR from gskcairoblur.c
|
|
|
|
float radius = u_blur_radius * 2.30348;
|
|
|
|
|
|
|
|
int half_radius = int(radius / 2.0);
|
|
|
|
|
|
|
|
for (int y = -half_radius; y < half_radius; y ++) {
|
|
|
|
float fy = Gaussian (radius / 2.0, float(y));
|
2018-01-08 17:36:48 +00:00
|
|
|
float offset_y = y * pixel_size_y;
|
2017-12-28 15:41:32 +00:00
|
|
|
|
|
|
|
for (int x = -half_radius; x < half_radius; x ++) {
|
|
|
|
float fx = Gaussian (radius / 2.0, float(x));
|
|
|
|
float offset_x = x * pixel_size_x;
|
|
|
|
|
|
|
|
vec4 c = Texture(u_source, uv + vec2(offset_x, offset_y));
|
|
|
|
total += fx * fy;
|
|
|
|
ret += c * fx * fy;
|
2017-11-25 07:56:50 +00:00
|
|
|
}
|
2017-12-28 15:41:32 +00:00
|
|
|
}
|
|
|
|
|
2017-11-25 07:56:50 +00:00
|
|
|
return ret / total;
|
|
|
|
}
|
|
|
|
|
2017-12-28 15:41:32 +00:00
|
|
|
void main() {
|
|
|
|
vec4 color = blur_pixel(vUv);
|
|
|
|
setOutputColor(color);
|
2017-11-25 07:56:50 +00:00
|
|
|
}
|