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