forked from lettier/3d-game-shaders-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 1
/
box-blur.frag
46 lines (33 loc) · 823 Bytes
/
box-blur.frag
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
/*
(C) 2019 David Lettier
lettier.com
*/
#version 150
uniform sampler2D colorTexture;
uniform vec2 parameters;
out vec4 fragColor;
void main() {
vec2 texSize = textureSize(colorTexture, 0).xy;
vec2 texCoord = gl_FragCoord.xy / texSize;
fragColor = texture(colorTexture, texCoord);
int size = int(parameters.x);
if (size <= 0) { return; }
float separation = parameters.y;
separation = max(separation, 1);
fragColor.rgb = vec3(0);
float count = 0.0;
for (int i = -size; i <= size; ++i) {
for (int j = -size; j <= size; ++j) {
fragColor.rgb +=
texture
( colorTexture
, ( gl_FragCoord.xy
+ (vec2(i, j) * separation)
)
/ texSize
).rgb;
count += 1.0;
}
}
fragColor.rgb /= count;
}