summaryrefslogtreecommitdiffstats
path: root/basicsuite/advancedcustommaterial/shaders/es2/water.frag
diff options
context:
space:
mode:
authorMikko Gronoff <mikko.gronoff@qt.io>2018-09-14 10:25:01 +0300
committerMikko Gronoff <mikko.gronoff@qt.io>2018-09-14 10:27:21 +0300
commit97863a4992276a3d1aeb3c1bb9ef5a280a5e8b12 (patch)
treeb38f6f152e7036b91c25834a917e320955660db2 /basicsuite/advancedcustommaterial/shaders/es2/water.frag
parent8be609623fc646e8d9642fc8481a1b9e59fb8417 (diff)
parentaa8e21cc3f60e54dd9c5d1ec482ca440857568f0 (diff)
Merge remote-tracking branch 'origin/5.11' into 5.12
* origin/5.11: aa8e21c Add new Qt3D demo ca03367 Exclude demos from colibri imx6ull a5345fd qtwebbrowser: merge changes from qtwebbrowser git repo d7e9731 do not enable highdpiscaling on emulator f730907 Fix mediaplayer default video path 09aa32d Fix some major scaling & font issues on ebike-demo Change-Id: I044c29ea2908a6254f32b0623037ea63f23d25cb
Diffstat (limited to 'basicsuite/advancedcustommaterial/shaders/es2/water.frag')
-rw-r--r--basicsuite/advancedcustommaterial/shaders/es2/water.frag76
1 files changed, 76 insertions, 0 deletions
diff --git a/basicsuite/advancedcustommaterial/shaders/es2/water.frag b/basicsuite/advancedcustommaterial/shaders/es2/water.frag
new file mode 100644
index 0000000..f471504
--- /dev/null
+++ b/basicsuite/advancedcustommaterial/shaders/es2/water.frag
@@ -0,0 +1,76 @@
+#define FP highp
+
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+varying FP vec4 worldTangent;
+varying FP vec2 texCoord;
+varying FP vec2 waveTexCoord;
+varying FP vec2 movtexCoord;
+varying FP vec2 multexCoord;
+varying FP vec2 skyTexCoord;
+
+varying FP vec3 vpos;
+
+varying FP vec3 color;
+
+uniform FP sampler2D diffuseTexture;
+uniform FP sampler2D specularTexture;
+uniform FP sampler2D normalTexture;
+uniform FP sampler2D waveTexture;
+uniform FP sampler2D skyTexture;
+uniform FP sampler2D foamTexture;
+
+uniform FP float offsetx;
+uniform FP float offsety;
+uniform FP float specularity;
+uniform FP float waveStrenght;
+uniform FP vec4 ka;
+uniform FP float shininess;
+uniform FP float normalAmount;
+uniform FP vec3 eyePosition;
+
+#pragma include phong.inc.frag
+#pragma include coordinatesystems.inc
+
+void main()
+{
+ // Move waveTexCoords
+ FP vec2 waveMovCoord = waveTexCoord;
+ waveMovCoord.x += offsetx;
+ waveMovCoord.y -= offsety;
+ FP vec4 wave = texture2D(waveTexture, waveMovCoord);
+
+ //Wiggle the newCoord by r and b colors of waveTexture
+ FP 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").
+ FP vec4 diffuseTextureColor = texture2D(diffuseTexture, texCoord);
+ // 2 Animated Layers of specularTexture mixed with the newCoord
+ FP vec4 specularTextureColor = texture2D( specularTexture, multexCoord+newCoord) + (texture2D( specularTexture, movtexCoord+newCoord ));
+ // 2 Animated Layers of normalTexture mixed with the newCoord
+ FP vec3 tNormal = normalAmount * texture2D( normalTexture, movtexCoord+newCoord ).rgb - vec3( 1.0 )+(normalAmount * texture2D( normalTexture, multexCoord+newCoord ).rgb - vec3( 1.0 ));
+ // Animated skyTexture layer
+ FP vec4 skycolor = texture2D(skyTexture, skyTexCoord);
+ skycolor = skycolor * 0.4;
+ //Animated foamTexture layer
+ FP vec4 foamTextureColor = texture2D(foamTexture, texCoord);
+
+ FP mat3 tangentMatrix = calcWorldSpaceToTangentSpaceMatrix(worldNormal, worldTangent);
+ FP mat3 invertTangentMatrix = transpose(tangentMatrix);
+
+ FP vec3 wNormal = normalize(invertTangentMatrix * tNormal);
+ FP vec3 worldView = normalize(eyePosition - worldPosition);
+
+ FP vec4 diffuse = vec4(diffuseTextureColor.rgb, vpos.y);
+ FP vec4 specular = vec4(specularTextureColor.a*specularity);
+ FP vec4 outputColor = phongFunction(ka, diffuse, specular, shininess, worldPosition, worldView, wNormal);
+
+ outputColor += vec4(skycolor.rgb, vpos.y);
+ outputColor += (foamTextureColor.rgba*vpos.y);
+
+ gl_FragColor = vec4(outputColor.rgb,1.0);
+}
+