summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/examples.pro8
-rw-r--r--examples/rollerball/AdsEffect.qml107
-rw-r--r--examples/rollerball/AdsMaterial.qml66
-rw-r--r--examples/rollerball/BallEntity.qml74
-rw-r--r--examples/rollerball/BasicCamera.qml71
-rw-r--r--examples/rollerball/ForwardRenderer.qml75
-rw-r--r--examples/rollerball/main.cpp68
-rw-r--r--examples/rollerball/main.qml113
-rw-r--r--examples/rollerball/rollerball.pro20
-rw-r--r--examples/rollerball/rollerball.qrc10
-rw-r--r--src/render/render.pro2
-rw-r--r--src/render/render.qrc2
-rw-r--r--src/render/shaders/phong.frag45
-rw-r--r--src/render/shaders/phong.vert19
14 files changed, 679 insertions, 1 deletions
diff --git a/examples/examples.pro b/examples/examples.pro
index 4085dc753..7c363c9a6 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -35,6 +35,10 @@ src_bigmodelqml.subdir = $$PWD/bigmodel-qml
src_bigmodelqml.target = sub-bigmodelqml
src_bigmodelqml.depends = src_exampleresources
+src_rollerball.subdir = $$PWD/rollerball
+src_rollerball.target = sub-rollerball
+src_rollerball.depends = src_exampleresources
+
SUBDIRS += \
src_exampleresources \
@@ -50,3 +54,7 @@ SUBDIRS += \
# TODO Port the old examples to new APIs
#SUBDIRS += qt3d
#qtHaveModule(qml): SUBDIRS += quick3d
+
+qtHaveModule(3dbulletphysics) {
+ SUBDIRS += src_rollerball
+}
diff --git a/examples/rollerball/AdsEffect.qml b/examples/rollerball/AdsEffect.qml
new file mode 100644
index 000000000..c1806e7b7
--- /dev/null
+++ b/examples/rollerball/AdsEffect.qml
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt3D 2.0
+import Qt3D.Render 2.0
+
+// For Qt.vector3d() and friends. For some reason this is provided by
+// QQuickValueTypeProvider in QtQuick rather than the default value
+// type provider in QtQml. So we will need to replicate this in Qt3D
+// for the types that we wish to support. Otherwise we'll have to import
+// QtQuick 2.1 all over the place.
+import QtQuick 2.1
+
+Effect {
+ id: root
+
+ // These parameters act as default values for the effect. They take
+ // priority over any parameters specified in the RenderPasses below
+ // (none provided in this example). In turn these parameters can be
+ // overwritten by specifying them in a Material that references this
+ // effect.
+ // The priority order is:
+ //
+ // Material -> Effect -> Technique -> RenderPass -> GLSL default values
+ parameters: [
+ Parameter { name: "ambient"; value: Qt.vector3d( 0.1, 0.1, 0.1 ) },
+ Parameter { name: "diffuse"; value: Qt.vector3d( 0.7, 0.7, 0.7 ) },
+ Parameter { name: "specular"; value: Qt.vector3d( 0.95, 0.95, 0.95 ) },
+ Parameter { name: "shininess"; value: root.shininess }
+ ]
+
+ techniques: [
+ Technique {
+ criteria : [
+ TechniqueCriterion {
+ criterionType: TechniqueCriterion.RenderingStyle
+ criterionValue : "forward"
+ }
+ ]
+
+ parameters : [
+ Parameter { name: "lightPosition"; value: Qt.vector4d( 0.0, 0.0, 0.0, 1.0 ) },
+ Parameter { name: "lightIntensity"; value: Qt.vector3d( 0.7, 0.7, 0.7 ) }
+ ]
+
+ renderPasses: [
+ RenderPass {
+ criteria: []
+
+ // The bindings property allows us to map from names of parameters (uniforms or vertex attributes)
+ // within a shader to more friendly names in QML. By default the parameter names are exposed from
+ // the shader so we only need to add add mappings where the names differ. E.g. here we map from the
+ // ka uniform name in the shader to a property called ambient
+ bindings: [
+ // Uniforms (those provided by the user)
+ ParameterMapper { parameterName: "ambient"; shaderVariableName: "ka"; bindingType: ParameterMapper.Uniform},
+ ParameterMapper { parameterName: "diffuse"; shaderVariableName: "kd"; bindingType: ParameterMapper.Uniform},
+ ParameterMapper { parameterName: "specular"; shaderVariableName: "ks"; bindingType: ParameterMapper.Uniform}
+ ]
+
+ shaderProgram: ShaderProgram {
+ vertexSourceFile: ":/shaders/phong.vert"
+ fragmentSourceFile: ":/shaders/phong.frag"
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/examples/rollerball/AdsMaterial.qml b/examples/rollerball/AdsMaterial.qml
new file mode 100644
index 000000000..cf8718458
--- /dev/null
+++ b/examples/rollerball/AdsMaterial.qml
@@ -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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt3D 2.0
+import Qt3D.Render 2.0
+
+// For Qt.vector3d() and friends. For some reason this is provided by
+// QQuickValueTypeProvider in QtQuick rather than the default value
+// type provider in QtQml. So we will need to replicate this in Qt3D
+// for the types that we wish to support. Otherwise we'll have to import
+// QtQuick 2.1 all over the place.
+import QtQuick 2.1 as QQ2
+
+Material {
+ id: root
+
+ property color ambient: Qt.rgba( 0.05, 0.05, 0.05, 1.0 )
+ property color diffuse: Qt.rgba( 0.7, 0.7, 0.7, 1.0 )
+ property color specular: Qt.rgba( 0.95, 0.95, 0.95, 1.0 )
+ property real shininess: 150.0
+
+ parameters: [
+ Parameter { name: "ambient"; value: Qt.vector3d(root.ambient.r, root.ambient.g, root.ambient.b) },
+ Parameter { name: "diffuse"; value: Qt.vector3d(root.diffuse.r, root.diffuse.g, root.diffuse.b) },
+ Parameter { name: "specular"; value: Qt.vector3d(root.specular.r, root.specular.g, root.specular.b) },
+ Parameter { name: "shininess"; value: root.shininess }
+ ]
+}
diff --git a/examples/rollerball/BallEntity.qml b/examples/rollerball/BallEntity.qml
new file mode 100644
index 000000000..458e15b77
--- /dev/null
+++ b/examples/rollerball/BallEntity.qml
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt3D 2.0
+import Qt3D.Render 2.0
+
+// For Qt.vector3d() and friends. For some reason this is provided by
+// QQuickValueTypeProvider in QtQuick rather than the default value
+// type provider in QtQml. So we will need to replicate this in Qt3D
+// for the types that we wish to support. Otherwise we'll have to import
+// QtQuick 2.1 all over the place.
+import QtQuick 2.1 as QQ2
+
+Entity {
+ id: root
+
+ property real x: 0.0
+ property real y: 0.0
+ property real z: 0.0
+ property real scale: 1.0
+ property Material material
+
+ components: [ transform, mesh, root.material ]
+
+ Transform {
+ id: transform
+ Translate { dx: root.x; dy: root.y; dz: root.z }
+ Scale { scale: root.scale }
+ }
+
+ SphereMesh {
+ id: mesh
+ rings: 50
+ slices: 100
+ }
+}
diff --git a/examples/rollerball/BasicCamera.qml b/examples/rollerball/BasicCamera.qml
new file mode 100644
index 000000000..1c338e7b4
--- /dev/null
+++ b/examples/rollerball/BasicCamera.qml
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt3D 2.0
+import Qt3D.Render 2.0
+
+// For Qt.vector3d() and friends. For some reason this is provided by
+// QQuickValueTypeProvider in QtQuick rather than the default value
+// type provider in QtQml. So we will need to replicate this in Qt3D
+// for the types that we wish to support. Otherwise we'll have to import
+// QtQuick 2.1 all over the place.
+import QtQuick 2.1 as QQ2
+
+Camera {
+ id: mainCamera
+ objectName: "mainCamera"
+
+ lens: CameraLens {
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 22.5
+ aspectRatio: 16 / 9 // TODO: Hook up to window aspect ratio
+ nearPlane: 0.01
+ farPlane: 1000.0
+ }
+
+ transform: Transform {
+ LookAt {
+ position: Qt.vector3d( 0.0, 0.0, 50.0 )
+ viewCenter: Qt.vector3d( 0.0, 0.0, 10.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ }
+ }
+}
diff --git a/examples/rollerball/ForwardRenderer.qml b/examples/rollerball/ForwardRenderer.qml
new file mode 100644
index 000000000..6ab3107e1
--- /dev/null
+++ b/examples/rollerball/ForwardRenderer.qml
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt3D 2.0
+import Qt3D.Render 2.0
+
+TechniqueFilter {
+ id: root
+ objectName : "techniqueFilter"
+
+ // Expose camera to allow user to choose which camera to use for rendering
+ property alias camera: cameraSelector.camera
+
+ // Select the forward rendering Technique of any used Effect
+ criteria : [
+ TechniqueCriterion {
+ criterionType: TechniqueCriterion.RenderingStyle;
+ criterionValue : "forward"
+ }
+ ]
+
+ // Use the whole viewport
+ Viewport {
+ id: viewport
+ objectName : "viewport"
+ rect: Qt.rect(0.0, 0.0, 1.0, 1.0)
+
+ // Use the specified camera
+ CameraSelector {
+ id : cameraSelector
+ objectName : "cameraSelector"
+
+ // Use a single pass called "lighting" from the selected Technique
+ RenderPassFilter { renderPassName: "lighting" }
+ }
+ }
+}
diff --git a/examples/rollerball/main.cpp b/examples/rollerball/main.cpp
new file mode 100644
index 000000000..7c230ea8a
--- /dev/null
+++ b/examples/rollerball/main.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <Qt3DQuick/quickwindow.h>
+#include <Qt3DRenderer/rendereraspect.h>
+#include <Qt3DBulletPhysics/bulletphysicsaspect.h>
+
+#include <exampleresources.h>
+
+#include <QGuiApplication>
+#include <QtQml>
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ initializeAssetResources("../exampleresources/example-assets.qrb");
+
+ Qt3D::Quick::QuickWindow view;
+ view.registerAspect(new Qt3D::RendererAspect());
+ view.registerAspect(new Qt3D::BulletPhysicsAspect());
+ // There should be some synchronising mechanism to make sure
+ // the source is set after all aspects have been completely initialized
+ // Otherwise we might encounter cases where an Aspect's QML elements have
+ // not yet been registered
+ view.setSource(QUrl("qrc:/main.qml"));
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/rollerball/main.qml b/examples/rollerball/main.qml
new file mode 100644
index 000000000..c6e56d7f4
--- /dev/null
+++ b/examples/rollerball/main.qml
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt3D 2.0
+import Qt3D.Render 2.0
+
+// For Qt.vector3d() and friends. For some reason this is provided by
+// QQuickValueTypeProvider in QtQuick rather than the default value
+// type provider in QtQml. So we will need to replicate this in Qt3D
+// for the types that we wish to support. Otherwise we'll have to import
+// QtQuick 2.1 all over the place.
+import QtQuick 2.1 as QQ2
+
+Entity {
+ id: root
+ objectName: "root"
+
+ // Use the renderer configuration specified in ForwardRenderer.qml
+ // and render from the mainCamera
+ components: [
+ FrameGraph {
+ activeFrameGraph: ForwardRenderer {
+ id: renderer
+ camera: mainCamera
+ }
+ }
+ ]
+
+ BasicCamera {
+ id: mainCamera
+ }
+
+ Configuration {
+ controlledCamera: mainCamera
+ }
+
+ AdsEffect {
+ id: adsEffect
+ }
+
+ AdsMaterial {
+ id: redMaterial
+ effect: adsEffect
+ ambient: Qt.rgba( 0.5, 0.0, 0.0, 1.0 )
+ }
+
+ AdsMaterial {
+ id: greenMaterial
+ effect: adsEffect
+ ambient: Qt.rgba( 0.0, 0.5, 0.0, 1.0 )
+ }
+
+ AdsMaterial {
+ id: blueMaterial
+ effect: adsEffect
+ ambient: Qt.rgba( 0.0, 0.0, 0.5, 1.0 )
+ }
+
+ BallEntity {
+ id: redBall
+ material: redMaterial
+ x: -5
+ }
+
+ BallEntity {
+ id: greenBall
+ material: greenMaterial
+ }
+
+ BallEntity {
+ id: blueBall
+ material: blueMaterial
+ x: 5
+ }
+}
diff --git a/examples/rollerball/rollerball.pro b/examples/rollerball/rollerball.pro
new file mode 100644
index 000000000..ec3071736
--- /dev/null
+++ b/examples/rollerball/rollerball.pro
@@ -0,0 +1,20 @@
+TEMPLATE = app
+
+QT += 3dcore 3drenderer 3dbulletphysics 3dquick qml quick
+
+include("../exampleresources/exampleresources.pri")
+
+HEADERS += \
+
+SOURCES += \
+ main.cpp
+
+OTHER_FILES += \
+ main.qml \
+ AdsEffect.qml \
+ Renderable.qml \
+ SimpleEffect.qml \
+ ForwardRenderer.qml
+
+RESOURCES += \
+ rollerball.qrc
diff --git a/examples/rollerball/rollerball.qrc b/examples/rollerball/rollerball.qrc
new file mode 100644
index 000000000..e51927697
--- /dev/null
+++ b/examples/rollerball/rollerball.qrc
@@ -0,0 +1,10 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>AdsEffect.qml</file>
+ <file>ForwardRenderer.qml</file>
+ <file>BasicCamera.qml</file>
+ <file>AdsMaterial.qml</file>
+ <file>BallEntity.qml</file>
+ </qresource>
+</RCC>
diff --git a/src/render/render.pro b/src/render/render.pro
index ad4f5870f..61b33774e 100644
--- a/src/render/render.pro
+++ b/src/render/render.pro
@@ -17,7 +17,7 @@ include(../3rdparty/assimp/assimp.pri)
RESOURCES += $$PWD/render.qrc
OTHER_FILES += \
- $$PWD/shaders/*
+ $$PWD/shaders/* \
gcov {
CONFIG += static
diff --git a/src/render/render.qrc b/src/render/render.qrc
index fde4905a7..a66d24c11 100644
--- a/src/render/render.qrc
+++ b/src/render/render.qrc
@@ -4,5 +4,7 @@
<file>shaders/basic.vert</file>
<file>shaders/diffuse.frag</file>
<file>shaders/diffuse.vert</file>
+ <file>shaders/phong.frag</file>
+ <file>shaders/phong.vert</file>
</qresource>
</RCC>
diff --git a/src/render/shaders/phong.frag b/src/render/shaders/phong.frag
new file mode 100644
index 000000000..741f4da9f
--- /dev/null
+++ b/src/render/shaders/phong.frag
@@ -0,0 +1,45 @@
+#version 150 core
+
+// TODO: Replace with a uniform block
+uniform vec4 lightPosition = vec4(1.0, 1.0, 0.0, 1.0);
+uniform vec3 lightIntensity = vec3(1.0, 0.0, 1.0);
+
+// TODO: Replace with a struct
+uniform vec3 ka; // Ambient reflectivity
+uniform vec3 kd; // Diffuse reflectivity
+uniform vec3 ks; // Specular reflectivity
+uniform float shininess; // Specular shininess factor
+
+in vec3 position;
+in vec3 normal;
+
+out vec4 fragColor;
+
+vec3 adsModel( const in vec3 pos, const in vec3 n )
+{
+ // Calculate the vector from the light to the fragment
+ vec3 s = normalize( vec3( lightPosition ) - 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 ambient, diffuse and specular contributions
+ return lightIntensity * ( ka + kd * diffuse + ks * specular );
+}
+
+void main()
+{
+ fragColor = vec4( adsModel( position, normalize( normal ) ), 1.0 );
+}
diff --git a/src/render/shaders/phong.vert b/src/render/shaders/phong.vert
new file mode 100644
index 000000000..c0f907f29
--- /dev/null
+++ b/src/render/shaders/phong.vert
@@ -0,0 +1,19 @@
+#version 150 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+
+out vec3 position;
+out vec3 normal;
+
+uniform mat4 modelView;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+void main()
+{
+ normal = normalize( modelViewNormal * vertexNormal );
+ position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}