summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-11-23 15:27:48 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-11-26 17:36:04 +0000
commit653fdeb073a525a676bf0c12511c3f74bad2095e (patch)
tree9c4e2f2f29e63a12a0a0f7799235cad9b71c738e /examples
parent1324668b1b77c865c90a1352a61b0b3da3da39b1 (diff)
Lights phase 1: infrastructure
QAbstractLight becomes QLight and gets its own backend node. This way we can easily gather all lights for the scene and filter them when building render commands. Both the frontend and backend remain a subclass of (Q)ShaderData but will not be part of the ordinary ShaderData component list. This prevents mixing up ShaderDatas and Lights but allows reusing the same underlying infrastructure so that properties can automatically be transformed for example. It is worth noting that the position property for lights is now removed: the position is determined by the entity's (to which the light component belongs) position. A number of changes are made to ShaderData itself as backend subclassing with different managers is not straightforward. For now the distance between the rendered entity and the entity with the light component is calculated and lights will be chosen based on this distance. A framegraph node for controlling this will be added in future patches. No uniform setting or shader changes are included here. Task-number: QTBUG-48834 Change-Id: I43a6c5f9420d4254d798c558bd58680b2b09eceb Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/qt3d/lights/lights.pro16
-rw-r--r--examples/qt3d/lights/lights.qrc5
-rw-r--r--examples/qt3d/lights/main.cpp61
-rw-r--r--examples/qt3d/lights/main.qml91
-rw-r--r--examples/qt3d/qt3d.pro3
5 files changed, 175 insertions, 1 deletions
diff --git a/examples/qt3d/lights/lights.pro b/examples/qt3d/lights/lights.pro
new file mode 100644
index 000000000..d1a2c4fea
--- /dev/null
+++ b/examples/qt3d/lights/lights.pro
@@ -0,0 +1,16 @@
+!include( ../examples.pri ) {
+ error( "Couldn't find the examples.pri file!" )
+}
+
+SOURCE += main.cpp
+
+QT += qml quick 3dcore 3drender 3dinput 3dquick
+
+OTHER_FILES += main.qml
+
+SOURCES += \
+ main.cpp
+
+RESOURCES += \
+ lights.qrc \
+ ../exampleresources/obj.qrc
diff --git a/examples/qt3d/lights/lights.qrc b/examples/qt3d/lights/lights.qrc
new file mode 100644
index 000000000..5f6483ac3
--- /dev/null
+++ b/examples/qt3d/lights/lights.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/qt3d/lights/main.cpp b/examples/qt3d/lights/main.cpp
new file mode 100644
index 000000000..51857b171
--- /dev/null
+++ b/examples/qt3d/lights/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include <window.h>
+#include <Qt3DRender/QRenderAspect>
+#include <Qt3DInput/QInputAspect>
+#include <Qt3DQuick/QQmlAspectEngine>
+#include <QGuiApplication>
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ Window view;
+ Qt3DCore::Quick::QQmlAspectEngine engine;
+
+ engine.aspectEngine()->registerAspect(new Qt3DRender::QRenderAspect());
+ engine.aspectEngine()->registerAspect(new Qt3DInput::QInputAspect());
+ QVariantMap data;
+ data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view)));
+ data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view));
+ engine.aspectEngine()->setData(data);
+ engine.aspectEngine()->initialize();
+ engine.setSource(QUrl("qrc:/main.qml"));
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/qt3d/lights/main.qml b/examples/qt3d/lights/main.qml
new file mode 100644
index 000000000..eb28fc1a5
--- /dev/null
+++ b/examples/qt3d/lights/main.qml
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** 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 QtQuick 2.0 as Quick
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+
+Entity
+{
+ components: FrameGraph {
+ activeFrameGraph: ForwardRenderer {
+ clearColor: Qt.rgba(0, 0, 0, 1)
+ camera: camera
+ }
+ }
+
+ Camera {
+ id: camera
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 45
+ aspectRatio: 16/9
+ nearPlane : 0.1
+ farPlane : 1000.0
+ position: Qt.vector3d( 0.0, 0.0, 50.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ viewCenter: Qt.vector3d( 0.0, 0.0, -1.0 )
+ }
+
+ Configuration {
+ controlledCamera: camera
+ }
+
+ Entity {
+ components: [
+ Transform { translation: Qt.vector3d(2.0, 1.0, 1.0); },
+ PointLight {
+ color: Qt.rgba(1, 0, 0, 1)
+ }
+ ]
+ }
+
+ Entity {
+ components: [
+ Transform { translation: Qt.vector3d(2.0, 3.0, 4.0); },
+ PointLight {
+ color: Qt.rgba(1, 0, 0, 1)
+ }
+ ]
+ }
+
+ Entity {
+ components: [
+ Mesh {
+ source: "assets/obj/toyplane.obj"
+ }
+ ]
+ }
+}
diff --git a/examples/qt3d/qt3d.pro b/examples/qt3d/qt3d.pro
index 4de448259..afa4cce79 100644
--- a/examples/qt3d/qt3d.pro
+++ b/examples/qt3d/qt3d.pro
@@ -44,7 +44,8 @@ SUBDIRS += \
instanced-arrays-qml \
picking-qml \
transforms-qml \
- qgltf
+ qgltf \
+ lights
# TODO Port the old examples to new APIs
#SUBDIRS += qt3d