summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/planets-qml/shaders
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@theqtcompany.com>2015-06-11 07:59:26 +0300
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>2015-06-23 12:20:55 +0000
commit520e2d32421f86958847b1bf9ee369606e0a83df (patch)
tree3bc179308b91fc552ad2511e7151aa158004bd22 /examples/qt3d/planets-qml/shaders
parent68ead5b04fb3e271524c19cc0b6d12a4c9c8a3c2 (diff)
Planets QML example for Qt3D
+ Improved earth clouds - Some weirdness with alpha, easily visible with rings. Might be the textures, although the alpha on them seems fine with image viewer. - Earth clouds seem to have the alpha issue as well. Change-Id: Ibdfa49472790d3fc797e269b52986b71d93876f2 Reviewed-by: Pasi Keränen <pasi.keranen@digia.com> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> (cherry picked from commit 30f9015933957eaf9533229f94b1bcd48a8ce3ed)
Diffstat (limited to 'examples/qt3d/planets-qml/shaders')
-rw-r--r--examples/qt3d/planets-qml/shaders/planetD.frag105
-rw-r--r--examples/qt3d/planets-qml/shaders/planetD.vert71
-rw-r--r--examples/qt3d/planets-qml/shaders/planetDB.frag107
-rw-r--r--examples/qt3d/planets-qml/shaders/planetDB.vert96
-rw-r--r--examples/qt3d/planets-qml/shaders/planetDS.frag104
-rw-r--r--examples/qt3d/planets-qml/shaders/planetDSB.frag110
-rw-r--r--examples/qt3d/planets-qml/shaders/shadowmap.frag41
-rw-r--r--examples/qt3d/planets-qml/shaders/shadowmap.vert46
8 files changed, 680 insertions, 0 deletions
diff --git a/examples/qt3d/planets-qml/shaders/planetD.frag b/examples/qt3d/planets-qml/shaders/planetD.frag
new file mode 100644
index 000000000..62d941d25
--- /dev/null
+++ b/examples/qt3d/planets-qml/shaders/planetD.frag
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+uniform mat4 viewMatrix;
+
+uniform vec3 lightPosition;
+uniform vec3 lightIntensity;
+
+uniform vec3 ka; // Ambient reflectivity
+uniform vec3 ks; // Specular reflectivity
+uniform float shininess; // Specular shininess factor
+uniform float opacity; // Alpha channel
+
+uniform sampler2D diffuseTexture;
+
+uniform sampler2DShadow shadowMapTexture;
+
+in vec4 positionInLightSpace;
+
+in vec3 position;
+in vec3 normal;
+in vec2 texCoord;
+
+out vec4 fragColor;
+
+vec3 dModel(const in vec2 flipYTexCoord)
+{
+ // Calculate the vector from the light to the fragment
+ vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - position);
+
+ // Calculate the vector from the fragment to the eye position
+ // (origin since this is in "eye" or "camera" space)
+ vec3 v = normalize(-position);
+
+ // Reflect the light beam using the normal at this fragment
+ vec3 r = reflect(-s, normal);
+
+ // Calculate the diffuse component
+ float diffuse = max(dot(s, normal), 0.0);
+
+ // Calculate the specular component
+ float specular = 0.0;
+ if (dot(s, normal) > 0.0)
+ specular = (shininess / (8.0 * 3.14)) * pow(max(dot(r, v), 0.0), shininess);
+
+ // Lookup diffuse and specular factors
+ vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb;
+
+ // Combine the ambient, diffuse and specular contributions
+ return lightIntensity * ((ka + diffuse) * diffuseColor + specular * ks);
+}
+
+void main()
+{
+ vec2 flipYTexCoord = texCoord;
+ flipYTexCoord.y = 1.0 - texCoord.y;
+
+ float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace);
+
+ vec3 ambient = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb;
+
+ vec3 result = ambient;
+ if (shadowMapSample > 0)
+ result = dModel(flipYTexCoord);
+
+ float alpha = opacity * texture(diffuseTexture, flipYTexCoord).a;
+
+ fragColor = vec4(result, alpha);
+}
diff --git a/examples/qt3d/planets-qml/shaders/planetD.vert b/examples/qt3d/planets-qml/shaders/planetD.vert
new file mode 100644
index 000000000..41a1db6e4
--- /dev/null
+++ b/examples/qt3d/planets-qml/shaders/planetD.vert
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+in vec2 vertexTexCoord;
+
+out vec4 positionInLightSpace;
+out vec3 position;
+out vec3 normal;
+out vec2 texCoord;
+
+uniform mat4 lightViewProjection;
+uniform mat4 modelMatrix;
+uniform mat4 modelView;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+uniform float texCoordScale;
+
+void main()
+{
+ const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.5, 0.5, 0.5, 1.0);
+
+ positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);
+
+ texCoord = vertexTexCoord * texCoordScale;
+ normal = normalize(modelViewNormal * vertexNormal);
+ position = vec3(modelView * vec4(vertexPosition, 1.0));
+
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}
diff --git a/examples/qt3d/planets-qml/shaders/planetDB.frag b/examples/qt3d/planets-qml/shaders/planetDB.frag
new file mode 100644
index 000000000..bf53a127b
--- /dev/null
+++ b/examples/qt3d/planets-qml/shaders/planetDB.frag
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+uniform mat4 viewMatrix;
+
+uniform vec3 lightPosition;
+uniform vec3 lightIntensity;
+
+uniform vec3 ka; // Ambient reflectivity
+uniform vec3 ks; // Specular reflectivity
+uniform float shininess; // Specular shininess factor
+uniform float opacity; // Alpha channel
+
+uniform sampler2D diffuseTexture;
+uniform sampler2D normalTexture;
+
+uniform sampler2DShadow shadowMapTexture;
+
+in vec4 positionInLightSpace;
+
+in vec3 lightDir;
+in vec3 viewDir;
+in vec2 texCoord;
+
+out vec4 fragColor;
+
+void dbModel(const in vec3 norm, const in vec2 flipYTexCoord, out vec3 ambientAndDiff, out vec3 spec)
+{
+ // Reflection of light direction about normal
+ vec3 r = reflect(-lightDir, norm);
+
+ vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb;
+
+ // Calculate the ambient contribution
+ vec3 ambient = lightIntensity * ka * diffuseColor;
+
+ // Calculate the diffuse contribution
+ float sDotN = max(dot(lightDir, norm), 0.0);
+ vec3 diffuse = lightIntensity * diffuseColor * sDotN;
+
+ // Sum the ambient and diffuse contributions
+ ambientAndDiff = ambient + diffuse;
+
+ // Calculate the specular highlight contribution
+ spec = vec3(0.0);
+ if (sDotN > 0.0)
+ spec = (lightIntensity * ks) * pow(max(dot(r, viewDir), 0.0), shininess);
+}
+
+void main()
+{
+ vec2 flipYTexCoord = texCoord;
+ flipYTexCoord.y = 1.0 - texCoord.y;
+
+ float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace);
+
+ // Sample the textures at the interpolated texCoords
+ vec4 normal = 2.0 * texture(normalTexture, flipYTexCoord) - vec4(1.0);
+
+ vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb;
+
+ // Calculate the lighting model, keeping the specular component separate
+ vec3 ambientAndDiff, spec;
+ if (shadowMapSample > 0) {
+ dbModel(normalize(normal.xyz), flipYTexCoord, ambientAndDiff, spec);
+ result = ambientAndDiff + spec;
+ }
+
+ // Combine spec with ambient+diffuse for final fragment color
+ fragColor = vec4(result, opacity);
+}
diff --git a/examples/qt3d/planets-qml/shaders/planetDB.vert b/examples/qt3d/planets-qml/shaders/planetDB.vert
new file mode 100644
index 000000000..e30394aa3
--- /dev/null
+++ b/examples/qt3d/planets-qml/shaders/planetDB.vert
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+in vec2 vertexTexCoord;
+in vec4 vertexTangent;
+
+out vec4 positionInLightSpace;
+out vec3 lightDir;
+out vec3 viewDir;
+out vec2 texCoord;
+
+uniform mat4 viewMatrix;
+uniform mat4 lightViewProjection;
+uniform mat4 modelMatrix;
+uniform mat4 modelView;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+uniform float texCoordScale;
+
+uniform vec3 lightPosition;
+
+void main()
+{
+ const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.5, 0.5, 0.5, 1.0);
+
+ positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);
+
+ // Pass through texture coordinates
+ texCoord = vertexTexCoord * texCoordScale;
+
+ // Transform position, normal, and tangent to eye coords
+ vec3 normal = normalize(modelViewNormal * vertexNormal);
+ vec3 tangent = normalize(modelViewNormal * vertexTangent.xyz);
+ vec3 position = vec3(modelView * vec4(vertexPosition, 1.0));
+
+ // Calculate binormal vector
+ vec3 binormal = normalize(cross(normal, tangent));
+
+ // Construct matrix to transform from eye coords to tangent space
+ mat3 tangentMatrix = mat3 (
+ tangent.x, binormal.x, normal.x,
+ tangent.y, binormal.y, normal.y,
+ tangent.z, binormal.z, normal.z);
+
+ // Transform light direction and view direction to tangent space
+ vec3 s = lightPosition - position;
+ lightDir = normalize(tangentMatrix * vec3(viewMatrix * vec4(s, 1.0)));
+
+ vec3 v = -position;
+ viewDir = normalize(tangentMatrix * v);
+
+ // Calculate vertex position in clip coordinates
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}
diff --git a/examples/qt3d/planets-qml/shaders/planetDS.frag b/examples/qt3d/planets-qml/shaders/planetDS.frag
new file mode 100644
index 000000000..2a1b78bfa
--- /dev/null
+++ b/examples/qt3d/planets-qml/shaders/planetDS.frag
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+uniform mat4 viewMatrix;
+
+uniform vec3 lightPosition;
+uniform vec3 lightIntensity;
+
+uniform vec3 ka; // Ambient reflectivity
+uniform float shininess; // Specular shininess factor
+uniform float opacity; // Alpha channel
+
+uniform sampler2D diffuseTexture;
+uniform sampler2D specularTexture;
+
+uniform sampler2DShadow shadowMapTexture;
+
+in vec4 positionInLightSpace;
+
+in vec3 position;
+in vec3 normal;
+in vec2 texCoord;
+
+out vec4 fragColor;
+
+vec3 dsModel(const in vec2 flipYTexCoord)
+{
+ // Calculate the vector from the light to the fragment
+ vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - position);
+
+ // Calculate the vector from the fragment to the eye position
+ // (origin since this is in "eye" or "camera" space)
+ vec3 v = normalize(-position);
+
+ // Reflect the light beam using the normal at this fragment
+ vec3 r = reflect(-s, normal);
+
+ // Calculate the diffuse component
+ float diffuse = max(dot(s, normal), 0.0);
+
+ // Calculate the specular component
+ float specular = 0.0;
+ if (dot(s, normal) > 0.0)
+ specular = (shininess / (8.0 * 3.14)) * pow(max(dot(r, v), 0.0), shininess);
+
+ // Lookup diffuse and specular factors
+ vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb;
+ vec3 specularColor = texture(specularTexture, flipYTexCoord).rgb;
+
+ // Combine the ambient, diffuse and specular contributions
+ return lightIntensity * ((ka + diffuse) * diffuseColor + specular * specularColor);
+}
+
+void main()
+{
+ vec2 flipYTexCoord = texCoord;
+ flipYTexCoord.y = 1.0 - texCoord.y;
+
+ float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace);
+
+ vec3 ambient = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb;
+
+ vec3 result = ambient;
+ if (shadowMapSample > 0)
+ result = dsModel(flipYTexCoord);
+
+ fragColor = vec4(result, opacity * texture(diffuseTexture, flipYTexCoord).a);
+}
diff --git a/examples/qt3d/planets-qml/shaders/planetDSB.frag b/examples/qt3d/planets-qml/shaders/planetDSB.frag
new file mode 100644
index 000000000..deb9565d4
--- /dev/null
+++ b/examples/qt3d/planets-qml/shaders/planetDSB.frag
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+uniform mat4 viewMatrix;
+
+uniform vec3 lightPosition;
+uniform vec3 lightIntensity;
+
+uniform vec3 ka; // Ambient reflectivity
+uniform float shininess; // Specular shininess factor
+uniform float opacity; // Alpha channel
+
+uniform sampler2D diffuseTexture;
+uniform sampler2D specularTexture;
+uniform sampler2D normalTexture;
+
+uniform sampler2DShadow shadowMapTexture;
+
+in vec4 positionInLightSpace;
+
+in vec3 lightDir;
+in vec3 viewDir;
+in vec2 texCoord;
+
+out vec4 fragColor;
+
+void dsbModel(const in vec3 norm, const in vec2 flipYTexCoord, out vec3 ambientAndDiff, out vec3 spec)
+{
+ // Reflection of light direction about normal
+ vec3 r = reflect(-lightDir, norm);
+
+ vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb;
+ vec3 specularColor = texture(specularTexture, flipYTexCoord).rgb;
+
+ // Calculate the ambient contribution
+ vec3 ambient = lightIntensity * ka * diffuseColor;
+
+ // Calculate the diffuse contribution
+ float sDotN = max(dot(lightDir, norm), 0.0);
+ vec3 diffuse = lightIntensity * diffuseColor * sDotN;
+
+ // Sum the ambient and diffuse contributions
+ ambientAndDiff = ambient + diffuse;
+
+ // Calculate the specular highlight contribution
+ spec = vec3(0.0);
+ if (sDotN > 0.0)
+ spec = (lightIntensity * (shininess / (8.0 * 3.14))) * pow(max(dot(r, viewDir), 0.0), shininess);
+
+ spec *= specularColor;
+}
+
+void main()
+{
+ vec2 flipYTexCoord = texCoord;
+ flipYTexCoord.y = 1.0 - texCoord.y;
+
+ float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace);
+
+ // Sample the textures at the interpolated texCoords
+ vec4 normal = 2.0 * texture(normalTexture, flipYTexCoord) - vec4(1.0);
+
+ vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb;
+
+ // Calculate the lighting model, keeping the specular component separate
+ vec3 ambientAndDiff, spec;
+ if (shadowMapSample > 0) {
+ dsbModel(normalize(normal.xyz), flipYTexCoord, ambientAndDiff, spec);
+ result = ambientAndDiff + spec;
+ }
+
+ // Combine spec with ambient+diffuse for final fragment color
+ fragColor = vec4(result, opacity);
+}
diff --git a/examples/qt3d/planets-qml/shaders/shadowmap.frag b/examples/qt3d/planets-qml/shaders/shadowmap.frag
new file mode 100644
index 000000000..63f203da6
--- /dev/null
+++ b/examples/qt3d/planets-qml/shaders/shadowmap.frag
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+void main()
+{
+}
diff --git a/examples/qt3d/planets-qml/shaders/shadowmap.vert b/examples/qt3d/planets-qml/shaders/shadowmap.vert
new file mode 100644
index 000000000..ca93360c6
--- /dev/null
+++ b/examples/qt3d/planets-qml/shaders/shadowmap.vert
@@ -0,0 +1,46 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+in vec3 vertexPosition;
+
+uniform mat4 mvp;
+
+void main()
+{
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}