forked from lettier/3d-game-shaders-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 3
/
base-combine.frag
31 lines (25 loc) · 1004 Bytes
/
base-combine.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
/*
(C) 2019 David Lettier
lettier.com
*/
#version 150
uniform sampler2D baseTexture;
uniform sampler2D refractionTexture;
uniform sampler2D foamTexture;
uniform sampler2D reflectionTexture;
uniform sampler2D specularTexture;
out vec4 fragColor;
void main() {
vec2 texSize = textureSize(baseTexture, 0).xy;
vec2 texCoord = gl_FragCoord.xy / texSize;
vec4 base = texture(baseTexture, texCoord);
vec4 refraction = texture(refractionTexture, texCoord);
vec4 foam = texture(foamTexture, texCoord);
vec4 reflection = texture(reflectionTexture, texCoord);
vec4 specular = texture(specularTexture, texCoord);
fragColor = base;
fragColor.rgb = mix(fragColor.rgb, refraction.rgb, clamp(refraction.a, 0.0, 1.0));
fragColor.rgb = mix(fragColor.rgb, reflection.rgb, clamp(reflection.a, 0.0, 1.0));
fragColor.rgb = mix(fragColor.rgb, foam.rgb, clamp(foam.a, 0.0, 1.0));
fragColor.rgb += (specular.rgb * clamp(specular.a, 0.0, 1.0));
}