diff options
Diffstat (limited to 'examples/qt3d')
20 files changed, 1385 insertions, 6 deletions
diff --git a/examples/qt3d/planets-qml/CMakeLists.txt b/examples/qt3d/planets-qml/CMakeLists.txt index 83e5211be..750a85096 100644 --- a/examples/qt3d/planets-qml/CMakeLists.txt +++ b/examples/qt3d/planets-qml/CMakeLists.txt @@ -90,6 +90,18 @@ set(planets-qml_resource_files "shaders/gl3/shadowmap.vert" "shaders/gl3/sun.frag" "shaders/gl3/sun.vert" + "shaders/rhi/planetD.frag" + "shaders/rhi/planetD.vert" + "shaders/rhi/planetDB.frag" + "shaders/rhi/planetDB.vert" + "shaders/rhi/planetDS.frag" + "shaders/rhi/planetDSB.frag" + "shaders/rhi/planetDShadow.frag" + "shaders/rhi/planetDShadow.vert" + "shaders/rhi/shadowmap.frag" + "shaders/rhi/shadowmap.vert" + "shaders/rhi/sun.frag" + "shaders/rhi/sun.vert" ) qt6_add_resources(planets-qml "planets-qml" diff --git a/examples/qt3d/planets-qml/PlanetEffect.qml b/examples/qt3d/planets-qml/PlanetEffect.qml index 7c8bf4948..1f7e65063 100644 --- a/examples/qt3d/planets-qml/PlanetEffect.qml +++ b/examples/qt3d/planets-qml/PlanetEffect.qml @@ -61,6 +61,8 @@ Effect { property string fragmentES: "qrc:/shaders/es2/planetD.frag" property string vertexGL: "qrc:/shaders/gl3/planetD.vert" property string fragmentGL: "qrc:/shaders/gl3/planetD.frag" + property string vertexRHI: "qrc:/shaders/rhi/planetD.vert" + property string fragmentRHI: "qrc:/shaders/rhi/planetD.frag" parameters: [ Parameter { name: "lightViewProjection"; value: root.light.lightViewProjection }, @@ -84,6 +86,17 @@ Effect { } RenderPass { + id: rhipass + filterKeys: [ forwardkey ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource(vertexRHI) + fragmentShaderCode: loadSource(fragmentRHI) + } + // no special render state set => use the default set of states + } + + RenderPass { id: espass filterKeys: [ forwardkey ] @@ -127,6 +140,17 @@ Effect { filterKeys: [ eskey ] renderPasses: [ espass ] + }, + Technique { + graphicsApiFilter { + api: GraphicsApiFilter.RHI + majorVersion: 1 + minorVersion: 0 + } + + filterKeys: [ glkey ] + + renderPasses: [ rhipass ] } ] } diff --git a/examples/qt3d/planets-qml/PlanetsMain.qml b/examples/qt3d/planets-qml/PlanetsMain.qml index 91cbfd4bd..d0ecaca57 100644 --- a/examples/qt3d/planets-qml/PlanetsMain.qml +++ b/examples/qt3d/planets-qml/PlanetsMain.qml @@ -68,7 +68,7 @@ Item { Connections { target: networkController - onCommandAccepted: { + function onCommandAccepted() { var focusedItem = mainview.Window.window.activeFocusItem if (focusedItem && focusedItem.panningEnabled) { focusedItem.panningEnabled = false @@ -224,9 +224,9 @@ Item { Component { id: planetButtonDelegate PlanetButton { - source: planetImageSource - text: name - focusPlanet: planetNumber + source: model.planetImageSource + text: model.name + focusPlanet: model.planetNumber planetSelector: mainview buttonSize: planetButtonSize fontSize: textSize diff --git a/examples/qt3d/planets-qml/ShadowEffect.qml b/examples/qt3d/planets-qml/ShadowEffect.qml index a5d414c47..362191d76 100644 --- a/examples/qt3d/planets-qml/ShadowEffect.qml +++ b/examples/qt3d/planets-qml/ShadowEffect.qml @@ -98,6 +98,34 @@ Effect { } RenderPass { + id: rhishadowpass + filterKeys: [ shadowkey ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/rhi/shadowmap.vert") + fragmentShaderCode: loadSource("qrc:/shaders/rhi/shadowmap.frag") + } + + renderStates: [ + PolygonOffset { scaleFactor: 4; depthSteps: 4 }, + DepthTest { depthFunction: DepthTest.Less } + ] + } + + + RenderPass { + id: rhipass + filterKeys: [ forwardkey ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/rhi/planetDShadow.vert") + fragmentShaderCode: loadSource("qrc:/shaders/rhi/planetDShadow.frag") + } + + // no special render state set => use the default set of states + } + + RenderPass { id: espass filterKeys: [ forwardkey ] @@ -143,6 +171,17 @@ Effect { filterKeys: [ eskey ] renderPasses: [ espass ] + }, + Technique { + graphicsApiFilter { + api: GraphicsApiFilter.RHi + majorVersion: 1 + minorVersion: 0 + } + + filterKeys: [ desktopkey ] + + renderPasses: [ rhishadowpass, rhipass ] } ] } diff --git a/examples/qt3d/planets-qml/SolarSystem.qml b/examples/qt3d/planets-qml/SolarSystem.qml index e5d8c957e..a4d90105c 100644 --- a/examples/qt3d/planets-qml/SolarSystem.qml +++ b/examples/qt3d/planets-qml/SolarSystem.qml @@ -163,6 +163,8 @@ Entity { fragmentES: "qrc:/shaders/es2/planetDB.frag" vertexGL: "qrc:/shaders/gl3/planetDB.vert" fragmentGL: "qrc:/shaders/gl3/planetDB.frag" + vertexRHI: "qrc:/shaders/rhi/planetDB.vert" + fragmentRHI: "qrc:/shaders/rhi/planetDB.frag" } PlanetEffect { @@ -172,6 +174,8 @@ Entity { fragmentES: "qrc:/shaders/es2/planetDSB.frag" vertexGL: "qrc:/shaders/gl3/planetDB.vert" fragmentGL: "qrc:/shaders/gl3/planetDSB.frag" + vertexRHI: "qrc:/shaders/rhi/planetDB.vert" + fragmentRHI: "qrc:/shaders/rhi/planetDSB.frag" } PlanetEffect { @@ -181,6 +185,8 @@ Entity { fragmentES: "qrc:/shaders/es2/planetDS.frag" vertexGL: "qrc:/shaders/gl3/planetD.vert" fragmentGL: "qrc:/shaders/gl3/planetDS.frag" + vertexRHI: "qrc:/shaders/rhi/planetD.vert" + fragmentRHI: "qrc:/shaders/rhi/planetDS.frag" } SunEffect { diff --git a/examples/qt3d/planets-qml/SunEffect.qml b/examples/qt3d/planets-qml/SunEffect.qml index 4cda00081..33370530b 100644 --- a/examples/qt3d/planets-qml/SunEffect.qml +++ b/examples/qt3d/planets-qml/SunEffect.qml @@ -72,6 +72,18 @@ Effect { } RenderPass { + id: rhipass + filterKeys: [ forwardkey ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/rhi/sun.vert") + fragmentShaderCode: loadSource("qrc:/shaders/rhi/sun.frag") + } + + // no special render state set => use the default set of states + } + + RenderPass { id: espass filterKeys: [ forwardkey ] @@ -116,6 +128,17 @@ Effect { filterKeys: [ eskey ] renderPasses: [ espass ] + }, + Technique { + graphicsApiFilter { + api: GraphicsApiFilter.RHI + majorVersion: 1 + minorVersion: 0 + } + + filterKeys: [ desktopkey ] + + renderPasses: [ rhipass ] } ] } diff --git a/examples/qt3d/planets-qml/main.cpp b/examples/qt3d/planets-qml/main.cpp index 07bfad5a2..32fca3136 100644 --- a/examples/qt3d/planets-qml/main.cpp +++ b/examples/qt3d/planets-qml/main.cpp @@ -60,7 +60,7 @@ int main(int argc, char **argv) QSurfaceFormat format; if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { - format.setVersion(3, 2); + format.setVersion(4, 5); format.setProfile(QSurfaceFormat::CoreProfile); } format.setDepthBufferSize(24); @@ -69,7 +69,6 @@ int main(int argc, char **argv) NetworkController networkController; - QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); QQuickView view; view.setFormat(format); view.rootContext()->setContextProperty("networkController", &networkController); diff --git a/examples/qt3d/planets-qml/planets-qml.qrc b/examples/qt3d/planets-qml/planets-qml.qrc index f3a34fa9f..d799fbdf0 100644 --- a/examples/qt3d/planets-qml/planets-qml.qrc +++ b/examples/qt3d/planets-qml/planets-qml.qrc @@ -38,5 +38,17 @@ <file>shaders/gl3/planetDShadow.frag</file> <file>shaders/gl3/planetDShadow.vert</file> <file>AppleTVInput.qml</file> + <file>shaders/rhi/planetD.frag</file> + <file>shaders/rhi/planetD.vert</file> + <file>shaders/rhi/planetDB.frag</file> + <file>shaders/rhi/planetDB.vert</file> + <file>shaders/rhi/planetDS.frag</file> + <file>shaders/rhi/planetDSB.frag</file> + <file>shaders/rhi/planetDShadow.frag</file> + <file>shaders/rhi/planetDShadow.vert</file> + <file>shaders/rhi/shadowmap.frag</file> + <file>shaders/rhi/shadowmap.vert</file> + <file>shaders/rhi/sun.frag</file> + <file>shaders/rhi/sun.vert</file> </qresource> </RCC> 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); +} |