Debian Codegraph @

tests/manual/advancedcustommaterial/shaders/gl3/water.frag

raw
1 #version 150 core
2
3 in vec3 worldPosition;
4 in vec3 worldNormal;
5 in vec4 worldTangent;
6 in vec2 texCoord;
7 in vec2 waveTexCoord;
8 in vec2 movtexCoord;
9 in vec2 multexCoord;
10 in vec2 skyTexCoord;
11
12 in vec3 vpos;
13
14 in vec3 color;
15
16 uniform sampler2D diffuseTexture;
17 uniform sampler2D specularTexture;
18 uniform sampler2D normalTexture;
19 uniform sampler2D waveTexture;
20 uniform sampler2D skyTexture;
21 uniform sampler2D foamTexture;
22
23 uniform float offsetx;
24 uniform float offsety;
25 uniform float specularity;
26 uniform float waveStrenght;
27 uniform vec4 ka;
28 uniform vec3 specularColor;
29 uniform float shininess;
30 uniform float normalAmount;
31 uniform vec3 eyePosition;
32
33 out vec4 fragColor;
34
35 #pragma include phong.inc.frag
36 #pragma include coordinatesystems.inc
37
38 void main()
39 {
40 // Move waveTexCoords
41 vec2 waveMovCoord = waveTexCoord;
42 waveMovCoord.x += offsetx;
43 waveMovCoord.y -= offsety;
44 vec4 wave = texture(waveTexture, waveMovCoord);
45
46 //Wiggle the newCoord by r and b colors of waveTexture
47 vec2 newCoord = texCoord;
48 newCoord.x += wave.r * waveStrenght;
49 newCoord.y -= wave.b * waveStrenght;
50
51 // Sample the textures at the interpolated texCoords
52 // Use default texCoord for diffuse (it does not move on x or y, so it can be used as "ground under the water").
53 vec4 diffuseTextureColor = texture(diffuseTexture, texCoord);
54 // 2 Animated Layers of specularTexture mixed with the newCoord
55 vec4 specularTextureColor = texture( specularTexture, multexCoord+newCoord) + (texture( specularTexture, movtexCoord+newCoord ));
56 // 2 Animated Layers of normalTexture mixed with the newCoord
57 vec3 tNormal = normalAmount * texture( normalTexture, movtexCoord+newCoord ).rgb - vec3( 1.0 )+(normalAmount * texture( normalTexture, multexCoord+newCoord ).rgb - vec3( 1.0 ));
58 // Animated skyTexture layer
59 vec4 skycolor = texture(skyTexture, skyTexCoord);
60 skycolor = skycolor * 0.4;
61 //Animated foamTexture layer
62 vec4 foamTextureColor = texture(foamTexture, texCoord);
63
64 mat3 tangentMatrix = calcWorldSpaceToTangentSpaceMatrix(worldNormal, worldTangent);
65 mat3 invertTangentMatrix = transpose(tangentMatrix);
66
67 vec3 wNormal = normalize(invertTangentMatrix * tNormal);
68 vec3 worldView = normalize(eyePosition - worldPosition);
69
70 vec4 diffuse = vec4(diffuseTextureColor.rgb, vpos.y);
71 vec4 specular = vec4(specularTextureColor.a*specularity);
72 vec4 outputColor = phongFunction(ka, diffuse, specular, shininess, worldPosition, worldView, wNormal);
73
74 outputColor += vec4(skycolor.rgb, vpos.y);
75 outputColor += (foamTextureColor.rgba*vpos.y);
76
77 fragColor = vec4(outputColor.rgb,1.0);
78 }
79