2018-01-08 17:59:01 +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;
|
|
|
|
|
2018-02-27 13:22:08 +00:00
|
|
|
int half_radius = max(int(radius / 2.0), 1);
|
2017-12-28 15:41:32 +00:00
|
|
|
|
|
|
|
for (int y = -half_radius; y < half_radius; y ++) {
|
|
|
|
float fy = Gaussian (radius / 2.0, float(y));
|
2018-01-08 17:59:01 +00:00
|
|
|
float offset_y = float(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));
|
2018-01-08 17:59:01 +00:00
|
|
|
float offset_x = float(x) * pixel_size_x;
|
2017-12-28 15:41:32 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|