diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-06-26 14:39:13 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-06-27 08:46:16 +0200 |
commit | b12e28a338842e273557413b235de49ec6bb04c3 (patch) | |
tree | f0c5c82f73116a5edf1168630255e2b0194107f9 | |
parent | 8dc95e0edc71cefc6c3e5c4cc67bfe385a8a0f32 (diff) | |
parent | a2bd6a2a820fc2f2c881102f884df34a190505c7 (diff) |
Merge remote-tracking branch 'origin/5.5.0' into 5.5
Conflicts:
examples/qt3d/planets-qml/CloudEffectDS.qml
examples/qt3d/planets-qml/PlanetButton.qml
examples/qt3d/planets-qml/PlanetEffectD.qml
examples/qt3d/planets-qml/PlanetEffectDB.qml
examples/qt3d/planets-qml/PlanetEffectDS.qml
examples/qt3d/planets-qml/PlanetEffectDSB.qml
examples/qt3d/planets-qml/PlanetMaterial.qml
examples/qt3d/planets-qml/PlanetsMain.qml
examples/qt3d/planets-qml/SolarSystem.qml
examples/qt3d/planets-qml/doc/src/planets-qml.qdoc
examples/qt3d/planets-qml/main.cpp
examples/qt3d/planets-qml/planets-qml.pro
examples/qt3d/planets-qml/planets-qml.qrc
Change-Id: I9f311f3104c8fcf9d49e12b14f8bfad9ca8cf199
40 files changed, 2300 insertions, 66 deletions
diff --git a/examples/qt3d/planets-qml/CloudEffectDS.qml b/examples/qt3d/planets-qml/CloudEffectDS.qml index f3c88f058..ea043d22b 100644 --- a/examples/qt3d/planets-qml/CloudEffectDS.qml +++ b/examples/qt3d/planets-qml/CloudEffectDS.qml @@ -58,9 +58,72 @@ Effect { minorVersion: 2 } + annotations: [ Annotation { name: "name"; value: "Desktop" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/gl3/planetD.vert") + fragmentShaderCode: loadSource("qrc:/shaders/gl3/planetDS.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.Desktop + majorVersion: 2 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + renderPasses: [ RenderPass { annotations: [ Annotation { name : "pass"; value : "forward" } ] + + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/es2/planetD.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetDS.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.ES + majorVersion: 2 + minorVersion: 0 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + bindings: [ // Uniforms (those provided by the user) ParameterMapping { @@ -71,8 +134,8 @@ Effect { ] shaderProgram: ShaderProgram { - vertexShaderCode: loadSource("qrc:/shaders/planetD.vert") - fragmentShaderCode: loadSource("qrc:/shaders/planetDS.frag") + vertexShaderCode: loadSource("qrc:/shaders/es2/planetD.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetDS.frag") } // no special render state set => use the default set of states diff --git a/examples/qt3d/planets-qml/PlanetButton.qml b/examples/qt3d/planets-qml/PlanetButton.qml index f68c70052..e530312dc 100644 --- a/examples/qt3d/planets-qml/PlanetButton.qml +++ b/examples/qt3d/planets-qml/PlanetButton.qml @@ -59,7 +59,8 @@ Rectangle { hoverEnabled: true onClicked: { planetSelector.focusedPlanet = focusPlanet } onEntered: PropertyAnimation { target: planetText; property: "opacity"; to: 1 } - onExited: PropertyAnimation { target: planetText; + onExited: PropertyAnimation { + target: planetText property: "opacity" to: { if (planetText.text != "Solar System") diff --git a/examples/qt3d/planets-qml/PlanetEffectD.qml b/examples/qt3d/planets-qml/PlanetEffectD.qml index 34dab4498..e5fcc8ae0 100644 --- a/examples/qt3d/planets-qml/PlanetEffectD.qml +++ b/examples/qt3d/planets-qml/PlanetEffectD.qml @@ -60,13 +60,15 @@ Effect { minorVersion: 2 } + annotations: [ Annotation { name: "name"; value: "Desktop" } ] + renderPasses: [ RenderPass { annotations: [ Annotation { name: "pass"; value: "shadowmap" } ] shaderProgram: ShaderProgram { - vertexShaderCode: loadSource("qrc:/shaders/shadowmap.vert") - fragmentShaderCode: loadSource("qrc:/shaders/shadowmap.frag") + vertexShaderCode: loadSource("qrc:/shaders/gl3/shadowmap.vert") + fragmentShaderCode: loadSource("qrc:/shaders/gl3/shadowmap.frag") } renderStates: [ @@ -92,8 +94,79 @@ Effect { ] shaderProgram: ShaderProgram { - vertexShaderCode: loadSource("qrc:/shaders/planetD.vert") - fragmentShaderCode: loadSource("qrc:/shaders/planetD.frag") + vertexShaderCode: loadSource("qrc:/shaders/gl3/planetD.vert") + fragmentShaderCode: loadSource("qrc:/shaders/gl3/planetD.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.Desktop + majorVersion: 2 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + }, + ParameterMapping { + parameterName: "specular"; + shaderVariableName: "ks"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/es2/planetD.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetD.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.ES + majorVersion: 2 + minorVersion: 0 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + }, + ParameterMapping { + parameterName: "specular"; + shaderVariableName: "ks"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/es2/planetD.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetD.frag") } // no special render state set => use the default set of states diff --git a/examples/qt3d/planets-qml/PlanetEffectDB.qml b/examples/qt3d/planets-qml/PlanetEffectDB.qml index dc261582d..ad9d2035e 100644 --- a/examples/qt3d/planets-qml/PlanetEffectDB.qml +++ b/examples/qt3d/planets-qml/PlanetEffectDB.qml @@ -60,13 +60,15 @@ Effect { minorVersion: 2 } + annotations: [ Annotation { name: "name"; value: "Desktop" } ] + renderPasses: [ RenderPass { annotations: [ Annotation { name: "pass"; value: "shadowmap" } ] shaderProgram: ShaderProgram { - vertexShaderCode: loadSource("qrc:/shaders/shadowmap.vert") - fragmentShaderCode: loadSource("qrc:/shaders/shadowmap.frag") + vertexShaderCode: loadSource("qrc:/shaders/gl3/shadowmap.vert") + fragmentShaderCode: loadSource("qrc:/shaders/gl3/shadowmap.frag") } renderStates: [ @@ -92,8 +94,79 @@ Effect { ] shaderProgram: ShaderProgram { - vertexShaderCode: loadSource("qrc:/shaders/planetDB.vert") - fragmentShaderCode: loadSource("qrc:/shaders/planetDB.frag") + vertexShaderCode: loadSource("qrc:/shaders/gl3/planetDB.vert") + fragmentShaderCode: loadSource("qrc:/shaders/gl3/planetDB.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.Desktop + majorVersion: 2 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + }, + ParameterMapping { + parameterName: "specular"; + shaderVariableName: "ks"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/es2/planetDB.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetDB.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.ES + majorVersion: 2 + minorVersion: 0 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + }, + ParameterMapping { + parameterName: "specular"; + shaderVariableName: "ks"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/es2/planetDB.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetDB.frag") } // no special render state set => use the default set of states diff --git a/examples/qt3d/planets-qml/PlanetEffectDS.qml b/examples/qt3d/planets-qml/PlanetEffectDS.qml index f1b2a2e2d..1d3512d86 100644 --- a/examples/qt3d/planets-qml/PlanetEffectDS.qml +++ b/examples/qt3d/planets-qml/PlanetEffectDS.qml @@ -60,13 +60,15 @@ Effect { minorVersion: 2 } + annotations: [ Annotation { name: "name"; value: "Desktop" } ] + renderPasses: [ RenderPass { annotations: [ Annotation { name: "pass"; value: "shadowmap" } ] shaderProgram: ShaderProgram { - vertexShaderCode: loadSource("qrc:/shaders/shadowmap.vert") - fragmentShaderCode: loadSource("qrc:/shaders/shadowmap.frag") + vertexShaderCode: loadSource("qrc:/shaders/gl3/shadowmap.vert") + fragmentShaderCode: loadSource("qrc:/shaders/gl3/shadowmap.frag") } renderStates: [ @@ -87,8 +89,69 @@ Effect { ] shaderProgram: ShaderProgram { - vertexShaderCode: loadSource("qrc:/shaders/planetD.vert") - fragmentShaderCode: loadSource("qrc:/shaders/planetDS.frag") + vertexShaderCode: loadSource("qrc:/shaders/gl3/planetD.vert") + fragmentShaderCode: loadSource("qrc:/shaders/gl3/planetDS.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.Desktop + majorVersion: 2 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/es2/planetD.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetDS.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.ES + majorVersion: 2 + minorVersion: 0 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/es2/planetD.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetDS.frag") } // no special render state set => use the default set of states diff --git a/examples/qt3d/planets-qml/PlanetEffectDSB.qml b/examples/qt3d/planets-qml/PlanetEffectDSB.qml index 58a1d1d80..78b00bd32 100644 --- a/examples/qt3d/planets-qml/PlanetEffectDSB.qml +++ b/examples/qt3d/planets-qml/PlanetEffectDSB.qml @@ -60,13 +60,15 @@ Effect { minorVersion: 2 } + annotations: [ Annotation { name: "name"; value: "Desktop" } ] + renderPasses: [ RenderPass { annotations: [ Annotation { name: "pass"; value: "shadowmap" } ] shaderProgram: ShaderProgram { - vertexShaderCode: loadSource("qrc:/shaders/shadowmap.vert") - fragmentShaderCode: loadSource("qrc:/shaders/shadowmap.frag") + vertexShaderCode: loadSource("qrc:/shaders/gl3/shadowmap.vert") + fragmentShaderCode: loadSource("qrc:/shaders/gl3/shadowmap.frag") } renderStates: [ @@ -87,8 +89,69 @@ Effect { ] shaderProgram: ShaderProgram { - vertexShaderCode: loadSource("qrc:/shaders/planetDB.vert") - fragmentShaderCode: loadSource("qrc:/shaders/planetDSB.frag") + vertexShaderCode: loadSource("qrc:/shaders/gl3/planetDB.vert") + fragmentShaderCode: loadSource("qrc:/shaders/gl3/planetDSB.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.Desktop + majorVersion: 2 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/es2/planetDB.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetDSB.frag") + } + + // no special render state set => use the default set of states + } + ] + }, + Technique { + openGLFilter { + api: OpenGLFilter.ES + majorVersion: 2 + minorVersion: 0 + } + + annotations: [ Annotation { name: "name"; value: "ES2" } ] + + renderPasses: [ + RenderPass { + annotations: [ Annotation { name : "pass"; value : "forward" } ] + + bindings: [ + // Uniforms (those provided by the user) + ParameterMapping { + parameterName: "ambient"; + shaderVariableName: "ka"; + bindingType: ParameterMapping.Uniform + } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/es2/planetDB.vert") + fragmentShaderCode: loadSource("qrc:/shaders/es2/planetDSB.frag") } // no special render state set => use the default set of states diff --git a/examples/qt3d/planets-qml/PlanetFrameGraph.qml b/examples/qt3d/planets-qml/PlanetFrameGraph.qml new file mode 100644 index 000000000..6034505d2 --- /dev/null +++ b/examples/qt3d/planets-qml/PlanetFrameGraph.qml @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D 2.0 +import Qt3D.Renderer 2.0 + +FrameGraph { + id: root + + property alias viewCamera: viewCameraSelector.camera + property alias lightCamera: lightCameraSelector.camera + readonly property Texture2D shadowTexture: depthTexture + + activeFrameGraph: Viewport { + rect: Qt.rect(0.0, 0.0, 1.0, 1.0) + clearColor: Qt.rgba(0.0, 0.0, 0.0, 1.0) + + TechniqueFilter { + requires: [ Annotation { name: "name"; value: "Desktop" } ] + + RenderPassFilter { + includes: [ Annotation { name: "pass"; value: "shadowmap" } ] + + RenderTargetSelector { + target: RenderTarget { + attachments: [ + RenderAttachment { + name: "depth" + type: RenderAttachment.DepthAttachment + texture: Texture2D { + id: depthTexture + width: mainview.width + height: mainview.height + format: Texture.D24 + generateMipMaps: false + magnificationFilter: Texture.Nearest + minificationFilter: Texture.Nearest + wrapMode { + x: WrapMode.ClampToEdge + y: WrapMode.ClampToEdge + } + comparisonFunction: Texture.CompareLessEqual + comparisonMode: Texture.CompareRefToTexture + } + } + ] + } + + ClearBuffer { + buffers: ClearBuffer.DepthBuffer + + CameraSelector { + id: lightCameraSelector + } + } + } + } + } + + RenderPassFilter { + includes: [ Annotation { name: "pass"; value: "forward" } ] + + ClearBuffer { + buffers: ClearBuffer.ColorDepthBuffer + + CameraSelector { + id: viewCameraSelector + } + } + } + } +} diff --git a/examples/qt3d/planets-qml/PlanetMaterial.qml b/examples/qt3d/planets-qml/PlanetMaterial.qml index 25f7da09d..e754394b0 100644 --- a/examples/qt3d/planets-qml/PlanetMaterial.qml +++ b/examples/qt3d/planets-qml/PlanetMaterial.qml @@ -53,19 +53,19 @@ Material { parameters: [ Parameter { - name: "ambient"; + name: "ambient" value: Qt.vector3d(root.ambientLight.r, root.ambientLight.g, root.ambientLight.b) }, Parameter { - name: "diffuse"; + name: "diffuse" value: Qt.vector3d(root.diffuseColor.r, root.diffuseColor.g, root.diffuseColor.b) }, Parameter { - name: "specular"; + name: "specular" value: Qt.vector3d(root.specularColor.r, root.specularColor.g, root.specularColor.b) }, Parameter { - name: "shininess"; + name: "shininess" value: root.shininess }, Parameter { @@ -80,10 +80,11 @@ Material { } generateMipMaps: true maximumAnisotropy: 16.0 - TextureImage { id: diffuseTextureImage; } + TextureImage { id: diffuseTextureImage } } }, - Parameter { name: "specularTexture"; + Parameter { + name: "specularTexture" value: Texture2D { id: specularTexture minificationFilter: Texture.LinearMipMapLinear @@ -94,10 +95,11 @@ Material { } generateMipMaps: true maximumAnisotropy: 16.0 - TextureImage { id: specularTextureImage; } + TextureImage { id: specularTextureImage } } }, - Parameter { name: "normalTexture"; + Parameter { + name: "normalTexture" value: Texture2D { id: normalTexture minificationFilter: Texture.Linear @@ -107,15 +109,15 @@ Material { y: WrapMode.Repeat } maximumAnisotropy: 16.0 - TextureImage { id: normalTextureImage; } + TextureImage { id: normalTextureImage } } }, Parameter { - name: "texCoordScale"; + name: "texCoordScale" value: textureScale }, Parameter { - name: "opacity"; + name: "opacity" value: opacity } ] diff --git a/examples/qt3d/planets-qml/PlanetsMain.qml b/examples/qt3d/planets-qml/PlanetsMain.qml index 84705e696..f72c93715 100644 --- a/examples/qt3d/planets-qml/PlanetsMain.qml +++ b/examples/qt3d/planets-qml/PlanetsMain.qml @@ -55,7 +55,6 @@ Item { anchors.fill: parent anchors.margins: 10 focus: true - aspects: "input" SolarSystem { id: solarsystem } } @@ -64,18 +63,13 @@ Item { MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton - onClicked: { - solarsystem.setFreeCamera(false) + onClicked: focusedPlanet = 100 - } - onDoubleClicked: - solarsystem.setFreeCamera(true) } } //! [1] onFocusedPlanetChanged: { - solarsystem.setFreeCamera(false) if (focusedPlanet == 100) { info.opacity = 0 updatePlanetInfo() diff --git a/examples/qt3d/planets-qml/SolarSystem.qml b/examples/qt3d/planets-qml/SolarSystem.qml index 328f41c1b..515e2d8d7 100644 --- a/examples/qt3d/planets-qml/SolarSystem.qml +++ b/examples/qt3d/planets-qml/SolarSystem.qml @@ -44,7 +44,6 @@ Entity { id: sceneRoot property bool ready: false - property bool freeCamera: false property real cameraNear: 0 property real xLookAtOffset: 0 @@ -120,7 +119,7 @@ Entity { } components: [ - ShadowMapFrameGraph { + PlanetFrameGraph { id: framegraph viewCamera: camera lightCamera: light.lightCamera @@ -231,10 +230,6 @@ Entity { checkScaling(focusedPlanet) } - function setFreeCamera(free) { - freeCamera = free - } - function setScale(value, focused) { // Save actual scale if (!focused) @@ -414,7 +409,7 @@ Entity { //! [3] function animate(focusedPlanet) { - if (!ready || freeCamera) + if (!ready) return advanceTime(focusedPlanet) diff --git a/examples/qt3d/planets-qml/android/AndroidManifest.xml b/examples/qt3d/planets-qml/android/AndroidManifest.xml new file mode 100644 index 000000000..0c768c546 --- /dev/null +++ b/examples/qt3d/planets-qml/android/AndroidManifest.xml @@ -0,0 +1,56 @@ +<?xml version="1.0"?> +<manifest package="org.qtproject.planets.qml" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto"> + <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:icon="@drawable/icon"> + <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/> + <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/> + <meta-data android:name="android.app.repository" android:value="default"/> + <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/> + <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/> + <!-- Deploy Qt libs as part of package --> + <meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/> + <meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/> + <meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/> + <!-- Run with local libs --> + <meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/> + <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/> + <meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/> + <meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/> + <meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/> + <!-- Messages maps --> + <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/> + <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/> + <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/> + <!-- Messages maps --> + + <!-- Splash screen --> + <!-- + <meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/> + --> + <!-- Splash screen --> + + <!-- Background running --> + <!-- Warning: changing this value to true may cause unexpected crashes if the + application still try to draw after + "applicationStateChanged(Qt::ApplicationSuspended)" + signal is sent! --> + <meta-data android:name="android.app.background_running" android:value="false"/> + <!-- Background running --> + </activity> + </application> + <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/> + <supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/> + + <!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application. + Remove the comment if you do not require these default permissions. --> + <!-- %%INSERT_PERMISSIONS --> + + <!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application. + Remove the comment if you do not require these default features. --> + <!-- %%INSERT_FEATURES --> + +</manifest> diff --git a/examples/qt3d/planets-qml/android/res/drawable-hdpi/icon.png b/examples/qt3d/planets-qml/android/res/drawable-hdpi/icon.png Binary files differnew file mode 100644 index 000000000..c62530326 --- /dev/null +++ b/examples/qt3d/planets-qml/android/res/drawable-hdpi/icon.png diff --git a/examples/qt3d/planets-qml/android/res/drawable-ldpi/icon.png b/examples/qt3d/planets-qml/android/res/drawable-ldpi/icon.png Binary files differnew file mode 100644 index 000000000..c62530326 --- /dev/null +++ b/examples/qt3d/planets-qml/android/res/drawable-ldpi/icon.png diff --git a/examples/qt3d/planets-qml/android/res/drawable-mdpi/icon.png b/examples/qt3d/planets-qml/android/res/drawable-mdpi/icon.png Binary files differnew file mode 100644 index 000000000..c62530326 --- /dev/null +++ b/examples/qt3d/planets-qml/android/res/drawable-mdpi/icon.png diff --git a/examples/qt3d/planets-qml/main.cpp b/examples/qt3d/planets-qml/main.cpp index 2d38334e0..02c43181f 100644 --- a/examples/qt3d/planets-qml/main.cpp +++ b/examples/qt3d/planets-qml/main.cpp @@ -36,13 +36,22 @@ #include <QGuiApplication> #include <QQuickView> +#include <QOpenGLContext> int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickView view; + QSurfaceFormat format; + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { + format.setVersion(3, 2); + format.setProfile(QSurfaceFormat::CoreProfile); + } + format.setDepthBufferSize(24); + format.setSamples(4); + QQuickView view; + view.setFormat(format); view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:/PlanetsMain.qml")); view.show(); diff --git a/examples/qt3d/planets-qml/planets-qml.pro b/examples/qt3d/planets-qml/planets-qml.pro index 7c27fc579..58a8b30fd 100644 --- a/examples/qt3d/planets-qml/planets-qml.pro +++ b/examples/qt3d/planets-qml/planets-qml.pro @@ -2,7 +2,7 @@ error( "Couldn't find the examples.pri file!" ) } -QT += qml quick 3dinput +QT += qml quick SOURCES += \ main.cpp @@ -10,7 +10,8 @@ SOURCES += \ OTHER_FILES += \ *.qml \ planets.js \ - shaders/*.* \ + shaders/gl3/*.* \ + shaders/es2/*.* \ doc/src/*.* \ doc/images/*.* @@ -19,4 +20,7 @@ RESOURCES += \ planets-qml-images.qrc DISTFILES += \ - PlanetsMain.qml + PlanetsMain.qml \ + android/AndroidManifest.xml + +ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android diff --git a/examples/qt3d/planets-qml/planets-qml.qrc b/examples/qt3d/planets-qml/planets-qml.qrc index f8efcbd44..04a67b7d7 100644 --- a/examples/qt3d/planets-qml/planets-qml.qrc +++ b/examples/qt3d/planets-qml/planets-qml.qrc @@ -15,17 +15,23 @@ <file>PlanetEffectDS.qml</file> <file>PlanetEffectDSB.qml</file> <file>PlanetMaterial.qml</file> - <file>ShadowMapFrameGraph.qml</file> + <file>PlanetFrameGraph.qml</file> <file>planets.js</file> <file>meshes/starfield.obj</file> <file>meshes/ring.obj</file> - <file>shaders/shadowmap.frag</file> - <file>shaders/shadowmap.vert</file> - <file>shaders/planetD.frag</file> - <file>shaders/planetD.vert</file> - <file>shaders/planetDB.frag</file> - <file>shaders/planetDB.vert</file> - <file>shaders/planetDS.frag</file> - <file>shaders/planetDSB.frag</file> + <file>shaders/gl3/shadowmap.frag</file> + <file>shaders/gl3/shadowmap.vert</file> + <file>shaders/gl3/planetD.frag</file> + <file>shaders/gl3/planetD.vert</file> + <file>shaders/gl3/planetDB.frag</file> + <file>shaders/gl3/planetDB.vert</file> + <file>shaders/gl3/planetDS.frag</file> + <file>shaders/gl3/planetDSB.frag</file> + <file>shaders/es2/planetD.frag</file> + <file>shaders/es2/planetD.vert</file> + <file>shaders/es2/planetDB.frag</file> + <file>shaders/es2/planetDB.vert</file> + <file>shaders/es2/planetDS.frag</file> + <file>shaders/es2/planetDSB.frag</file> </qresource> </RCC> diff --git a/examples/qt3d/planets-qml/shaders/es2/planetD.frag b/examples/qt3d/planets-qml/shaders/es2/planetD.frag new file mode 100644 index 000000000..6df16b5b4 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/es2/planetD.frag @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +uniform highp mat4 viewMatrix; + +uniform highp vec3 lightPosition; +uniform highp vec3 lightIntensity; + +uniform highp vec3 ka; // Ambient reflectivity +uniform highp vec3 ks; // Specular reflectivity +uniform highp float shininess; // Specular shininess factor +uniform highp float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; + +varying highp vec4 positionInLightSpace; + +varying highp vec3 position; +varying highp vec3 normal; +varying highp vec2 texCoord; + +highp vec3 dModel(const highp vec2 flipYTexCoord) +{ + // Calculate the vector from the light to the fragment + highp 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) + highp vec3 v = normalize(-position); + + // Reflect the light beam using the normal at this fragment + highp vec3 r = reflect(-s, normal); + + // Calculate the diffuse component + highp float diffuse = max(dot(s, normal), 0.0); + + // Calculate the specular component + highp 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 + highp vec3 diffuseColor = texture2D(diffuseTexture, flipYTexCoord).rgb; + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ((ka + diffuse) * diffuseColor + specular * ks); +} + +void main() +{ + highp vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + highp vec3 result = dModel(flipYTexCoord); + + highp float alpha = opacity * texture2D(diffuseTexture, flipYTexCoord).a; + + gl_FragColor = vec4(result, alpha); +} diff --git a/examples/qt3d/planets-qml/shaders/es2/planetD.vert b/examples/qt3d/planets-qml/shaders/es2/planetD.vert new file mode 100644 index 000000000..12f19768c --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/es2/planetD.vert @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +attribute vec3 vertexPosition; +attribute vec3 vertexNormal; +attribute vec2 vertexTexCoord; + +varying vec4 positionInLightSpace; +varying vec3 position; +varying vec3 normal; +varying vec2 texCoord; + +uniform mat4 lightViewProjection; +uniform mat4 modelMatrix; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +uniform float texCoordScale; + +void main() +{ + const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0); + + positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0); + + texCoord = vertexTexCoord * texCoordScale; + normal = normalize(modelViewNormal * vertexNormal); + position = vec3(modelView * vec4(vertexPosition, 1.0)); + + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/examples/qt3d/planets-qml/shaders/es2/planetDB.frag b/examples/qt3d/planets-qml/shaders/es2/planetDB.frag new file mode 100644 index 000000000..0a2cc87ee --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/es2/planetDB.frag @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +uniform highp mat4 viewMatrix; + +uniform highp vec3 lightPosition; +uniform highp vec3 lightIntensity; + +uniform highp vec3 ka; // Ambient reflectivity +uniform highp vec3 ks; // Specular reflectivity +uniform highp float shininess; // Specular shininess factor +uniform highp float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; +uniform sampler2D normalTexture; + +varying highp vec4 positionInLightSpace; + +varying highp vec3 lightDir; +varying highp vec3 viewDir; +varying highp vec2 texCoord; + +highp vec3 dbModel(const highp vec3 norm, const highp vec2 flipYTexCoord) +{ + // Reflection of light direction about normal + highp vec3 r = reflect(-lightDir, norm); + + highp vec3 diffuseColor = texture2D(diffuseTexture, flipYTexCoord).rgb; + + // Calculate the ambient contribution + highp vec3 ambient = lightIntensity * ka * diffuseColor; + + // Calculate the diffuse contribution + highp float sDotN = max(dot(lightDir, norm), 0.0); + highp vec3 diffuse = lightIntensity * diffuseColor * sDotN; + + // Calculate the specular highlight contribution + highp vec3 specular = vec3(0.0); + if (sDotN > 0.0) + specular = (lightIntensity * ks) * pow(max(dot(r, viewDir), 0.0), shininess); + + return ambient + diffuse + specular; +} + +void main() +{ + highp vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + highp vec4 normal = 2.0 * texture2D(normalTexture, flipYTexCoord) - vec4(1.0); + + highp vec3 result = dbModel(normalize(normal.xyz), flipYTexCoord); + + gl_FragColor = vec4(result, opacity); +} diff --git a/examples/qt3d/planets-qml/shaders/es2/planetDB.vert b/examples/qt3d/planets-qml/shaders/es2/planetDB.vert new file mode 100644 index 000000000..423e337c9 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/es2/planetDB.vert @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +attribute vec3 vertexPosition; +attribute vec3 vertexNormal; +attribute vec2 vertexTexCoord; +attribute vec4 vertexTangent; + +varying vec4 positionInLightSpace; +varying vec3 lightDir; +varying vec3 viewDir; +varying vec2 texCoord; + +uniform mat4 viewMatrix; +uniform mat4 lightViewProjection; +uniform mat4 modelMatrix; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +uniform float texCoordScale; + +uniform vec3 lightPosition; + +void main() +{ + const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0); + + positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0); + + // Pass through texture coordinates + texCoord = vertexTexCoord * texCoordScale; + + // Transform position, normal, and tangent to eye coords + vec3 normal = normalize(modelViewNormal * vertexNormal); + vec3 tangent = normalize(modelViewNormal * vertexTangent.xyz); + vec3 position = vec3(modelView * vec4(vertexPosition, 1.0)); + + // Calculate binormal vector + vec3 binormal = normalize(cross(normal, tangent)); + + // Construct matrix to transform from eye coords to tangent space + mat3 tangentMatrix = mat3 ( + tangent.x, binormal.x, normal.x, + tangent.y, binormal.y, normal.y, + tangent.z, binormal.z, normal.z); + + // Transform light direction and view direction to tangent space + vec3 s = lightPosition - position; + lightDir = normalize(tangentMatrix * vec3(viewMatrix * vec4(s, 1.0))); + + vec3 v = -position; + viewDir = normalize(tangentMatrix * v); + + // Calculate vertex position in clip coordinates + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/examples/qt3d/planets-qml/shaders/es2/planetDS.frag b/examples/qt3d/planets-qml/shaders/es2/planetDS.frag new file mode 100644 index 000000000..9b35ce10c --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/es2/planetDS.frag @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +uniform highp mat4 viewMatrix; + +uniform highp vec3 lightPosition; +uniform highp vec3 lightIntensity; + +uniform highp vec3 ka; // Ambient reflectivity +uniform highp float shininess; // Specular shininess factor +uniform highp float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; +uniform sampler2D specularTexture; + +varying highp vec4 positionInLightSpace; + +varying highp vec3 position; +varying highp vec3 normal; +varying highp vec2 texCoord; + +highp vec3 dsModel(const highp vec2 flipYTexCoord) +{ + // Calculate the vector from the light to the fragment + highp 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) + highp vec3 v = normalize(-position); + + // Reflect the light beam using the normal at this fragment + highp vec3 r = reflect(-s, normal); + + // Calculate the diffuse component + highp float diffuse = max(dot(s, normal), 0.0); + + // Calculate the specular component + highp 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 + highp vec3 diffuseColor = texture2D(diffuseTexture, flipYTexCoord).rgb; + highp vec3 specularColor = texture2D(specularTexture, flipYTexCoord).rgb; + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ((ka + diffuse) * diffuseColor + specular * specularColor); +} + +void main() +{ + highp vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + highp vec3 result = dsModel(flipYTexCoord); + + highp float alpha = opacity * texture2D(diffuseTexture, flipYTexCoord).a; + + gl_FragColor = vec4(result, alpha); +} diff --git a/examples/qt3d/planets-qml/shaders/es2/planetDSB.frag b/examples/qt3d/planets-qml/shaders/es2/planetDSB.frag new file mode 100644 index 000000000..cbbdae353 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/es2/planetDSB.frag @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +uniform highp mat4 viewMatrix; + +uniform highp vec3 lightPosition; +uniform highp vec3 lightIntensity; + +uniform highp vec3 ka; // Ambient reflectivity +uniform highp float shininess; // Specular shininess factor +uniform highp float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; +uniform sampler2D specularTexture; +uniform sampler2D normalTexture; + +varying highp vec4 positionInLightSpace; + +varying highp vec3 lightDir; +varying highp vec3 viewDir; +varying highp vec2 texCoord; + +highp vec3 dsbModel(const highp vec3 norm, const highp vec2 flipYTexCoord) +{ + // Reflection of light direction about normal + highp vec3 r = reflect(-lightDir, norm); + + highp vec3 diffuseColor = texture2D(diffuseTexture, flipYTexCoord).rgb; + highp vec3 specularColor = texture2D(specularTexture, flipYTexCoord).rgb; + + // Calculate the ambient contribution + highp vec3 ambient = lightIntensity * ka * diffuseColor; + + // Calculate the diffuse contribution + highp float sDotN = max(dot(lightDir, norm), 0.0); + highp vec3 diffuse = lightIntensity * diffuseColor * sDotN; + + // Calculate the specular highlight contribution + highp vec3 specular = vec3(0.0); + if (sDotN > 0.0) + specular = (lightIntensity * (shininess / (8.0 * 3.14))) * pow(max(dot(r, viewDir), 0.0), shininess); + + specular *= specularColor; + + return ambient + diffuse + specular; +} + +void main() +{ + highp vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + // Sample the textures at the interpolated texCoords + highp vec4 normal = 2.0 * texture2D(normalTexture, flipYTexCoord) - vec4(1.0); + + highp vec3 result = dsbModel(normalize(normal.xyz), flipYTexCoord); + + // Combine spec with ambient+diffuse for final fragment color + gl_FragColor = vec4(result, opacity); +} diff --git a/examples/qt3d/planets-qml/shaders/gl3/planetD.frag b/examples/qt3d/planets-qml/shaders/gl3/planetD.frag new file mode 100644 index 000000000..62d941d25 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/gl3/planetD.frag @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#version 150 core + +uniform mat4 viewMatrix; + +uniform vec3 lightPosition; +uniform vec3 lightIntensity; + +uniform vec3 ka; // Ambient reflectivity +uniform vec3 ks; // Specular reflectivity +uniform float shininess; // Specular shininess factor +uniform float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; + +uniform sampler2DShadow shadowMapTexture; + +in vec4 positionInLightSpace; + +in vec3 position; +in vec3 normal; +in vec2 texCoord; + +out vec4 fragColor; + +vec3 dModel(const in vec2 flipYTexCoord) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - position); + + // Calculate the vector from the fragment to the eye position + // (origin since this is in "eye" or "camera" space) + vec3 v = normalize(-position); + + // Reflect the light beam using the normal at this fragment + vec3 r = reflect(-s, normal); + + // Calculate the diffuse component + float diffuse = max(dot(s, normal), 0.0); + + // Calculate the specular component + float specular = 0.0; + if (dot(s, normal) > 0.0) + specular = (shininess / (8.0 * 3.14)) * pow(max(dot(r, v), 0.0), shininess); + + // Lookup diffuse and specular factors + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ((ka + diffuse) * diffuseColor + specular * ks); +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace); + + vec3 ambient = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + + vec3 result = ambient; + if (shadowMapSample > 0) + result = dModel(flipYTexCoord); + + float alpha = opacity * texture(diffuseTexture, flipYTexCoord).a; + + fragColor = vec4(result, alpha); +} diff --git a/examples/qt3d/planets-qml/shaders/gl3/planetD.vert b/examples/qt3d/planets-qml/shaders/gl3/planetD.vert new file mode 100644 index 000000000..41a1db6e4 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/gl3/planetD.vert @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#version 150 core + +in vec3 vertexPosition; +in vec3 vertexNormal; +in vec2 vertexTexCoord; + +out vec4 positionInLightSpace; +out vec3 position; +out vec3 normal; +out vec2 texCoord; + +uniform mat4 lightViewProjection; +uniform mat4 modelMatrix; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +uniform float texCoordScale; + +void main() +{ + const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0); + + positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0); + + texCoord = vertexTexCoord * texCoordScale; + normal = normalize(modelViewNormal * vertexNormal); + position = vec3(modelView * vec4(vertexPosition, 1.0)); + + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/examples/qt3d/planets-qml/shaders/gl3/planetDB.frag b/examples/qt3d/planets-qml/shaders/gl3/planetDB.frag new file mode 100644 index 000000000..bf53a127b --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/gl3/planetDB.frag @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#version 150 core + +uniform mat4 viewMatrix; + +uniform vec3 lightPosition; +uniform vec3 lightIntensity; + +uniform vec3 ka; // Ambient reflectivity +uniform vec3 ks; // Specular reflectivity +uniform float shininess; // Specular shininess factor +uniform float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; +uniform sampler2D normalTexture; + +uniform sampler2DShadow shadowMapTexture; + +in vec4 positionInLightSpace; + +in vec3 lightDir; +in vec3 viewDir; +in vec2 texCoord; + +out vec4 fragColor; + +void dbModel(const in vec3 norm, const in vec2 flipYTexCoord, out vec3 ambientAndDiff, out vec3 spec) +{ + // Reflection of light direction about normal + vec3 r = reflect(-lightDir, norm); + + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + + // Calculate the ambient contribution + vec3 ambient = lightIntensity * ka * diffuseColor; + + // Calculate the diffuse contribution + float sDotN = max(dot(lightDir, norm), 0.0); + vec3 diffuse = lightIntensity * diffuseColor * sDotN; + + // Sum the ambient and diffuse contributions + ambientAndDiff = ambient + diffuse; + + // Calculate the specular highlight contribution + spec = vec3(0.0); + if (sDotN > 0.0) + spec = (lightIntensity * ks) * pow(max(dot(r, viewDir), 0.0), shininess); +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace); + + // Sample the textures at the interpolated texCoords + vec4 normal = 2.0 * texture(normalTexture, flipYTexCoord) - vec4(1.0); + + vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + + // Calculate the lighting model, keeping the specular component separate + vec3 ambientAndDiff, spec; + if (shadowMapSample > 0) { + dbModel(normalize(normal.xyz), flipYTexCoord, ambientAndDiff, spec); + result = ambientAndDiff + spec; + } + + // Combine spec with ambient+diffuse for final fragment color + fragColor = vec4(result, opacity); +} diff --git a/examples/qt3d/planets-qml/shaders/gl3/planetDB.vert b/examples/qt3d/planets-qml/shaders/gl3/planetDB.vert new file mode 100644 index 000000000..e30394aa3 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/gl3/planetDB.vert @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#version 150 core + +in vec3 vertexPosition; +in vec3 vertexNormal; +in vec2 vertexTexCoord; +in vec4 vertexTangent; + +out vec4 positionInLightSpace; +out vec3 lightDir; +out vec3 viewDir; +out vec2 texCoord; + +uniform mat4 viewMatrix; +uniform mat4 lightViewProjection; +uniform mat4 modelMatrix; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +uniform float texCoordScale; + +uniform vec3 lightPosition; + +void main() +{ + const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0); + + positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0); + + // Pass through texture coordinates + texCoord = vertexTexCoord * texCoordScale; + + // Transform position, normal, and tangent to eye coords + vec3 normal = normalize(modelViewNormal * vertexNormal); + vec3 tangent = normalize(modelViewNormal * vertexTangent.xyz); + vec3 position = vec3(modelView * vec4(vertexPosition, 1.0)); + + // Calculate binormal vector + vec3 binormal = normalize(cross(normal, tangent)); + + // Construct matrix to transform from eye coords to tangent space + mat3 tangentMatrix = mat3 ( + tangent.x, binormal.x, normal.x, + tangent.y, binormal.y, normal.y, + tangent.z, binormal.z, normal.z); + + // Transform light direction and view direction to tangent space + vec3 s = lightPosition - position; + lightDir = normalize(tangentMatrix * vec3(viewMatrix * vec4(s, 1.0))); + + vec3 v = -position; + viewDir = normalize(tangentMatrix * v); + + // Calculate vertex position in clip coordinates + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/examples/qt3d/planets-qml/shaders/gl3/planetDS.frag b/examples/qt3d/planets-qml/shaders/gl3/planetDS.frag new file mode 100644 index 000000000..2a1b78bfa --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/gl3/planetDS.frag @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#version 150 core + +uniform mat4 viewMatrix; + +uniform vec3 lightPosition; +uniform vec3 lightIntensity; + +uniform vec3 ka; // Ambient reflectivity +uniform float shininess; // Specular shininess factor +uniform float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; +uniform sampler2D specularTexture; + +uniform sampler2DShadow shadowMapTexture; + +in vec4 positionInLightSpace; + +in vec3 position; +in vec3 normal; +in vec2 texCoord; + +out vec4 fragColor; + +vec3 dsModel(const in vec2 flipYTexCoord) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - position); + + // Calculate the vector from the fragment to the eye position + // (origin since this is in "eye" or "camera" space) + vec3 v = normalize(-position); + + // Reflect the light beam using the normal at this fragment + vec3 r = reflect(-s, normal); + + // Calculate the diffuse component + float diffuse = max(dot(s, normal), 0.0); + + // Calculate the specular component + float specular = 0.0; + if (dot(s, normal) > 0.0) + specular = (shininess / (8.0 * 3.14)) * pow(max(dot(r, v), 0.0), shininess); + + // Lookup diffuse and specular factors + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + vec3 specularColor = texture(specularTexture, flipYTexCoord).rgb; + + // Combine the ambient, diffuse and specular contributions + return lightIntensity * ((ka + diffuse) * diffuseColor + specular * specularColor); +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace); + + vec3 ambient = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + + vec3 result = ambient; + if (shadowMapSample > 0) + result = dsModel(flipYTexCoord); + + fragColor = vec4(result, opacity * texture(diffuseTexture, flipYTexCoord).a); +} diff --git a/examples/qt3d/planets-qml/shaders/gl3/planetDSB.frag b/examples/qt3d/planets-qml/shaders/gl3/planetDSB.frag new file mode 100644 index 000000000..deb9565d4 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/gl3/planetDSB.frag @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#version 150 core + +uniform mat4 viewMatrix; + +uniform vec3 lightPosition; +uniform vec3 lightIntensity; + +uniform vec3 ka; // Ambient reflectivity +uniform float shininess; // Specular shininess factor +uniform float opacity; // Alpha channel + +uniform sampler2D diffuseTexture; +uniform sampler2D specularTexture; +uniform sampler2D normalTexture; + +uniform sampler2DShadow shadowMapTexture; + +in vec4 positionInLightSpace; + +in vec3 lightDir; +in vec3 viewDir; +in vec2 texCoord; + +out vec4 fragColor; + +void dsbModel(const in vec3 norm, const in vec2 flipYTexCoord, out vec3 ambientAndDiff, out vec3 spec) +{ + // Reflection of light direction about normal + vec3 r = reflect(-lightDir, norm); + + vec3 diffuseColor = texture(diffuseTexture, flipYTexCoord).rgb; + vec3 specularColor = texture(specularTexture, flipYTexCoord).rgb; + + // Calculate the ambient contribution + vec3 ambient = lightIntensity * ka * diffuseColor; + + // Calculate the diffuse contribution + float sDotN = max(dot(lightDir, norm), 0.0); + vec3 diffuse = lightIntensity * diffuseColor * sDotN; + + // Sum the ambient and diffuse contributions + ambientAndDiff = ambient + diffuse; + + // Calculate the specular highlight contribution + spec = vec3(0.0); + if (sDotN > 0.0) + spec = (lightIntensity * (shininess / (8.0 * 3.14))) * pow(max(dot(r, viewDir), 0.0), shininess); + + spec *= specularColor; +} + +void main() +{ + vec2 flipYTexCoord = texCoord; + flipYTexCoord.y = 1.0 - texCoord.y; + + float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace); + + // Sample the textures at the interpolated texCoords + vec4 normal = 2.0 * texture(normalTexture, flipYTexCoord) - vec4(1.0); + + vec3 result = lightIntensity * ka * texture(diffuseTexture, flipYTexCoord).rgb; + + // Calculate the lighting model, keeping the specular component separate + vec3 ambientAndDiff, spec; + if (shadowMapSample > 0) { + dsbModel(normalize(normal.xyz), flipYTexCoord, ambientAndDiff, spec); + result = ambientAndDiff + spec; + } + + // Combine spec with ambient+diffuse for final fragment color + fragColor = vec4(result, opacity); +} diff --git a/examples/qt3d/planets-qml/shaders/gl3/shadowmap.frag b/examples/qt3d/planets-qml/shaders/gl3/shadowmap.frag new file mode 100644 index 000000000..63f203da6 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/gl3/shadowmap.frag @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#version 150 core + +void main() +{ +} diff --git a/examples/qt3d/planets-qml/shaders/gl3/shadowmap.vert b/examples/qt3d/planets-qml/shaders/gl3/shadowmap.vert new file mode 100644 index 000000000..ca93360c6 --- /dev/null +++ b/examples/qt3d/planets-qml/shaders/gl3/shadowmap.vert @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#version 150 core + +in vec3 vertexPosition; + +uniform mat4 mvp; + +void main() +{ + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/examples/qt3d/shadow-map-qml/doc/images/shadowmapping-depth.png b/examples/qt3d/shadow-map-qml/doc/images/shadowmapping-depth.png Binary files differnew file mode 100644 index 000000000..d2b501412 --- /dev/null +++ b/examples/qt3d/shadow-map-qml/doc/images/shadowmapping-depth.png diff --git a/examples/qt3d/shadow-map-qml/doc/images/shadowmapping-qt3d.png b/examples/qt3d/shadow-map-qml/doc/images/shadowmapping-qt3d.png Binary files differnew file mode 100644 index 000000000..bac6ac75c --- /dev/null +++ b/examples/qt3d/shadow-map-qml/doc/images/shadowmapping-qt3d.png diff --git a/examples/qt3d/shadow-map-qml/doc/src/shadow-map-qml.qdoc b/examples/qt3d/shadow-map-qml/doc/src/shadow-map-qml.qdoc index 4e55da3b1..fd3377a8b 100644 --- a/examples/qt3d/shadow-map-qml/doc/src/shadow-map-qml.qdoc +++ b/examples/qt3d/shadow-map-qml/doc/src/shadow-map-qml.qdoc @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. @@ -29,4 +29,242 @@ \example shadow-map-qml \title Qt3D: Shadow Map QML Example \ingroup qt3d-examples-qml + + \brief A Qt3D QML application that illustrates how to render a scene in Qt3D + with shadows. + + \image shadowmapping-qt3d.png + + \e {Qt3D Shadow Map} illustrates how to configure the renderer in order to + accommodate custom rendering techniques. The example application displays a + self-shadowed plane and trefoil knot. + + We implement \l{Shadow Mapping}{shadow mapping} using a two pass rendering. + In the first pass, we generate the shadow information. In the second pass, + we generate the scene using the forward rendering technique with Phong + shading, while at the same time using the information gathered in the first + pass to draw the shadows. + + The entire rendering is configured using QML, but it is possible to use C++ + to achieve the very same result. + + \include examples-run.qdocinc + + \section1 Setting Up the Scene + + We set up the entire scene in the \e main.qml file. + + To be able to use the types in the Q3D and Q3D Renderer modules, we must + import the modules: + + \quotefromfile shadow-map-qml/main.qml + \skipto import Qt3D + \printuntil Renderer + + The first entities we create are a \l Camera, which represents the camera + used for the final rendering, and a \l Configuration, which allows us to + control this camera using the keyboard or the mouse: + + \printuntil } + \printuntil } + + We then create a Light custom entity, which represents our light. It is a + directional spotlight, placed somewhere above the plane and looking down at + the scene’s origin: + + \printuntil } + + This light entity is used by our custom framegraph, ShadowMapFrameGraph, + and our rendering effect, AdsEffect, whose instances are created just after + the light: + + \printuntil ] + \printuntil } + + Last, we create three entities for the meshes in the scene: a trefoil knot, + a toy plane, and a ground plane. They aggregate a mesh, a transformation, + and a material that uses the AdsEffect. The toy plane and the trefoil knot + transformations are animated: + + \printuntil /^\}/ + + \section1 Specifying the Light + + We specify the Light custom entity in \e Light.qml. + + Again, we import the necessary modules: + + \quotefromfile shadow-map-qml/Light.qml + \skipto import Qt3D + \printuntil Qt3D.Renderer + + We then use an \l Entity type as the root element of the custom QML type. + The light is a directional spotlight that exposes as properties a position, + intensity, and a 4×4 transformation matrix: + + \printuntil matrix4x4 + + In the first rendering pass, we use the light as a camera, and therefore we + use a \l Camera entity within the light and expose it as a property: + + \printuntil /^\}/ + + \section1 Configuring the Framegraph + + In Qt3D, the framegraph is the data-driven configuration for the rendering. + We implement the framegraph in the \e ShadowMapFrameGraph.qml file. + + In addition to the Qt3D and Qt3D Renderer modules, we also import the + Qt Quick module: + + \quotefromfile shadow-map-qml/ShadowMapFrameGraph.qml + \skipto import Qt3D + \printuntil QtQuick + + The code defines a \l FrameGraph entity that has a tree of entities as the + active framegraph: + + \printuntil clearColor + + Any path from the leaves of this tree to the root is a viable framegraph + configuration. Filter entities can enable or disable such paths, and + selector entities can alter the configuration. + + In our case, the tree looks like this: + + \code + Viewport + RenderPassFilter + RenderTargetSelector + ClearBuffer + CameraSelector + RenderPassFilter + ClearBuffer + CameraSelector + \endcode + + So we have two paths from the topmost \l Viewport entity. Each path + corresponds to a pass of the shadow map technique. The paths are enabled and + disabled using a RenderPassFilter, an entity that can filter depending on + arbitrary values defined in a given render pass. In this example, it is a + string: + + \printuntil ] + + The actual passes are not defined here. The framegraph simply modifies its + configuration when a given pass is rendered. + + \section1 Generating the Shadow Map + + In the shadow map generation pass, we must render to an offscreen surface + (Framebuffer Object) which has a depth texture attachment. In Qt3D, it is + represented by the RenderTarget entity, which has a number of attachments. + + In this example, we need only a depth attachment. We define it as a + RenderAttachment entity using the RenderAttachment.DepthAttachment \c type + that stores the depth and a Texture2D entity that actually configures the + exture storage used to store the depth information: + + \printuntil ] + \printuntil } + + Moreover, in this first pass, we must render using the light’s camera. + Therefore, we have a CameraSelector entity that sets the camera to the one + exported by the Light: + + \skipto CameraSelector + \printuntil } + + The second pass is more straightforward, because we simply render to the + screen using the main camera. + + \section1 Using Effects + + The bulk of the magic happens in the \e AdsEffect.qml file, where our main + \l Effect entity is defined. It implements the Ambient, Diffuse and Specular + (ADS) Lightning Model Phong shading with the addition of shadow mapped + generated shadows. + + An effect contains the implementation of a particular rendering strategy. In + this example, shadow mapping using two passes: + + \quotefromfile shadow-map-qml/AdsEffect.qml + \skipto Effect + \printuntil Light + + The \c parameters list defines some default values for the effect. The + values will get mapped to OpenGL shader program uniforms, so that in the + shaders we can access them. In this example, we expose some information from + the Light entity (position, intensity, view or projection matrix defined by + the internal camera) and the shadow map texture exposed by the framegraph: + + \skipto parameters: + \printuntil ] + + It is possible to put such parameters all the way down, from a \l Material, + to its \l Effect, to one of the effect’s \l Techniques. This allows a + \l Material instance to override defaults in an \l Effect or \l Technique. + The bindings array provides the same thing, except that it also allows us to + rename some parameters. In this example, it renames the \c ambient, + \c diffuse, and \c specular values defined in the material to the actual + uniform names used by the shader programs: + + \skipto bindings: + \printuntil ] + + To adapt the implementation to different hardware or OpenGL versions, we + could use one or more \l Technique elements. In this example, only one + technique is provided, targeting OpenGL 3.2 Core, or later: + + \quotefromfile shadow-map-qml/AdsEffect.qml + \skipto techniques: + \printuntil } + + Inside the technique, we finally have the definition of our two rendering + passes. We \e tag each pass with an \l Annotation entity, matching the ones + we specified in the framegraph configuration, so that each pass will have + different rendering settings: + + \printuntil ] + + The first pass is the shadow map generation. We load a suitable set of GLSL + shaders, which are actually extremely simple. They do only MVP (Model, View, + Projection) to bring meshes from their model space into clip space (and, + remember, in this first pass, the light is the camera). The fragment shader + is totally empty, because there is no color to be generated, and the depth + will be automatically captured for us by OpenGL: + + \printuntil } + + In this first pass, we also set some custom OpenGL state in the form of a + polygon offset and depth testing mode: + + \printuntil ] + + \section1 Rendering Using Phong Shading + + The second pass is a normal forward rendering using Phong shading. The code + in the effect entity is extremely simple. We simply configure some + parameters and load a pair of shaders which will be used when drawing. + + The first part of the shadow mapping happens in the vertex shader defined in + \e ads.vert file, where we output towards the fragment shader the + coordinates of each vertex in light space: + + \quotefromfile shadow-map-qml/shaders/ads.vert + \skipto mat4( + \skipto positionInLightSpace + \printuntil ; + + Actually, the coordinates get adjusted a little to allow us to easily sample + the shadow map texture. + + The second part happens in the fragment shader defined in the \e ads.frag + file, where we sample the shadow map. If the currently processed fragment is + behind the one closest to the light, then the current fragment is in shadow + (and only gets ambient contribution). Otherwise, it gets full Phong shading: + + \quotefromfile shadow-map-qml/shaders/ads.frag + \skipto main + \printuntil } */ diff --git a/examples/qt3d/wireframe/doc/images/qt3d-wireframe-rendering.png b/examples/qt3d/wireframe/doc/images/qt3d-wireframe-rendering.png Binary files differnew file mode 100644 index 000000000..c05f9b492 --- /dev/null +++ b/examples/qt3d/wireframe/doc/images/qt3d-wireframe-rendering.png diff --git a/examples/qt3d/wireframe/doc/src/wireframe.qdoc b/examples/qt3d/wireframe/doc/src/wireframe.qdoc index 453be115d..2b0cdda62 100644 --- a/examples/qt3d/wireframe/doc/src/wireframe.qdoc +++ b/examples/qt3d/wireframe/doc/src/wireframe.qdoc @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. @@ -29,4 +29,168 @@ \example wireframe \title Qt3D: Wireframe QML Example \ingroup qt3d-examples-qml + + \brief A Qt3D QML application that implements a single-pass wireframe + rendering method. + + \image qt3d-wireframe-rendering.png + + \e {Qt3D Wireframe Rendering} illustrates how to draw a single entity + (a trefoil knot) using a custom set of shaders to implement a single-pass + wireframe rendering method. + + \include examples-run.qdocinc + + \section1 Creating Entities + + The renderer aspect looks for entities that have some geometry, a material, + and optionally a transformation. These are all specified in the form of + subclasses of QComponent that have been exported to the QML engine in the + form of \l Mesh, \l Material, and \l Transform. We use these components to + create a custom QML item in \e TrefoilKnot.qml. + + We start off by importing the \c {Qt3D 2.0} module that provides the + \l Entity type and value type helpers, such as Qt.vector3d(). We also import + the \c {Qt3D.Renderer} module that provides the components and other types + picked up by the renderer aspect: + + \quotefromfile wireframe/TrefoilKnot.qml + \skipto import Qt3D + \printuntil Renderer + + To use components from other aspects, we would need to import the + corresponding QML module, too. + + We then use an \l Entity type as the root element of the custom QML type + exposing some custom properties just as you would with any other type in + QML: + + \printuntil Material + + In addition to aggregating components, the \l Entity type can be used to + group child objects together. This is analogous to how the \l Item type is + used in Qt Quick 2. + + \section1 Specifying Transformations + + We instantiate a \l Transform component and a \l Mesh component. The + \l Transform component specifies how the renderer should transform the + geometry when it is drawn with the OpenGL pipeline. We combine an ordered + set of transformations into a single \l Transform component. This + information will be automatically available to our shaders through standard + named uniform variables: + + \skipto Transform + \printuntil phiRotation + \printuntil } + + \section1 Loading Dynamic Per-Vertex Data + + The \l Mesh component is very simple. We use its source property to load in + a static set of geometry (such as vertex positions, normal vectors, and + texture coordinates) from a file in the Wavefront Obj format. This data was + exported from the Blender application. + + \printuntil } + + In addition to the \l Mesh element, Qt3D also enables dynamic generation of + per-vertex attribute data through C++ hooks that are called by the + task-based engine. + + \section1 Aggregating Components + + Simply instantiating components is not enough, however. In order for them to + imbue special behavior on an entity, the entity must aggregate the + components by means of its components property: + + \quotefromfile wireframe/TrefoilKnot.qml + \skipto components + \printuntil ] + + This allows components to be shared between multiple entities very easily. + In this example, we have components for the transform and mesh that are + contained within the TrefoilKnot custom type. The final component, of type + \l Material, is provided by a property of the TrefoilKnot custom type. We + will later customize the appearance of the entity. + + \section1 Rendering from Cameras + + We use the TrefoilKnot custom type in \e main.qml to draw the trefoil knot + on the screen. + + We use the same import statements as in \e TrefoilKnot.qml, with the + addition of a namespaced import for the Qt Quick module that we will + need for animations: + + \quotefromfile wireframe/main.qml + \skipto import Qt3D + \printuntil QtQuick + + We use an \l Entity type as the root type simply to act as a parent for + its children. In this sense, the \l Entity type is much like the \l Item + type: + + \printuntil id + + The FrameGraph component uses the ForwardRenderer type to completely + configure the renderer without touching any C++ code: + + \printuntil ] + + The \l BasicCamera type is a trivial wrapper around the built-in \l Camera + type that represents a virtual camera. It has properties for such things as + the near and far planes, field of view, aspect ratio, projection type, + position, and orientation: + + \printuntil } + + The \l Configuration type provides a temporary workaround for having mouse + control of the camera while the proper implementation that uses aspects and + components is being completed: + + \printuntil } + + It is trivial to use multiple cameras and choose between them using the + framegraph for all or part of the scene rendering. + + \section1 Mapping Materials + + Qt3D has a robust and very flexible \l {Qt3D Overview#Materials}{material + system} that allows multiple levels of customization. We use the + WireframeMaterial custom type to wrap the \l Material type: + + \printuntil diffuse + + We then instantiate the TrefoilKnot type and set the material on it: + + \skipto TrefoilKnot + \printuntil } + + The Qt3D engine in conjunction with the renderer aspect now has enough + information to finally render our mesh using the material we specified. + + \section1 Using Animation Elements + + We use the animation elements provided by Qt Quick 2 to animate the + properties of the TrefoilKnot and WireframeMaterial types. The properties of + the components of a type are updated by using the QML property binding + mechanism: + + \quotefromfile wireframe/main.qml + \skipto SequentialAnimation + \printuntil PauseAnimation + \printuntil } + + The property updates are noticed by the \l{Qt3D::}{QNode} base class + and automatically sent through to the corresponding objects in the renderer + aspect. The renderer then takes care of translating the property updates + to new values for uniform variables in the GLSL shader programs. + + Run the example to view the trefoil knot with the width of the wireframe + lines pulsing. All the heavy lifting is being done by the GPU. The CPU only + has to run the property animations and to translate the scenegraph and + framegraph into raw OpenGL calls. + + It is also possible to animate on the GPU via a custom shader program and + material. */ diff --git a/src/core/doc/qt3dcore.qdocconf b/src/core/doc/qt3dcore.qdocconf index 28f985029..923cc1345 100644 --- a/src/core/doc/qt3dcore.qdocconf +++ b/src/core/doc/qt3dcore.qdocconf @@ -48,7 +48,8 @@ exampledirs += src/snippets #excludedirs += -imagedirs += images +imagedirs += images \ + ../../../examples/qt3d/shadow-map-qml/doc/images Cpp.ignoretokens += QT3DCORE_PRIVATE_EXPORT \ QT3DINPUTSHARED_EXPORT \ diff --git a/src/core/doc/src/qt3d-overview.qdoc b/src/core/doc/src/qt3d-overview.qdoc index a02f32d83..133f6fd14 100644 --- a/src/core/doc/src/qt3d-overview.qdoc +++ b/src/core/doc/src/qt3d-overview.qdoc @@ -60,17 +60,124 @@ \list \li 2D and 3D rendering for C++ and Qt Quick applications \li Meshes - \li Materials - \li Shadows - \li Shaders + \li \l {Materials} + \li \l {Shaders} + \li \l {Shadow Mapping}{Shadow mapping} \li Ambient occlusion \li High dynamic range \li Deferred rendering \li Multitexturing - \li Instancing - \li Uniform Buffer Objects + \li \l {Instanced Rendering}{Instanced rendering} + \li \l {Uniform Buffer Objects} \endlist + \section2 Materials + + Qt3D has a robust and very flexible material system that allows multiple + levels of customization. It caters for different rendering approaches on + different platforms or OpenGL versions, enables multiple rendering passes + with different state sets, provides mechanisms for overriding of parameters + at different levels, and allows easy switching of shaders. All this from C++ + or using QML property bindings. + + The properties of a \l Material type can easily be mapped through to uniform + variables in a GLSL shader program that is itself specified in the + referenced effect property. + + For examples of using materials, see the \l {Qt3D: Materials C++ Example} + and \l {Qt3D: Materials QML Example}. + + \section2 Shaders + + Qt3D supports all of the OpenGL programmable rendering pipeline stages: + vertex, tessellation control, tessellation evaluation, geometry, and + fragment shaders. Compute shaders are planned for a future release. + + For examples of using shaders, see the Simple Shaders QML Example, + \l {Qt3D: Tessellation Modes QML Example}, + \l {Qt3D: Shadow Map QML Example}, \l{Qt3D: Wireframe QML Example}, and + \l {Qt3D: Wave QML Example}. + + \section2 Shadow Mapping + + Shadows are not directly supported by OpenGL, but there are countless + techniques that can be employed to generate them. Shadow mapping is simple + to use for generating good-looking shadows, while having a very small + performance cost. + + Shadow mapping is typically implemented using a two pass rendering. In the + first pass, the shadow information is generated. In the second pass, the + scene is generated using a particular rendering technique, while at the + same time using the information gathered in the first pass to draw the + shadows. + + The idea behind shadow mapping is that only the closest fragments to the + light are lit. Fragments \e behind other fragments are occluded, and + therefore in shadow. + + Therefore, in the first pass, the scene is drawn from the point of view of + the light. The information that is stored is simply the distance of the + closest fragment in this \e {light space}. In OpenGL terms, this corresponds + to having a Framebuffer Object, or FBO, with a depth texture attached to it. + In fact, the \e {distance from the eye} is the definition of the depth, + and the default depth testing done by OpenGL will actually store only the + depth for the closest fragment. + + A color texture attachment is not even needed, because there is no need to + shade fragments, only to calculate their depth. + + The following image displays a scene with a self-shadowed plane and trefoil + knot: + + \image shadowmapping-qt3d.png + + The following image shows an exaggerated shadow map texture of the scene: + + \image shadowmapping-depth.png + + The image indicates the depth stored when rendering the scene from the light + point of view. Darker colors represent a shallow depth (that is, closer to + the camera). In this scene, the light is placed somewhere above the objects + in the scene, on the right side with respect to the main camera (compare + this with the first screenshot). This matches with the fact that the toy + plane is closer to the camera than the other objects. + + Once the shadow map has been generated, the second rendering pass is done. + In this second pass, rendering is done using the normal scene's camera. Any + effect can be used here, such as Phong shading. It is important that the + shadow map algorithm is applied in the fragment shader. That is, the + fragment that is closest to the light is drawn lit, whereas the other + fragments are drawn in shadow. + + The shadow map generated in the first pass provides the necessary + information about the distance of fragments to light. It then suffices to + remap the fragment in light space, thereby calculating its depth from the + light point of view, as well as where its coordinates are on the shadow map + texture. The shadow map texture can then be sampled at the given coordinates + and the fragment's depth can be compared with the result of the sampling. If + the fragment is further away, then it is in shadow; otherwise it is lit. + + For example code, see the \l {Qt3D: Shadow Map QML Example}. + + \section2 Instanced Rendering + + \e Instancing is a way of getting the GPU to draw many copies (instances) of + a base object that varies in some way for each copy. Often, in position, + orientation, color, material properties, scale, and so on. Qt3D provides an + API similar to the Qt Quick \l Repeater element. In this case, the delegate + is the base object and the model provides the per-instance data. So whereas + an entity with a \l Mesh component attached eventually gets transformed into + a call to glDrawElements, an entity with a instanced component will be + translated into a call to glDrawElementsInstanced. + + Instanced rendering is planned for a future release. + + \section2 Uniform Buffer Objects + + A Uniform Buffer Object (UBO) can be bound to OpenGL shader programs to make + large amounts of data readily available. Typical use cases for UBOs are for + sets of material or lighting parameters. + \section1 Configurable Renderer To combine support for both C++ and QML APIs with having a fully diff --git a/src/input/qkeyboardinput.cpp b/src/input/qkeyboardinput.cpp index 9d707ec49..d83891018 100644 --- a/src/input/qkeyboardinput.cpp +++ b/src/input/qkeyboardinput.cpp @@ -172,7 +172,7 @@ void QKeyboardInput::keyEvent(Q3DKeyEvent *event) QByteArray keySignal = keyToSignal(event->key()); if (!keySignal.isEmpty()) { - keySignal += "(Q3DKeyEvent*)"; + keySignal += "(Qt3D::Q3DKeyEvent*)"; // TO DO: Finding if the signal is connected to anything before doing the invocation // could be an improvement // That's what QQ2 does but since it accesses QML private classes to do so, that may not be diff --git a/src/render/doc/qt3drenderer.qdocconf b/src/render/doc/qt3drenderer.qdocconf index e56b6f992..add1cc90c 100644 --- a/src/render/doc/qt3drenderer.qdocconf +++ b/src/render/doc/qt3drenderer.qdocconf @@ -45,6 +45,9 @@ exampledirs += ../../../examples/qt3d \ imagedirs += images +examples.fileextensions += "*.fraq *.geom *.vert" +examples.imageextensions += "*.png" + Cpp.ignoretokens += QT3DRENDERERSHARED_EXPORT \ QT3DRENDERERSHARED_PRIVATE_EXPORT |