2019-12-14 21:06:12 +00:00
|
|
|
// VERTEX_SHADER:
|
2019-12-20 10:43:33 +00:00
|
|
|
uniform float u_blur_radius;
|
|
|
|
uniform vec2 u_blur_size;
|
|
|
|
uniform vec2 u_blur_dir;
|
|
|
|
|
|
|
|
_OUT_ vec2 pixel_step;
|
|
|
|
_OUT_ float pixels_per_side;
|
|
|
|
_OUT_ vec3 initial_gaussian;
|
|
|
|
|
|
|
|
const float PI = 3.14159265;
|
2020-08-07 04:43:06 +00:00
|
|
|
const float RADIUS_MULTIPLIER = 2.0;
|
2019-12-20 10:43:33 +00:00
|
|
|
|
2019-12-14 21:06:12 +00:00
|
|
|
void main() {
|
|
|
|
gl_Position = u_projection * u_modelview * vec4(aPosition, 0.0, 1.0);
|
|
|
|
|
|
|
|
vUv = vec2(aUv.x, aUv.y);
|
2019-12-20 10:43:33 +00:00
|
|
|
|
|
|
|
pixel_step = (vec2(1.0) / u_blur_size) * u_blur_dir;
|
|
|
|
pixels_per_side = floor(u_blur_radius * RADIUS_MULTIPLIER / 2.0);
|
|
|
|
|
2020-08-29 09:30:45 +00:00
|
|
|
float sigma = u_blur_radius / 2.0; // *shrug*
|
2019-12-20 10:43:33 +00:00
|
|
|
initial_gaussian.x = 1.0 / (sqrt(2.0 * PI) * sigma);
|
|
|
|
initial_gaussian.y = exp(-0.5 / (sigma * sigma));
|
|
|
|
initial_gaussian.z = initial_gaussian.y * initial_gaussian.y;
|
2019-12-14 21:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FRAGMENT_SHADER:
|
2019-11-26 08:38:53 +00:00
|
|
|
uniform float u_blur_radius;
|
|
|
|
uniform vec2 u_blur_size;
|
2017-11-25 07:56:50 +00:00
|
|
|
|
2019-12-20 10:43:33 +00:00
|
|
|
_IN_ vec2 pixel_step;
|
|
|
|
_IN_ float pixels_per_side;
|
|
|
|
_IN_ vec3 initial_gaussian;
|
2017-11-25 07:56:50 +00:00
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
// blur_radius 0 is NOT supported and MUST be caught before.
|
2017-11-25 07:56:50 +00:00
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
// Partially from http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html
|
|
|
|
void main() {
|
2019-12-20 10:43:33 +00:00
|
|
|
vec3 incrementalGaussian = initial_gaussian;
|
2017-12-28 15:41:32 +00:00
|
|
|
|
2019-12-16 05:16:26 +00:00
|
|
|
float coefficientSum = 0.0;
|
2020-09-18 09:35:29 +00:00
|
|
|
vec4 sum = GskTexture(u_source, vUv) * incrementalGaussian.x;
|
2019-11-26 08:38:53 +00:00
|
|
|
coefficientSum += incrementalGaussian.x;
|
|
|
|
incrementalGaussian.xy *= incrementalGaussian.yz;
|
2017-12-28 15:41:32 +00:00
|
|
|
|
2019-12-20 10:43:33 +00:00
|
|
|
vec2 p = pixel_step;
|
|
|
|
for (int i = 1; i <= int(pixels_per_side); i++) {
|
2020-09-18 09:35:29 +00:00
|
|
|
sum += GskTexture(u_source, vUv - p) * incrementalGaussian.x;
|
|
|
|
sum += GskTexture(u_source, vUv + p) * incrementalGaussian.x;
|
2017-12-28 15:41:32 +00:00
|
|
|
|
2019-11-26 08:38:53 +00:00
|
|
|
coefficientSum += 2.0 * incrementalGaussian.x;
|
|
|
|
incrementalGaussian.xy *= incrementalGaussian.yz;
|
2019-12-20 10:43:33 +00:00
|
|
|
|
|
|
|
p += pixel_step;
|
2019-11-26 08:38:53 +00:00
|
|
|
}
|
2017-11-25 07:56:50 +00:00
|
|
|
|
2020-09-18 09:35:29 +00:00
|
|
|
gskSetOutputColor(sum / coefficientSum);
|
2017-11-25 07:56:50 +00:00
|
|
|
}
|