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