diff options
author | Mika Salmela <mika.salmela@theqtcompany.com> | 2015-10-29 12:09:19 +0200 |
---|---|---|
committer | Mika Salmela <mika.salmela@theqtcompany.com> | 2015-10-29 10:47:59 +0000 |
commit | 9b9f34701f47824e8201453d148152fb0855f98a (patch) | |
tree | 14aded63ab188c367d59e3b4f14a4bd0dbc5d758 /tests | |
parent | 68d32040f688aeebb8236e13effcfd9da43de71c (diff) |
Shadow version of benchmarking app
Added shadows to benchmarking test application to test two pass
rendering performance.
Change-Id: I81bb6e9fea32ab70d6c5c65a9ba787d976e2eaa0
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/benchmarks/Qt3DBench/GroundPlane.qml | 63 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/Light.qml | 62 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/Qt3DBenchFrameGraph.qml | 64 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/Qt3DBenchMain.qml | 3 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/ShadowEffect.qml | 88 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/ShadowMaterial.qml | 54 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/SphereElement.qml | 8 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/SphereView.qml | 54 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/main.cpp | 39 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/qt3dbench-qml.pro | 8 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/qt3dbench-qml.qrc | 10 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/shaders/ads.frag | 93 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/shaders/ads.vert | 66 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/shaders/shadowmap.frag | 41 | ||||
-rw-r--r-- | tests/benchmarks/Qt3DBench/shaders/shadowmap.vert | 46 |
15 files changed, 668 insertions, 31 deletions
diff --git a/tests/benchmarks/Qt3DBench/GroundPlane.qml b/tests/benchmarks/Qt3DBench/GroundPlane.qml new file mode 100644 index 000000000..2fb8c07ee --- /dev/null +++ b/tests/benchmarks/Qt3DBench/GroundPlane.qml @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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.Core 2.0 +import Qt3D.Render 2.0 + +Entity { + id: root + property Material material + + PlaneMesh { + id: groundMesh + width: 50 + height: width + meshResolution: Qt.size(2, 2) + } + + Transform { + id: groundTransform + Translate { + dy: -14 + } + } + + components: [ + groundMesh, + groundTransform, + material + ] +} diff --git a/tests/benchmarks/Qt3DBench/Light.qml b/tests/benchmarks/Qt3DBench/Light.qml new file mode 100644 index 000000000..eba533713 --- /dev/null +++ b/tests/benchmarks/Qt3DBench/Light.qml @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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.Core 2.0 +import Qt3D.Render 2.0 + +Entity { + id: root + + property vector3d lightPosition: Qt.vector3d(30.0, 30.0, 0.0) + property vector3d lightIntensity: Qt.vector3d(1.0, 1.0, 1.0) + + readonly property Camera lightCamera: lightCamera + readonly property matrix4x4 lightViewProjection: lightCamera.projectionMatrix.times(lightCamera.matrix) + + Camera { + id: lightCamera + objectName: "lightCameraLens" + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: 1280 / 768 //mainview.width / mainview.height + nearPlane: 0.1 + farPlane: 200.0 + position: root.lightPosition + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + } +} diff --git a/tests/benchmarks/Qt3DBench/Qt3DBenchFrameGraph.qml b/tests/benchmarks/Qt3DBench/Qt3DBenchFrameGraph.qml index f96604a69..0ef2cf57f 100644 --- a/tests/benchmarks/Qt3DBench/Qt3DBenchFrameGraph.qml +++ b/tests/benchmarks/Qt3DBench/Qt3DBenchFrameGraph.qml @@ -34,34 +34,68 @@ ** ****************************************************************************/ -import Qt3D 2.0 -import Qt3D.Renderer 2.0 +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import QtQuick 2.2 as QQ2 FrameGraph { id: root - property alias viewCamera: cameraSelector.camera + 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) - CameraSelector { - id: cameraSelector - camera: Camera { - id: camera - projectionType: CameraLens.PerspectiveProjection - fieldOfView: 45 - aspectRatio: mainview.width / mainview.height - nearPlane: 0.01 - farPlane: 1000.0 - position: Qt.vector3d(0.0, 0.0, -100.0) - upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) - viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + RenderPassFilter { + includes: [ Annotation { name: "pass"; value: "shadowmap" } ] + + RenderTargetSelector { + target: RenderTarget { + attachments: [ + RenderAttachment { + name: "depth" + type: RenderAttachment.DepthAttachment + texture: Texture2D { + id: depthTexture + width: 1024 + height: 1024 + format: Texture.DepthFormat + generateMipMaps: false + magnificationFilter: Texture.Linear + minificationFilter: Texture.Linear + 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/tests/benchmarks/Qt3DBench/Qt3DBenchMain.qml b/tests/benchmarks/Qt3DBench/Qt3DBenchMain.qml index 21abe2976..ed253be38 100644 --- a/tests/benchmarks/Qt3DBench/Qt3DBenchMain.qml +++ b/tests/benchmarks/Qt3DBench/Qt3DBenchMain.qml @@ -58,13 +58,12 @@ Item { } } - // FPS thing property int frames: 0 Timer { interval: 1000 repeat: true - running: true//!fpsDisplay.hidden + running: true onTriggered: { console.log("Frames done :" + frames) frames = 0 diff --git a/tests/benchmarks/Qt3DBench/ShadowEffect.qml b/tests/benchmarks/Qt3DBench/ShadowEffect.qml new file mode 100644 index 000000000..4a8f0bb11 --- /dev/null +++ b/tests/benchmarks/Qt3DBench/ShadowEffect.qml @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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.Core 2.0 +import Qt3D.Render 2.0 + +Effect { + id: root + + property Texture2D shadowTexture + property Light light + + parameters: [ + Parameter { name: "lightViewProjection"; value: root.light.lightViewProjection }, + Parameter { name: "lightPosition"; value: root.light.lightPosition }, + Parameter { name: "lightIntensity"; value: root.light.lightIntensity }, + + Parameter { name: "shadowMapTexture"; value: root.shadowTexture } + ] + + techniques: [ + Technique { + renderPasses: [ + RenderPass { + annotations: [ Annotation { name: "pass"; value: "shadowmap" } ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/shadowmap.vert") + fragmentShaderCode: loadSource("qrc:/shaders/shadowmap.frag") + } + + renderStates: [ + PolygonOffset { factor: 4; units: 4 }, + DepthTest { func: DepthTest.Less } + ] + }, + + RenderPass { + annotations: [ Annotation { name: "pass"; value: "forward" } ] + + bindings: [ + ParameterMapping { parameterName: "ambient"; shaderVariableName: "ka"; bindingType: ParameterMapping.Uniform }, + ParameterMapping { parameterName: "diffuse"; shaderVariableName: "kd"; bindingType: ParameterMapping.Uniform }, + ParameterMapping { parameterName: "specular"; shaderVariableName: "ks"; bindingType: ParameterMapping.Uniform } + ] + + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/shaders/ads.vert") + fragmentShaderCode: loadSource("qrc:/shaders/ads.frag") + } + } + ] + } + ] +} diff --git a/tests/benchmarks/Qt3DBench/ShadowMaterial.qml b/tests/benchmarks/Qt3DBench/ShadowMaterial.qml new file mode 100644 index 000000000..4e02e23e6 --- /dev/null +++ b/tests/benchmarks/Qt3DBench/ShadowMaterial.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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.Core 2.0 +import Qt3D.Render 2.0 +import QtQuick 2.1 + +Material { + id: root + property color ambientColor: Qt.rgba(0.1, 0.1, 0.1, 1.0) + property color diffuseColor: Qt.rgba(0.7, 0.7, 0.9, 1.0) + property color specularColor: Qt.rgba(0.1, 0.1, 0.1, 1.0) + property real shininess: 150.0 + + parameters: [ + Parameter { name: "ambient"; value: Qt.vector3d(root.ambientColor.r, root.ambientColor.g, root.ambientColor.b) }, + Parameter { name: "diffuse"; value: Qt.vector3d(root.diffuseColor.r, root.diffuseColor.g, root.diffuseColor.b) }, + Parameter { name: "specular"; value: Qt.vector3d(root.specularColor.r, root.specularColor.g, root.specularColor.b) }, + Parameter { name: "shininess"; value: root.shininess } + ] +} diff --git a/tests/benchmarks/Qt3DBench/SphereElement.qml b/tests/benchmarks/Qt3DBench/SphereElement.qml index 01e13bb6f..df1049af8 100644 --- a/tests/benchmarks/Qt3DBench/SphereElement.qml +++ b/tests/benchmarks/Qt3DBench/SphereElement.qml @@ -34,14 +34,15 @@ ** ****************************************************************************/ -import Qt3D 2.0 -import Qt3D.Renderer 2.0 +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 Entity { id: root property real xPos: 0 property real yPos: 0 property real zPos: 0 + property Material material SphereMesh { id: sphereMesh @@ -61,6 +62,7 @@ Entity { components: [ sphereMesh, - sphereTransform + sphereTransform, + material ] } diff --git a/tests/benchmarks/Qt3DBench/SphereView.qml b/tests/benchmarks/Qt3DBench/SphereView.qml index 5d3f0617c..ad5b8fbc5 100644 --- a/tests/benchmarks/Qt3DBench/SphereView.qml +++ b/tests/benchmarks/Qt3DBench/SphereView.qml @@ -34,31 +34,56 @@ ** ****************************************************************************/ -import Qt3D 2.0 -import Qt3D.Renderer 2.0 +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 import QtQuick 2.0 as QQ2 Entity { id: sceneRoot + Camera { + id: camera + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: 1280 / 768 //_window.width / _window.height + nearPlane: 0.01 + farPlane: 1000.0 + position: Qt.vector3d(0.0, 0.0, -100.0) + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + } + + Configuration { + controlledCamera: camera + } + + Light { + id: light + } + components: [ Qt3DBenchFrameGraph { id: frameGraph + viewCamera: camera + lightCamera: light.lightCamera } ] - Configuration { - controlledCamera: frameGraph.viewCamera + ShadowEffect { + id: shadowEffect + + shadowTexture: frameGraph.shadowTexture + light: light } NodeInstantiator { id: spheres - property int count: 900 + property int count: 100 property real spacing: 2 property int cols: 10 - property int rows: 9 + property int rows: 10 property int levelCount: cols * rows - property int levels: 10 + property int levels: 1 model: count delegate: SphereElement { @@ -67,6 +92,21 @@ Entity { xPos: spheres.spacing * (index % spheres.cols - 0.5 * (spheres.cols - 1)) yPos: spheres.spacing * (Math.floor(index / spheres.levelCount) - 0.5 * spheres.levels) zPos: spheres.spacing * (Math.floor((index % spheres.levelCount) / spheres.cols) - 0.5 * spheres.rows) + material: ShadowMaterial { + effect: shadowEffect + diffuseColor: Qt.rgba(0.9, 0.5, 0.3, 1.0) + shininess: 75 + } + } + } + + // Ground plane + // Just for showing that shadows are really working + GroundPlane { + material: ShadowMaterial { + effect: shadowEffect + diffuseColor: Qt.rgba(0.2, 0.5, 0.3, 1.0) + specularColor: Qt.rgba(1.0, 0, 0, 1.0) } } } diff --git a/tests/benchmarks/Qt3DBench/main.cpp b/tests/benchmarks/Qt3DBench/main.cpp index 3bd3acb7d..fca6ea0ef 100644 --- a/tests/benchmarks/Qt3DBench/main.cpp +++ b/tests/benchmarks/Qt3DBench/main.cpp @@ -34,6 +34,8 @@ ** ****************************************************************************/ +#if 0 +// This one uses Scene3D #include <QGuiApplication> #include <QQuickView> #include <QOpenGLContext> @@ -51,6 +53,7 @@ int main(int argc, char **argv) format.setSamples(4); QQuickView view; + view.resize(1280, 768); view.setFormat(format); view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:/Qt3DBenchMain.qml")); @@ -58,3 +61,39 @@ int main(int argc, char **argv) return app.exec(); } + +#else + +#include <window.h> +#include <Qt3DRender/qrenderaspect.h> +#include <Qt3DInput/QInputAspect> +#include <Qt3DQuick/QQmlAspectEngine> + +#include <QGuiApplication> +#include <QQmlContext> +#include <QQmlEngine> + +int main(int argc, char* argv[]) +{ + QGuiApplication app(argc, argv); + + Window view; + Qt3DCore::Quick::QQmlAspectEngine engine; + + view.resize(1280, 768); + engine.aspectEngine()->registerAspect(new Qt3DRender::QRenderAspect()); + engine.aspectEngine()->registerAspect(new Qt3DInput::QInputAspect()); + engine.aspectEngine()->initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.qmlEngine()->rootContext()->setContextProperty("_window", &view); + engine.setSource(QUrl("qrc:/SphereView.qml")); + + view.show(); + + return app.exec(); +} + +#endif diff --git a/tests/benchmarks/Qt3DBench/qt3dbench-qml.pro b/tests/benchmarks/Qt3DBench/qt3dbench-qml.pro index c0cd81f4d..5766f8660 100644 --- a/tests/benchmarks/Qt3DBench/qt3dbench-qml.pro +++ b/tests/benchmarks/Qt3DBench/qt3dbench-qml.pro @@ -1,4 +1,8 @@ -QT += qml quick +!include( ../../../examples/qt3d/examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +QT += 3dcore 3drender 3dinput 3dquick qml quick SOURCES += \ main.cpp @@ -8,5 +12,3 @@ OTHER_FILES += \ RESOURCES += \ qt3dbench-qml.qrc - -DISTFILES += diff --git a/tests/benchmarks/Qt3DBench/qt3dbench-qml.qrc b/tests/benchmarks/Qt3DBench/qt3dbench-qml.qrc index 8855e91b9..17c7e96af 100644 --- a/tests/benchmarks/Qt3DBench/qt3dbench-qml.qrc +++ b/tests/benchmarks/Qt3DBench/qt3dbench-qml.qrc @@ -1,8 +1,16 @@ <RCC> <qresource prefix="/"> - <file>Qt3DBenchMain.qml</file> <file>Qt3DBenchFrameGraph.qml</file> <file>SphereView.qml</file> <file>SphereElement.qml</file> + <file>GroundPlane.qml</file> + <file>shaders/shadowmap.frag</file> + <file>shaders/shadowmap.vert</file> + <file>shaders/ads.frag</file> + <file>shaders/ads.vert</file> + <file>Light.qml</file> + <file>ShadowEffect.qml</file> + <file>ShadowMaterial.qml</file> + <file>Qt3DBenchMain.qml</file> </qresource> </RCC> diff --git a/tests/benchmarks/Qt3DBench/shaders/ads.frag b/tests/benchmarks/Qt3DBench/shaders/ads.frag new file mode 100644 index 000000000..b2b056a3a --- /dev/null +++ b/tests/benchmarks/Qt3DBench/shaders/ads.frag @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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 kd; // Diffuse reflectivity +uniform vec3 ks; // Specular reflectivity +uniform float shininess; // Specular shininess factor + +uniform sampler2DShadow shadowMapTexture; + +in vec4 positionInLightSpace; + +in vec3 position; +in vec3 normal; + +out vec4 fragColor; + +vec3 dsModel(const in vec3 pos, const in vec3 n) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - pos); + + // Calculate the vector from the fragment to the eye position + // (origin since this is in "eye" or "camera" space) + vec3 v = normalize(-pos); + + // Reflect the light beam using the normal at this fragment + vec3 r = reflect(-s, n); + + // Calculate the diffuse component + float diffuse = max(dot(s, n), 0.0); + + // Calculate the specular component + float specular = 0.0; + if (dot(s, n) > 0.0) + specular = pow(max(dot(r, v), 0.0), shininess); + + // Combine the diffuse and specular contributions (ambient is taken into account by the caller) + return lightIntensity * (kd * diffuse + ks * specular); +} + +void main() +{ + float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace); + + vec3 ambient = lightIntensity * ka; + + vec3 result = ambient; + if (shadowMapSample > 0) + result += dsModel(position, normalize(normal)); + + fragColor = vec4(result, 1.0); +} diff --git a/tests/benchmarks/Qt3DBench/shaders/ads.vert b/tests/benchmarks/Qt3DBench/shaders/ads.vert new file mode 100644 index 000000000..e77a8f287 --- /dev/null +++ b/tests/benchmarks/Qt3DBench/shaders/ads.vert @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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; + +out vec4 positionInLightSpace; +out vec3 position; +out vec3 normal; + +uniform mat4 lightViewProjection; +uniform mat4 modelMatrix; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +void main() +{ + // positionInLightSpace = lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0); + 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); + + normal = normalize(modelViewNormal * vertexNormal); + position = vec3(modelView * vec4(vertexPosition, 1.0)); + + gl_Position = mvp * vec4(vertexPosition, 1.0); +} diff --git a/tests/benchmarks/Qt3DBench/shaders/shadowmap.frag b/tests/benchmarks/Qt3DBench/shaders/shadowmap.frag new file mode 100644 index 000000000..becac915e --- /dev/null +++ b/tests/benchmarks/Qt3DBench/shaders/shadowmap.frag @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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/tests/benchmarks/Qt3DBench/shaders/shadowmap.vert b/tests/benchmarks/Qt3DBench/shaders/shadowmap.vert new file mode 100644 index 000000000..a0b81a846 --- /dev/null +++ b/tests/benchmarks/Qt3DBench/shaders/shadowmap.vert @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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); +} |