diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-05-24 12:09:44 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-05-24 12:10:02 +0100 |
commit | 77d294db076dac19e8b549b445ffede9f7260c84 (patch) | |
tree | 828ee7a6862ec5c0bd24f97cb540625a2c647376 /examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag | |
parent | 59f8fec8a41606b3185fe3a4e276978e3e1ed5ef (diff) | |
parent | 939b9b4b7591e8a421cf048a0a84ed3e75d81d21 (diff) |
Merge branch 'dev' into wip/animationwip/animation
Change-Id: I6e770609c90a7745d08fa4e2f424e865678c5d6f
Diffstat (limited to 'examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag')
-rw-r--r-- | examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag b/examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag new file mode 100644 index 000000000..9657cc63a --- /dev/null +++ b/examples/qt3d/advancedcustommaterial/shaders/gl3/water.frag @@ -0,0 +1,74 @@ +#version 150 core + +in vec3 worldPosition; +in vec2 texCoord; +in vec2 waveTexCoord; +in vec2 movtexCoord; +in vec2 multexCoord; +in vec2 skyTexCoord; + +in vec3 vpos; + +in mat3 tangentMatrix; +in vec3 color; + +uniform sampler2D diffuseTexture; +uniform sampler2D specularTexture; +uniform sampler2D normalTexture; +uniform sampler2D waveTexture; +uniform sampler2D skyTexture; +uniform sampler2D foamTexture; + +uniform float offsetx; +uniform float offsety; +uniform float specularity; +uniform float waveStrenght; +uniform vec3 ka; +uniform vec3 specularColor; +uniform float shininess; +uniform float normalAmount; +uniform vec3 eyePosition; + +out vec4 fragColor; + +#pragma include light.inc.frag + +void main() +{ + // Move waveTexCoords + vec2 waveMovCoord = waveTexCoord; + waveMovCoord.x += offsetx; + waveMovCoord.y -= offsety; + vec4 wave = texture(waveTexture, waveMovCoord); + + //Wiggle the newCoord by r and b colors of waveTexture + vec2 newCoord = texCoord; + newCoord.x += wave.r * waveStrenght; + newCoord.y -= wave.b * waveStrenght; + + // Sample the textures at the interpolated texCoords + // Use default texCoord for diffuse (it does not move on x or y, so it can be used as "ground under the water"). + vec4 diffuseTextureColor = texture(diffuseTexture, texCoord); + // 2 Animated Layers of specularTexture mixed with the newCoord + vec4 specularTextureColor = texture( specularTexture, multexCoord+newCoord) + (texture( specularTexture, movtexCoord+newCoord )); + // 2 Animated Layers of normalTexture mixed with the newCoord + vec3 normal = normalAmount * texture( normalTexture, movtexCoord+newCoord ).rgb - vec3( 1.0 )+(normalAmount * texture( normalTexture, multexCoord+newCoord ).rgb - vec3( 1.0 )); + // Animated skyTexture layer + vec4 skycolor = texture(skyTexture, skyTexCoord); + skycolor = skycolor * 0.4; + //Animated foamTexture layer + vec4 foamTextureColor = texture(foamTexture, texCoord); + + // Calculate the lighting model, keeping the specular component separate + vec3 diffuseColor, specularColor; + adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor); + + // Combine final fragment color + vec4 outputColor = vec4(((skycolor.rgb + ka + diffuseTextureColor.rgb * (diffuseColor))+(specularColor * specularTextureColor.a*specularity)), vpos.y ); + + + outputColor += (foamTextureColor.rgba*vpos.y); + + fragColor = vec4(outputColor.rgb,1.0); +} + |