diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2020-11-26 13:08:49 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2020-11-26 17:47:24 +0100 |
commit | 230a2650d713b50fbec984deddfc3741bdf51d7a (patch) | |
tree | 80287ade3b96b699d43a9ffcd061c5ef47de6c31 /examples/qt3d/planets-qml/shaders | |
parent | 9c682cf8ffe302719df1202d89e560e4fe67739d (diff) |
planet-qml example: port to RHI
Change-Id: I4246c59903a6d8f302a916ba7d19e9e37b5fe9c8
Pick-to: 6.0 6.0.0
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'examples/qt3d/planets-qml/shaders')
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/planetD.frag | 129 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/planetD.vert | 90 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/planetDB.frag | 132 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/planetDB.vert | 131 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/planetDS.frag | 129 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/planetDSB.frag | 134 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/planetDShadow.frag | 134 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/planetDShadow.vert | 99 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/shadowmap.frag | 55 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/shadowmap.vert | 68 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/sun.frag | 77 | ||||
-rw-r--r-- | examples/qt3d/planets-qml/shaders/rhi/sun.vert | 86 |
12 files changed, 1264 insertions, 0 deletions
diff --git a/examples/qt3d/planets-qml/shaders/rhi/planetD.frag b/examples/qt3d/planets-qml/shaders/rhi/planetD.frag new file mode 100644 index 000000000..554ccb559 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/planetD.frag @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core + +layout(std140, binding = 2) uniform extras_uniforms { + float texCoordScale; + vec3 ka; // Ambient reflectivity + vec3 ks; // Specular reflectivity + float shininess; // Specular shininess factor + float opacity; // Alpha channel + vec3 lightPosition; + vec3 lightIntensity; +}; + +layout(binding=3) uniform sampler2D diffuseTexture; + +layout(location=0) in vec3 position; +layout(location=1) in vec3 normal; +layout(location=2) in vec2 texCoord; + +layout(std140, binding = 0) uniform qt3d_render_view_uniforms { + mat4 viewMatrix; + mat4 projectionMatrix; + mat4 uncorrectedProjectionMatrix; + mat4 clipCorrectionMatrix; + mat4 viewProjectionMatrix; + mat4 inverseViewMatrix; + mat4 inverseProjectionMatrix; + mat4 inverseViewProjectionMatrix; + mat4 viewportMatrix; + mat4 inverseViewportMatrix; + vec4 textureTransformMatrix; + vec3 eyePosition; + float aspectRatio; + float gamma; + float exposure; + float time; +}; + +layout(location=0) 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; + + vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + result += dModel(flipYTexCoord); + + float alpha = opacity * texture(diffuseTexture, flipYTexCoord).a; + + fragColor = vec4(result, alpha); +} diff --git a/examples/qt3d/planets-qml/shaders/rhi/planetD.vert b/examples/qt3d/planets-qml/shaders/rhi/planetD.vert new file mode 100644 index 000000000..5892fffe4 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/planetD.vert @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core + +layout(location=0) in vec3 vertexPosition; +layout(location=1) in vec3 vertexNormal; +layout(location=2) in vec2 vertexTexCoord; + +layout(location=0) out vec3 position; +layout(location=1) out vec3 normal; +layout(location=2) out vec2 texCoord; + + +layout(std140, binding = 1) uniform qt3d_command_uniforms { + mat4 modelMatrix; + mat4 inverseModelMatrix; + mat4 modelViewMatrix; + mat3 modelNormalMatrix; + mat4 inverseModelViewMatrix; + mat4 modelViewProjection; + mat4 inverseModelViewProjectionMatrix; +}; + +layout(std140, binding = 2) uniform extras_uniforms { + float texCoordScale; + vec3 ka; // Ambient reflectivity + vec3 ks; // Specular reflectivity + float shininess; // Specular shininess factor + float opacity; // Alpha channel + vec3 lightPosition; + vec3 lightIntensity; +}; + +void main() +{ + texCoord = vertexTexCoord * texCoordScale; + normal = normalize(modelNormalMatrix * vertexNormal); + position = vec3(modelViewMatrix * vec4(vertexPosition, 1.0)); + + gl_Position = modelViewProjection * vec4(vertexPosition, 1.0); +} diff --git a/examples/qt3d/planets-qml/shaders/rhi/planetDB.frag b/examples/qt3d/planets-qml/shaders/rhi/planetDB.frag new file mode 100644 index 000000000..6faf05d9a --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/planetDB.frag @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core + +layout(std140, binding = 0) uniform qt3d_render_view_uniforms { + mat4 viewMatrix; + mat4 projectionMatrix; + mat4 uncorrectedProjectionMatrix; + mat4 clipCorrectionMatrix; + mat4 viewProjectionMatrix; + mat4 inverseViewMatrix; + mat4 inverseProjectionMatrix; + mat4 inverseViewProjectionMatrix; + mat4 viewportMatrix; + mat4 inverseViewportMatrix; + vec4 textureTransformMatrix; + vec3 eyePosition; + float aspectRatio; + float gamma; + float exposure; + float time; +}; + +layout(std140, binding = 2) uniform extras_uniforms { + float texCoordScale; + vec3 ka; // Ambient reflectivity + vec3 ks; // Specular reflectivity + float shininess; // Specular shininess factor + float opacity; // Alpha channel + vec3 lightPosition; + vec3 lightIntensity; +}; + +layout(binding=3) uniform sampler2D diffuseTexture; +layout(binding=4) uniform sampler2D normalTexture; + +layout(location = 0) in vec3 lightDir; +layout(location = 1) in vec3 viewDir; +layout(location = 2) in vec2 texCoord; + +layout(location = 0) 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; + + // 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; + 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/rhi/planetDB.vert b/examples/qt3d/planets-qml/shaders/rhi/planetDB.vert new file mode 100644 index 000000000..627ae0081 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/planetDB.vert @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core + +layout(location=0) in vec3 vertexPosition; +layout(location=1) in vec3 vertexNormal; +layout(location=2) in vec2 vertexTexCoord; +layout(location=3) in vec4 vertexTangent; + +layout(location=0) out vec3 lightDir; +layout(location=1) out vec3 viewDir; +layout(location=2) out vec2 texCoord; + + +layout(std140, binding = 0) uniform qt3d_render_view_uniforms { + mat4 viewMatrix; + mat4 projectionMatrix; + mat4 uncorrectedProjectionMatrix; + mat4 clipCorrectionMatrix; + mat4 viewProjectionMatrix; + mat4 inverseViewMatrix; + mat4 inverseProjectionMatrix; + mat4 inverseViewProjectionMatrix; + mat4 viewportMatrix; + mat4 inverseViewportMatrix; + vec4 textureTransformMatrix; + vec3 eyePosition; + float aspectRatio; + float gamma; + float exposure; + float time; +}; + +layout(std140, binding = 1) uniform qt3d_command_uniforms { + mat4 modelMatrix; + mat4 inverseModelMatrix; + mat4 modelViewMatrix; + mat3 modelNormalMatrix; + mat4 inverseModelViewMatrix; + mat4 modelViewProjection; + mat4 inverseModelViewProjectionMatrix; +}; + +layout(std140, binding = 2) uniform extras_uniforms { + float texCoordScale; + vec3 ka; // Ambient reflectivity + vec3 ks; // Specular reflectivity + float shininess; // Specular shininess factor + float opacity; // Alpha channel + vec3 lightPosition; + vec3 lightIntensity; +}; + +void main() +{ + // Pass through texture coordinates + texCoord = vertexTexCoord * texCoordScale; + + // Transform position, normal, and tangent to eye coords + vec3 normal = normalize(modelNormalMatrix * vertexNormal); + vec3 tangent = normalize(modelNormalMatrix * vertexTangent.xyz); + vec3 position = vec3(modelViewMatrix * 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 = modelViewProjection * vec4(vertexPosition, 1.0); +} diff --git a/examples/qt3d/planets-qml/shaders/rhi/planetDS.frag b/examples/qt3d/planets-qml/shaders/rhi/planetDS.frag new file mode 100644 index 000000000..728e22469 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/planetDS.frag @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core + +layout(std140, binding = 2) uniform extras_uniforms { + float texCoordScale; + vec3 ka; // Ambient reflectivity + vec3 ks; // Specular reflectivity + float shininess; // Specular shininess factor + float opacity; // Alpha channel + vec3 lightPosition; + vec3 lightIntensity; +}; + +layout(binding=3) uniform sampler2D diffuseTexture; +layout(binding=4) uniform sampler2D specularTexture; + +layout(location=0) in vec3 position; +layout(location=1) in vec3 normal; +layout(location=2) in vec2 texCoord; + +layout(std140, binding = 0) uniform qt3d_render_view_uniforms { + mat4 viewMatrix; + mat4 projectionMatrix; + mat4 uncorrectedProjectionMatrix; + mat4 clipCorrectionMatrix; + mat4 viewProjectionMatrix; + mat4 inverseViewMatrix; + mat4 inverseProjectionMatrix; + mat4 inverseViewProjectionMatrix; + mat4 viewportMatrix; + mat4 inverseViewportMatrix; + vec4 textureTransformMatrix; + vec3 eyePosition; + float aspectRatio; + float gamma; + float exposure; + float time; +}; + +layout(location=0) 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; + + vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + result += dsModel(flipYTexCoord); + + fragColor = vec4(result, opacity * texture(diffuseTexture, flipYTexCoord).a); +} diff --git a/examples/qt3d/planets-qml/shaders/rhi/planetDSB.frag b/examples/qt3d/planets-qml/shaders/rhi/planetDSB.frag new file mode 100644 index 000000000..78cae7b49 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/planetDSB.frag @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core + +layout(std140, binding = 0) uniform qt3d_render_view_uniforms { + mat4 viewMatrix; + mat4 projectionMatrix; + mat4 uncorrectedProjectionMatrix; + mat4 clipCorrectionMatrix; + mat4 viewProjectionMatrix; + mat4 inverseViewMatrix; + mat4 inverseProjectionMatrix; + mat4 inverseViewProjectionMatrix; + mat4 viewportMatrix; + mat4 inverseViewportMatrix; + vec4 textureTransformMatrix; + vec3 eyePosition; + float aspectRatio; + float gamma; + float exposure; + float time; +}; + +layout(std140, binding = 2) uniform extras_uniforms { + float texCoordScale; + vec3 ka; // Ambient reflectivity + vec3 ks; // Specular reflectivity + float shininess; // Specular shininess factor + float opacity; // Alpha channel + vec3 lightPosition; + vec3 lightIntensity; +}; + +layout(binding=3) uniform sampler2D diffuseTexture; +layout(binding=4) uniform sampler2D normalTexture; +layout(binding=5) uniform sampler2D specularTexture; + +layout(location = 0) in vec3 lightDir; +layout(location = 1) in vec3 viewDir; +layout(location = 2) in vec2 texCoord; + +layout(location = 0) out vec4 fragColor; + +void dsbModel(const in vec3 norm, const in vec2 flipXTexCoord, out vec3 ambientAndDiff, out vec3 spec) +{ + // Reflection of light direction about normal + vec3 r = reflect(-lightDir, norm); + + vec3 diffuseColor = texture(diffuseTexture, flipXTexCoord).rgb; + vec3 specularColor = texture(specularTexture, flipXTexCoord).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 flipXTexCoord = texCoord; + flipXTexCoord.x = 1.0 - texCoord.x; + + // Sample the textures at the interpolated texCoords + vec4 normal = 2.0 * texture(normalTexture, flipXTexCoord) - vec4(1.0); + + // Calculate the lighting model, keeping the specular component separate + vec3 ambientAndDiff, spec; + dsbModel(normalize(normal.xyz), flipXTexCoord, ambientAndDiff, spec); + vec3 result = ambientAndDiff + spec; + + // Combine spec with ambient+diffuse for final fragment color + fragColor = vec4(result, opacity); +} diff --git a/examples/qt3d/planets-qml/shaders/rhi/planetDShadow.frag b/examples/qt3d/planets-qml/shaders/rhi/planetDShadow.frag new file mode 100644 index 000000000..81f1d55e8 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/planetDShadow.frag @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core +layout(std140, binding = 0) uniform qt3d_render_view_uniforms { + mat4 viewMatrix; + mat4 projectionMatrix; + mat4 uncorrectedProjectionMatrix; + mat4 clipCorrectionMatrix; + mat4 viewProjectionMatrix; + mat4 inverseViewMatrix; + mat4 inverseProjectionMatrix; + mat4 inverseViewProjectionMatrix; + mat4 viewportMatrix; + mat4 inverseViewportMatrix; + vec4 textureTransformMatrix; + vec3 eyePosition; + float aspectRatio; + float gamma; + float exposure; + float time; +}; + +layout(std140, binding = 2) uniform extras_uniforms { + float texCoordScale; + vec3 ka; // Ambient reflectivity + vec3 ks; // Specular reflectivity + float shininess; // Specular shininess factor + float opacity; // Alpha channel + vec3 lightPosition; + vec3 lightIntensity; +}; + +layout(binding=3) uniform sampler2D diffuseTexture; +layout(binding=4) uniform sampler2DShadow shadowMapTexture; + +layout(location = 3) in vec4 positionInLightSpace; + +layout(location = 0) in vec3 position; +layout(location = 1) in vec3 normal; +layout(location = 2) in vec2 texCoord; + +layout(location = 0)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 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + 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/rhi/planetDShadow.vert b/examples/qt3d/planets-qml/shaders/rhi/planetDShadow.vert new file mode 100644 index 000000000..e748e3fbb --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/planetDShadow.vert @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core + +layout(location=0) in vec3 vertexPosition; +layout(location=1) in vec3 vertexNormal; +layout(location=2) in vec2 vertexTexCoord; + +layout(location = 3) out vec4 positionInLightSpace; + +layout(location = 0) out vec3 position; +layout(location = 1) out vec3 normal; +layout(location = 2) out vec2 texCoord; + +layout(std140, binding = 1) uniform qt3d_command_uniforms { + mat4 modelMatrix; + mat4 inverseModelMatrix; + mat4 modelViewMatrix; + mat3 modelNormalMatrix; + mat4 inverseModelViewMatrix; + mat4 modelViewProjection; + mat4 inverseModelViewProjectionMatrix; +}; + +layout(std140, binding = 2) uniform extras_uniforms { + float texCoordScale; + vec3 ka; // Ambient reflectivity + vec3 ks; // Specular reflectivity + float shininess; // Specular shininess factor + float opacity; // Alpha channel + vec3 lightPosition; + vec3 lightIntensity; + mat4 lightViewProjection; +}; + +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(modelNormalMatrix * vertexNormal); + position = vec3(modelViewMatrix * vec4(vertexPosition, 1.0)); + + gl_Position = modelViewProjection * vec4(vertexPosition, 1.0); +} diff --git a/examples/qt3d/planets-qml/shaders/rhi/shadowmap.frag b/examples/qt3d/planets-qml/shaders/rhi/shadowmap.frag new file mode 100644 index 000000000..f14de2d0b --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/shadowmap.frag @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#version 450 core + +void main() +{ +} diff --git a/examples/qt3d/planets-qml/shaders/rhi/shadowmap.vert b/examples/qt3d/planets-qml/shaders/rhi/shadowmap.vert new file mode 100644 index 000000000..e67cabd93 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/shadowmap.vert @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#version 450 core + +layout(location=0) in vec3 vertexPosition; + +layout(std140, binding = 1) uniform qt3d_command_uniforms { + mat4 modelMatrix; + mat4 inverseModelMatrix; + mat4 modelViewMatrix; + mat3 modelNormalMatrix; + mat4 inverseModelViewMatrix; + mat4 modelViewProjection; + mat4 inverseModelViewProjectionMatrix; +}; + +void main() +{ + gl_Position = modelViewProjection * vec4(vertexPosition, 1.0); +} diff --git a/examples/qt3d/planets-qml/shaders/rhi/sun.frag b/examples/qt3d/planets-qml/shaders/rhi/sun.frag new file mode 100644 index 000000000..8f68eb977 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/sun.frag @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core + +layout(binding=3) uniform sampler2D diffuseTexture; + +layout(location=0) in vec3 position; +layout(location=1) in vec2 texCoord; + +layout(location = 0) out vec4 fragColor; + +vec4 dModel(const in vec2 flipYTexCoord) +{ + // Lookup diffuse + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + + return vec4(diffuseColor, 1.0); +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + vec4 result = dModel(flipYTexCoord); + + fragColor = result; +} diff --git a/examples/qt3d/planets-qml/shaders/rhi/sun.vert b/examples/qt3d/planets-qml/shaders/rhi/sun.vert new file mode 100644 index 000000000..ed9e713df --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/rhi/sun.vert @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2017 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#version 450 core + + +layout(location=0) in vec3 vertexPosition; +layout(location=1) in vec2 vertexTexCoord; + +layout(location=0) out vec3 position; +layout(location=1) out vec2 texCoord; + +layout(std140, binding = 1) uniform qt3d_command_uniforms { + mat4 modelMatrix; + mat4 inverseModelMatrix; + mat4 modelViewMatrix; + mat3 modelNormalMatrix; + mat4 inverseModelViewMatrix; + mat4 modelViewProjection; + mat4 inverseModelViewProjectionMatrix; +}; + +layout(std140, binding = 2) uniform extras_uniforms { + float texCoordScale; + vec3 ka; // Ambient reflectivity + vec3 ks; // Specular reflectivity + float shininess; // Specular shininess factor + float opacity; // Alpha channel + vec3 lightPosition; + vec3 lightIntensity; +}; + +void main() +{ + texCoord = vertexTexCoord * texCoordScale; + position = vec3(modelViewMatrix * vec4(vertexPosition, 1.0)); + gl_Position = modelViewProjection * vec4(vertexPosition, 1.0); +} |