mirror of https://github.com/qt/qt3d.git
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>
This commit is contained in:
parent
68d32040f6
commit
9b9f34701f
|
|
@ -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
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -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 )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -34,34 +34,68 @@
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
import Qt3D 2.0
|
import Qt3D.Core 2.0
|
||||||
import Qt3D.Renderer 2.0
|
import Qt3D.Render 2.0
|
||||||
|
import QtQuick 2.2 as QQ2
|
||||||
|
|
||||||
FrameGraph {
|
FrameGraph {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property alias viewCamera: cameraSelector.camera
|
property alias viewCamera: viewCameraSelector.camera
|
||||||
|
property alias lightCamera: lightCameraSelector.camera
|
||||||
|
readonly property Texture2D shadowTexture: depthTexture
|
||||||
|
|
||||||
activeFrameGraph: Viewport {
|
activeFrameGraph: Viewport {
|
||||||
rect: Qt.rect(0.0, 0.0, 1.0, 1.0)
|
rect: Qt.rect(0.0, 0.0, 1.0, 1.0)
|
||||||
clearColor: Qt.rgba(0.0, 0.0, 0.0, 1.0)
|
clearColor: Qt.rgba(0.0, 0.0, 0.0, 1.0)
|
||||||
|
|
||||||
CameraSelector {
|
RenderPassFilter {
|
||||||
id: cameraSelector
|
includes: [ Annotation { name: "pass"; value: "shadowmap" } ]
|
||||||
camera: Camera {
|
|
||||||
id: camera
|
RenderTargetSelector {
|
||||||
projectionType: CameraLens.PerspectiveProjection
|
target: RenderTarget {
|
||||||
fieldOfView: 45
|
attachments: [
|
||||||
aspectRatio: mainview.width / mainview.height
|
RenderAttachment {
|
||||||
nearPlane: 0.01
|
name: "depth"
|
||||||
farPlane: 1000.0
|
type: RenderAttachment.DepthAttachment
|
||||||
position: Qt.vector3d(0.0, 0.0, -100.0)
|
texture: Texture2D {
|
||||||
upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
|
id: depthTexture
|
||||||
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
|
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 {
|
ClearBuffer {
|
||||||
buffers : ClearBuffer.ColorDepthBuffer
|
buffers : ClearBuffer.ColorDepthBuffer
|
||||||
|
|
||||||
|
CameraSelector {
|
||||||
|
id: viewCameraSelector
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,13 +58,12 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FPS thing
|
|
||||||
property int frames: 0
|
property int frames: 0
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
interval: 1000
|
interval: 1000
|
||||||
repeat: true
|
repeat: true
|
||||||
running: true//!fpsDisplay.hidden
|
running: true
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
console.log("Frames done :" + frames)
|
console.log("Frames done :" + frames)
|
||||||
frames = 0
|
frames = 0
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -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 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -34,14 +34,15 @@
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
import Qt3D 2.0
|
import Qt3D.Core 2.0
|
||||||
import Qt3D.Renderer 2.0
|
import Qt3D.Render 2.0
|
||||||
|
|
||||||
Entity {
|
Entity {
|
||||||
id: root
|
id: root
|
||||||
property real xPos: 0
|
property real xPos: 0
|
||||||
property real yPos: 0
|
property real yPos: 0
|
||||||
property real zPos: 0
|
property real zPos: 0
|
||||||
|
property Material material
|
||||||
|
|
||||||
SphereMesh {
|
SphereMesh {
|
||||||
id: sphereMesh
|
id: sphereMesh
|
||||||
|
|
@ -61,6 +62,7 @@ Entity {
|
||||||
|
|
||||||
components: [
|
components: [
|
||||||
sphereMesh,
|
sphereMesh,
|
||||||
sphereTransform
|
sphereTransform,
|
||||||
|
material
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,31 +34,56 @@
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
import Qt3D 2.0
|
import Qt3D.Core 2.0
|
||||||
import Qt3D.Renderer 2.0
|
import Qt3D.Render 2.0
|
||||||
import QtQuick 2.0 as QQ2
|
import QtQuick 2.0 as QQ2
|
||||||
|
|
||||||
Entity {
|
Entity {
|
||||||
id: sceneRoot
|
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: [
|
components: [
|
||||||
Qt3DBenchFrameGraph {
|
Qt3DBenchFrameGraph {
|
||||||
id: frameGraph
|
id: frameGraph
|
||||||
|
viewCamera: camera
|
||||||
|
lightCamera: light.lightCamera
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
Configuration {
|
ShadowEffect {
|
||||||
controlledCamera: frameGraph.viewCamera
|
id: shadowEffect
|
||||||
|
|
||||||
|
shadowTexture: frameGraph.shadowTexture
|
||||||
|
light: light
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeInstantiator {
|
NodeInstantiator {
|
||||||
id: spheres
|
id: spheres
|
||||||
property int count: 900
|
property int count: 100
|
||||||
property real spacing: 2
|
property real spacing: 2
|
||||||
property int cols: 10
|
property int cols: 10
|
||||||
property int rows: 9
|
property int rows: 10
|
||||||
property int levelCount: cols * rows
|
property int levelCount: cols * rows
|
||||||
property int levels: 10
|
property int levels: 1
|
||||||
|
|
||||||
model: count
|
model: count
|
||||||
delegate: SphereElement {
|
delegate: SphereElement {
|
||||||
|
|
@ -67,6 +92,21 @@ Entity {
|
||||||
xPos: spheres.spacing * (index % spheres.cols - 0.5 * (spheres.cols - 1))
|
xPos: spheres.spacing * (index % spheres.cols - 0.5 * (spheres.cols - 1))
|
||||||
yPos: spheres.spacing * (Math.floor(index / spheres.levelCount) - 0.5 * spheres.levels)
|
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)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// This one uses Scene3D
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQuickView>
|
#include <QQuickView>
|
||||||
#include <QOpenGLContext>
|
#include <QOpenGLContext>
|
||||||
|
|
@ -51,6 +53,7 @@ int main(int argc, char **argv)
|
||||||
format.setSamples(4);
|
format.setSamples(4);
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
|
view.resize(1280, 768);
|
||||||
view.setFormat(format);
|
view.setFormat(format);
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:/Qt3DBenchMain.qml"));
|
view.setSource(QUrl("qrc:/Qt3DBenchMain.qml"));
|
||||||
|
|
@ -58,3 +61,39 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
return app.exec();
|
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
|
||||||
|
|
|
||||||
|
|
@ -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 += \
|
SOURCES += \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
@ -8,5 +12,3 @@ OTHER_FILES += \
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
qt3dbench-qml.qrc
|
qt3dbench-qml.qrc
|
||||||
|
|
||||||
DISTFILES +=
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,16 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>Qt3DBenchMain.qml</file>
|
|
||||||
<file>Qt3DBenchFrameGraph.qml</file>
|
<file>Qt3DBenchFrameGraph.qml</file>
|
||||||
<file>SphereView.qml</file>
|
<file>SphereView.qml</file>
|
||||||
<file>SphereElement.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>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue