-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathblur.glsl
81 lines (58 loc) · 1.89 KB
/
blur.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#START_VERTEX
#version 140
/**
-------------- blur vertex shader -------------
author: Richman Stewart
simple vertex shader that sets the position
to the specified matrix and position while
passing the vertex colour and tex coords
to the fragment shader
**/
in vec2 a_position;
in vec2 a_tex_coord;
in vec4 a_colour;
uniform mat4 matrix;
out vec4 v_colour;
out vec2 tex_coord;
void main() {
v_colour = a_colour;
tex_coord = a_tex_coord;
gl_Position = matrix * vec4(a_position, 0, 1);
}
#END_VERTEX
#START_FRAGMENT
#version 140
/**
------------ one pass blur shader ------------
author: Richman Stewart
applies a gaussian blur horizontally and vertically
------------------ use ------------------------
blur_size - blur spread amount
**/
in vec4 v_colour;
in vec2 tex_coord;
out vec4 pixel;
uniform sampler2D t0;
uniform vec2 blur_size = vec2(.5, .5);
void main() {
ivec2 size = textureSize(t0, 0);
float uv_x = tex_coord.x * size.x;
float uv_y = tex_coord.y * size.y;
vec4 sum = vec4(0.0);
for (int n = 0; n < 9; ++n) {
uv_y = (tex_coord.y * size.y) + (blur_size.y * float(n - 4.5));
vec4 h_sum = vec4(0.0);
h_sum += texelFetch(t0, ivec2(uv_x - (4.0 * blur_size.x), uv_y), 0);
h_sum += texelFetch(t0, ivec2(uv_x - (3.0 * blur_size.x), uv_y), 0);
h_sum += texelFetch(t0, ivec2(uv_x - (2.0 * blur_size.x), uv_y), 0);
h_sum += texelFetch(t0, ivec2(uv_x - blur_size.x, uv_y), 0);
h_sum += texelFetch(t0, ivec2(uv_x, uv_y), 0);
h_sum += texelFetch(t0, ivec2(uv_x + blur_size.x, uv_y), 0);
h_sum += texelFetch(t0, ivec2(uv_x + (2.0 * blur_size.x), uv_y), 0);
h_sum += texelFetch(t0, ivec2(uv_x + (3.0 * blur_size.x), uv_y), 0);
h_sum += texelFetch(t0, ivec2(uv_x + (4.0 * blur_size.x), uv_y), 0);
sum += h_sum / 9.0;
}
pixel = sum / 9.0;
}
#END_FRAGMENT