-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
reflection-color.frag
49 lines (37 loc) · 1019 Bytes
/
reflection-color.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
/*
(C) 2019 David Lettier
lettier.com
*/
#version 150
uniform sampler2D uvTexture;
uniform sampler2D colorTexture;
out vec4 fragColor;
void main() {
int size = 6;
float separation = 2.0;
vec2 texSize = textureSize(uvTexture, 0).xy;
vec2 texCoord = gl_FragCoord.xy / texSize;
vec4 uv = texture(uvTexture, texCoord);
// Removes holes in the UV map.
if (uv.b <= 0.0) {
uv = vec4(0.0);
float count = 0.0;
for (int i = -size; i <= size; ++i) {
for (int j = -size; j <= size; ++j) {
uv += texture
( uvTexture
, ( (vec2(i, j) * separation)
+ gl_FragCoord.xy
)
/ texSize
);
count += 1.0;
}
}
uv.xyz /= count;
}
if (uv.b <= 0.0) { fragColor = vec4(0.0); return;}
vec4 color = texture(colorTexture, uv.xy);
float alpha = clamp(uv.b, 0.0, 1.0);
fragColor = vec4(mix(vec3(0.0), color.rgb, alpha), alpha);
}