summaryrefslogtreecommitdiffstats
path: root/basicsuite/advancedcustommaterial/shaders/es2
diff options
context:
space:
mode:
Diffstat (limited to 'basicsuite/advancedcustommaterial/shaders/es2')
-rw-r--r--basicsuite/advancedcustommaterial/shaders/es2/coordinatesystems.inc87
-rw-r--r--basicsuite/advancedcustommaterial/shaders/es2/light.inc.frag17
-rw-r--r--basicsuite/advancedcustommaterial/shaders/es2/phong.inc.frag128
-rw-r--r--basicsuite/advancedcustommaterial/shaders/es2/water.frag76
-rw-r--r--basicsuite/advancedcustommaterial/shaders/es2/water.vert73
5 files changed, 381 insertions, 0 deletions
diff --git a/basicsuite/advancedcustommaterial/shaders/es2/coordinatesystems.inc b/basicsuite/advancedcustommaterial/shaders/es2/coordinatesystems.inc
new file mode 100644
index 0000000..5f6ee40
--- /dev/null
+++ b/basicsuite/advancedcustommaterial/shaders/es2/coordinatesystems.inc
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#define FP highp
+
+FP mat3 transpose(const in FP mat3 inputMatrix)
+{
+ FP vec3 i0 = inputMatrix[0];
+ FP vec3 i1 = inputMatrix[1];
+ FP vec3 i2 = inputMatrix[2];
+
+ FP mat3 outputMatrix = mat3(
+ vec3(i0.x, i1.x, i2.x),
+ vec3(i0.y, i1.y, i2.y),
+ vec3(i0.z, i1.z, i2.z)
+ );
+
+ return outputMatrix;
+}
+
+FP mat3 calcWorldSpaceToTangentSpaceMatrix(const in FP vec3 wNormal, const in FP vec4 wTangent)
+{
+ // Make the tangent truly orthogonal to the normal by using Gram-Schmidt.
+ // This allows to build the tangentMatrix below by simply transposing the
+ // tangent -> eyespace matrix (which would now be orthogonal)
+ FP vec3 wFixedTangent = normalize(wTangent.xyz - dot(wTangent.xyz, wNormal) * wNormal);
+
+ // Calculate binormal vector. No "real" need to renormalize it,
+ // as built by crossing two normal vectors.
+ // To orient the binormal correctly, use the fourth coordinate of the tangent,
+ // which is +1 for a right hand system, and -1 for a left hand system.
+ FP vec3 wBinormal = cross(wNormal, wFixedTangent.xyz) * wTangent.w;
+
+ // Construct matrix to transform from world space to tangent space
+ // This is the transpose of the tangentToWorld transformation matrix
+ FP mat3 tangentToWorldMatrix = mat3(wFixedTangent, wBinormal, wNormal);
+ FP mat3 worldToTangentMatrix = transpose(tangentToWorldMatrix);
+ return worldToTangentMatrix;
+}
+
diff --git a/basicsuite/advancedcustommaterial/shaders/es2/light.inc.frag b/basicsuite/advancedcustommaterial/shaders/es2/light.inc.frag
new file mode 100644
index 0000000..167ff30
--- /dev/null
+++ b/basicsuite/advancedcustommaterial/shaders/es2/light.inc.frag
@@ -0,0 +1,17 @@
+#define FP highp
+
+const int MAX_LIGHTS = 8;
+const int TYPE_POINT = 0;
+const int TYPE_DIRECTIONAL = 1;
+const int TYPE_SPOT = 2;
+struct Light {
+ int type;
+ FP vec3 position;
+ FP vec3 color;
+ FP float intensity;
+ FP vec3 direction;
+ FP vec3 attenuation;
+ FP float cutOffAngle;
+};
+uniform Light lights[MAX_LIGHTS];
+uniform int lightCount;
diff --git a/basicsuite/advancedcustommaterial/shaders/es2/phong.inc.frag b/basicsuite/advancedcustommaterial/shaders/es2/phong.inc.frag
new file mode 100644
index 0000000..9d17b68
--- /dev/null
+++ b/basicsuite/advancedcustommaterial/shaders/es2/phong.inc.frag
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma include light.inc.frag
+
+void adsModel(const in FP vec3 vpos, const in FP vec3 vnormal, const in FP vec3 vview, const in FP float shininess,
+ out FP vec3 diffuseColor, out FP vec3 specularColor)
+{
+ diffuseColor = vec3(0.0);
+ specularColor = vec3(0.0);
+
+ FP vec3 n = normalize( vnormal );
+
+ FP vec3 s;
+ Light light;
+ for (int i = 0; i < lightCount; ++i) {
+ if (i == 0)
+ light = lights[0];
+ else if (i == 1)
+ light = lights[1];
+ else if (i == 2)
+ light = lights[2];
+ else if (i == 3)
+ light = lights[3];
+ else if (i == 4)
+ light = lights[4];
+ else if (i == 5)
+ light = lights[5];
+ else if (i == 6)
+ light = lights[6];
+ else if (i == 7)
+ light = lights[7];
+
+ FP float att = 1.0;
+ if ( light.type != TYPE_DIRECTIONAL ) {
+ s = light.position - vpos;
+ if (length( light.attenuation ) != 0.0) {
+ FP float dist = length(s);
+ att = 1.0 / (light.attenuation.x + light.attenuation.y * dist + light.attenuation.z * dist * dist);
+ }
+ s = normalize( s );
+ if ( light.type == TYPE_SPOT ) {
+ if ( degrees(acos(dot(-s, normalize(light.direction))) ) > light.cutOffAngle)
+ att = 0.0;
+ }
+ } else {
+ s = normalize( -light.direction );
+ }
+
+ FP float diffuse = max( dot( s, n ), 0.0 );
+
+ FP float specular = 0.0;
+ if (diffuse > 0.0 && shininess > 0.0 && att > 0.0) {
+ FP vec3 r = reflect( -s, n );
+ FP float normFactor = ( shininess + 2.0 ) / 2.0;
+ specular = normFactor * pow( max( dot( r, vview ), 0.0 ), shininess );
+ }
+
+ diffuseColor += att * light.intensity * diffuse * light.color;
+ specularColor += att * light.intensity * specular * light.color;
+ }
+}
+
+FP vec4 phongFunction(const in FP vec4 ambient,
+ const in FP vec4 diffuse,
+ const in FP vec4 specular,
+ const in FP float shininess,
+ const in FP vec3 worldPosition,
+ const in FP vec3 worldView,
+ const in FP vec3 worldNormal)
+{
+ // Calculate the lighting model, keeping the specular component separate
+ FP vec3 diffuseColor, specularColor;
+ adsModel(worldPosition, worldNormal, worldView, shininess, diffuseColor, specularColor);
+
+ // Combine spec with ambient+diffuse for final fragment color
+ FP vec3 color = (ambient.rgb + diffuseColor) * diffuse.rgb
+ + specularColor * specular.rgb;
+
+ return vec4(color, diffuse.a);
+}
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);
+}
+
diff --git a/basicsuite/advancedcustommaterial/shaders/es2/water.vert b/basicsuite/advancedcustommaterial/shaders/es2/water.vert
new file mode 100644
index 0000000..76dd3f8
--- /dev/null
+++ b/basicsuite/advancedcustommaterial/shaders/es2/water.vert
@@ -0,0 +1,73 @@
+#define FP highp
+
+attribute FP vec3 vertexPosition;
+attribute FP vec3 vertexNormal;
+attribute FP vec2 vertexTexCoord;
+attribute FP vec4 vertexTangent;
+
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+varying FP vec4 worldTangent;
+varying FP vec2 texCoord;
+varying FP vec2 movtexCoord;
+varying FP vec2 multexCoord;
+varying FP vec2 waveTexCoord;
+varying FP vec2 skyTexCoord;
+varying FP vec3 vpos;
+
+uniform FP mat4 modelMatrix;
+uniform FP mat3 modelNormalMatrix;
+uniform FP mat4 mvp;
+
+uniform FP float offsetx;
+uniform FP float offsety;
+uniform FP float vertYpos;
+uniform FP float texCoordScale;
+uniform FP float waveheight;
+uniform FP float waveRandom;
+
+
+void main()
+{
+ // Scale texture coordinates for for fragment shader
+ texCoord = vertexTexCoord * texCoordScale;
+ movtexCoord = vertexTexCoord * texCoordScale;
+ multexCoord = vertexTexCoord * (texCoordScale*0.5);
+ waveTexCoord = vertexTexCoord * (texCoordScale * 6.0);
+ skyTexCoord = vertexTexCoord * (texCoordScale * 0.2);
+
+ // Add Animated x and y Offset to SKY, MOV and MUL texCoords
+ movtexCoord = vec2(texCoord.x+offsetx,texCoord.y+offsety);
+ multexCoord = vec2(texCoord.x-offsetx,texCoord.y+offsety);
+ skyTexCoord = vec2(texCoord.x-(offsetx/2.0),texCoord.y-(offsety/2.0));
+
+ // Transform position, normal, and tangent to world coords
+ worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0));
+ worldNormal = normalize(modelNormalMatrix * vertexNormal);
+ worldTangent.xyz = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0)));
+ worldTangent.w = vertexTangent.w;
+
+ // Calculate animated vertex positions
+
+ FP float sinPos = (vertexPosition.z)+(vertexPosition.x);
+ FP float sinPos2 = (vertexPosition.y/2.0)+(vertexPosition.z);
+ FP vec3 vertMod = vec3(vertexPosition.x,vertexPosition.y,vertexPosition.z);
+
+ vertMod = vec3(vertMod.x+=sin(vertYpos*2.2-sinPos2)*waveheight,
+ vertMod.y=sin(vertYpos*2.2+sinPos)*waveheight,
+ vertMod.z-=sin(vertYpos*2.2-cos(sinPos2))*waveheight);
+
+ FP vec3 vertModCom = vec3(vertMod.x+=cos(vertYpos*2.2-cos(sinPos2))*waveheight,
+ vertMod.y=sin(vertYpos*2.2+cos(sinPos))*waveheight,
+ vertMod.z-=cos(vertYpos*2.2-cos(sinPos))*waveheight);
+
+
+ // Add wave animation only to vertices above world pos.y zero
+ if(vertexPosition.y < 0.0){vertModCom = vertexPosition;}
+ else{vertModCom = vertModCom;}
+
+ vpos = vertModCom;
+
+ // Calculate vertex position in clip coordinates
+ gl_Position = mvp * vec4(vertModCom, 1.0);
+}