forked from lettier/3d-game-shaders-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssao-blur.frag
51 lines (36 loc) · 914 Bytes
/
ssao-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
47
48
49
50
51
/*
(C) 2019 David Lettier
lettier.com
*/
#version 140
uniform sampler2D ssaoTexture;
out vec4 fragColor;
void main() {
float separation = 0.001;
int samples = 3;
vec2 texSize = textureSize(ssaoTexture, 0).xy;
vec2 texCoord = gl_FragCoord.xy / texSize;
int size = samples;
int size2 = size * size;
int countMax = size + ((size - 1) / 2);
int countMin = size - ((size - 1) / 2);
int xCount = countMax;
int yCount = countMax;
int x = 0;
int y = 0;
vec3 result = vec3(0);
for (int i = 0; i < size2; ++i) {
x = size - xCount;
y = yCount - size;
result +=
texture
( ssaoTexture
, texCoord
+ vec2(x * separation, y * separation)
).rgb;
xCount -= 1;
if (xCount < countMin) { xCount = countMax; yCount -= 1; }
}
result = result / size2;
fragColor = vec4(result, texture(ssaoTexture, texCoord).a);
}