summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/clip-planes-qml
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire350@gmail.com>2015-07-19 18:17:02 +0200
committerPaul Lemire <paul.lemire@kdab.com>2015-07-29 06:09:04 +0000
commite87187e9a0d6acb18c874ac27fc565bda1d51e6e (patch)
tree7db52a6e93c778f2683c4e9a18455a74960cc7e5 /examples/qt3d/clip-planes-qml
parentf05c1d69e415187b32bfc419d89cbd38265f9de0 (diff)
clip-planes-qml examples
Demonstrates use of: -StencilOp / StencilTest -StateSet and nested StateSet -ClipPlane -Multiple render passes with different shaders -Use of layers Change-Id: I2d3f87e99e1fdbf9ed22e81838d6cc1744b6b8c1 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples/qt3d/clip-planes-qml')
-rw-r--r--examples/qt3d/clip-planes-qml/CappingMaterialEffect.qml79
-rw-r--r--examples/qt3d/clip-planes-qml/ClipCappingFrameGraph.qml131
-rw-r--r--examples/qt3d/clip-planes-qml/ClipMaterialEffect.qml86
-rw-r--r--examples/qt3d/clip-planes-qml/ClipPlaneEntity.qml74
-rw-r--r--examples/qt3d/clip-planes-qml/ClippingPlanes.qml166
-rw-r--r--examples/qt3d/clip-planes-qml/PlaneVisualizationMaterial.qml120
-rw-r--r--examples/qt3d/clip-planes-qml/capping.frag13
-rw-r--r--examples/qt3d/clip-planes-qml/capping.geom80
-rw-r--r--examples/qt3d/clip-planes-qml/capping.vert15
-rw-r--r--examples/qt3d/clip-planes-qml/clip-planes-qml.pro11
-rw-r--r--examples/qt3d/clip-planes-qml/clip-planes-qml.qrc17
-rw-r--r--examples/qt3d/clip-planes-qml/main.cpp62
-rw-r--r--examples/qt3d/clip-planes-qml/main.qml104
-rw-r--r--examples/qt3d/clip-planes-qml/passthrough.frag13
-rw-r--r--examples/qt3d/clip-planes-qml/phong-clip.frag47
-rw-r--r--examples/qt3d/clip-planes-qml/phong-clip.vert38
16 files changed, 1056 insertions, 0 deletions
diff --git a/examples/qt3d/clip-planes-qml/CappingMaterialEffect.qml b/examples/qt3d/clip-planes-qml/CappingMaterialEffect.qml
new file mode 100644
index 000000000..9becbc217
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/CappingMaterialEffect.qml
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Paul Lemire
+** 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 2.0
+import Qt3D.Renderer 2.0
+
+Effect {
+
+ property ShaderData sectionsData;
+
+ parameters: [
+ Parameter { name: "ka"; value: "black" },
+ Parameter { name: "kd"; value: "blue" },
+ Parameter { name: "ks"; value: "white" },
+ Parameter { name: "shininess"; value: 100 },
+ Parameter { name: "lightPosition"; value: Qt.vector4d(1.0, 1.0, 0.0, 1.0) },
+ Parameter { name: "lightIntensity"; value: Qt.vector3d(1.0, 1.0, 1.0) },
+ Parameter { name: "sectionsData"; value: sectionsData }
+ ]
+
+ techniques: [
+ Technique {
+
+ openGLFilter {
+ api: OpenGLFilter.Desktop
+ profile: OpenGLFilter.None
+ majorVersion: 3
+ minorVersion: 2
+ }
+
+ renderPasses: [
+ // Capping pass: generate planes given clipping plane equations
+ // to be rendered with the phong material
+ RenderPass {
+ annotations: Annotation { name: "pass"; value: "capping" }
+ shaderProgram: ShaderProgram {
+ vertexShaderCode: loadSource("qrc:/capping.vert")
+ geometryShaderCode: loadSource("qrc:/capping.geom")
+ fragmentShaderCode: loadSource("qrc:/capping.frag")
+ }
+ }
+ ]
+ }
+ ]
+}
+
diff --git a/examples/qt3d/clip-planes-qml/ClipCappingFrameGraph.qml b/examples/qt3d/clip-planes-qml/ClipCappingFrameGraph.qml
new file mode 100644
index 000000000..2716fa25b
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/ClipCappingFrameGraph.qml
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Paul Lemire
+** 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 2.0
+import Qt3D.Renderer 2.0
+
+Viewport {
+ property alias camera: cameraSelector.camera
+
+ CameraSelector {
+ id: cameraSelector
+
+ StateSet {
+ // Enable 3 clipping planes
+ renderStates: [
+ ClipPlane { plane: 0 },
+ ClipPlane { plane: 1 },
+ ClipPlane { plane: 2 },
+ DepthTest { func: DepthTest.LessOrEqual }
+ ]
+
+ // Branch 1
+ LayerFilter {
+ // Render entities with their regular material
+ // Fills depth buffer for entities that are clipped
+ layers: ["content", "visualization"]
+ ClearBuffer {
+ buffers: ClearBuffer.ColorDepthBuffer
+ RenderPassFilter {
+ includes: Annotation { name: "pass"; value: "material" }
+ }
+ }
+ }
+
+ // Branch 2
+ ClearBuffer {
+ // Enable and fill Stencil to later generate caps
+ buffers: ClearBuffer.StencilBuffer
+ StateSet {
+ // Disable depth culling
+ // Incr for back faces
+ // Decr for front faces
+ // No need to output color values
+ renderStates: [
+ StencilTest {
+ front {
+ func: StencilTestSeparate.Always
+ ref: 0; mask: 0
+ }
+ back {
+ func: StencilTestSeparate.Always
+ ref: 0; mask: 0
+ }
+ },
+ StencilOp {
+ front.stencilDepthPass: StencilOpSeparate.Decr
+ back.stencilDepthPass: StencilOpSeparate.Incr
+ },
+ ColorMask { red: false; green: false; blue: false; alpha: false }
+ ]
+
+ LayerFilter {
+ layers: "content"
+ RenderPassFilter {
+ includes: Annotation { name: "pass"; value: "stencilFill"; }
+ }
+ }
+ }
+ }
+ }
+
+ // Branch 3
+ StateSet {
+ // Draw caps using stencil buffer
+ LayerFilter {
+ layers: "caps"
+ RenderPassFilter {
+ includes: Annotation { name: "pass"; value: "capping"; }
+ }
+ }
+
+ // Draw back faces - front faces -> caps
+ renderStates: [
+ StencilTest {
+ front {
+ func: StencilTestSeparate.NotEqual
+ ref: 0; mask: ~0
+ }
+ back {
+ func: StencilTestSeparate.NotEqual
+ ref: 0; mask: ~0
+ }
+ }
+ ]
+ }
+ }
+}
+
diff --git a/examples/qt3d/clip-planes-qml/ClipMaterialEffect.qml b/examples/qt3d/clip-planes-qml/ClipMaterialEffect.qml
new file mode 100644
index 000000000..c92732625
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/ClipMaterialEffect.qml
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Paul Lemire
+** 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 2.0
+import Qt3D.Renderer 2.0
+
+Effect {
+
+ property ShaderData sectionsData;
+
+ parameters: [
+ Parameter { name: "ka"; value: "black" },
+ Parameter { name: "kd"; value: "blue" },
+ Parameter { name: "ks"; value: "white" },
+ Parameter { name: "shininess"; value: 100 },
+ Parameter { name: "lightPosition"; value: Qt.vector4d(1.0, 1.0, 0.0, 1.0) },
+ Parameter { name: "lightIntensity"; value: Qt.vector3d(1.0, 1.0, 1.0) },
+ Parameter { name: "sectionsData"; value: sectionsData }
+ ]
+
+ techniques: [
+ Technique {
+
+ openGLFilter {
+ api: OpenGLFilter.Desktop
+ profile: OpenGLFilter.None
+ majorVersion: 3
+ minorVersion: 2
+ }
+
+ renderPasses: [
+
+ // Draw mesh with PhongMaterial and additional clipping planes
+ RenderPass {
+ annotations: Annotation { name: "pass"; value: "material" }
+ shaderProgram: ShaderProgram {
+ vertexShaderCode: loadSource("qrc:/phong-clip.vert")
+ fragmentShaderCode: loadSource("qrc:/phong-clip.frag")
+ }
+ },
+
+ // Basic stencil fill pass
+ RenderPass {
+ annotations: Annotation { name: "pass"; value: "stencilFill" }
+ shaderProgram: ShaderProgram {
+ vertexShaderCode: loadSource("qrc:/phong-clip.vert")
+ fragmentShaderCode: loadSource("qrc:/passthrough.frag")
+ }
+ }
+ ]
+ }
+ ]
+}
+
diff --git a/examples/qt3d/clip-planes-qml/ClipPlaneEntity.qml b/examples/qt3d/clip-planes-qml/ClipPlaneEntity.qml
new file mode 100644
index 000000000..76d721e7c
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/ClipPlaneEntity.qml
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Paul Lemire
+** 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 2.0
+import Qt3D.Renderer 2.0
+
+Entity {
+ id: root
+ property Material visualMaterial;
+ property alias rotateAngle: _rotate.angle
+ property alias rotateAxis: _rotate.axis
+
+ property vector3d center;
+ property vector3d normal;
+ readonly property vector4d equation: Qt.vector4d(normal.x,
+ normal.y,
+ normal.z,
+ -(normal.x * center.x +
+ normal.y * center.y +
+ normal.z * center.z))
+
+ PlaneMesh {
+ id: mesh
+ width: 20.0
+ height: 20.0
+ meshResolution: Qt.size(2, 2)
+ }
+
+ Transform {
+ id: transform
+ Rotate { id: _rotate }
+ Translate { translation: root.center }
+ }
+
+ property Layer layer: Layer {
+ names: "visualization"
+ }
+
+ components: [visualMaterial, mesh, transform, layer]
+}
+
diff --git a/examples/qt3d/clip-planes-qml/ClippingPlanes.qml b/examples/qt3d/clip-planes-qml/ClippingPlanes.qml
new file mode 100644
index 000000000..5fac3b709
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/ClippingPlanes.qml
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Paul Lemire
+** 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 2.0
+import Qt3D.Renderer 2.0
+import QtQuick 2.4 as QQ2
+
+Entity {
+ id: root
+ property ShaderData sectionData: ShaderData {
+ property real sectionsCount: 3
+ property ShaderDataArray sections: ShaderDataArray {
+ ShaderData {
+ property vector4d equation: clipPlane0.equation
+ property vector3d center: clipPlane0.center
+ }
+ ShaderData {
+ property vector4d equation: clipPlane1.equation
+ property vector3d center: clipPlane1.center
+ }
+ ShaderData {
+ property vector4d equation: clipPlane2.equation
+ property vector3d center: clipPlane2.center
+ }
+ }
+ }
+
+ Entity {
+ property Layer layer: Layer {
+ names: "caps"
+ }
+
+ property Material cappingMaterial: Material {
+ effect: CappingMaterialEffect {
+ sectionsData: root.sectionData
+ }
+ }
+
+ property PlaneMesh mesh: PlaneMesh {
+ width: 20.0
+ height: 20.0
+ meshResolution: Qt.size(2, 2)
+ }
+
+ components: [cappingMaterial, mesh, layer]
+ }
+
+ PlaneVisualizationMaterial {
+ id: clipPlanesMaterial
+ alpha: 0.5
+ }
+
+ // XZ
+ ClipPlaneEntity {
+ id: clipPlane0
+ visualMaterial: clipPlanesMaterial
+ center: Qt.vector3d(0, -10, 0)
+ normal: Qt.vector3d(0, -1.0, 0)
+ }
+ // XY
+ ClipPlaneEntity {
+ id: clipPlane1
+ visualMaterial: clipPlanesMaterial
+ center: Qt.vector3d(0, 0, 10)
+ normal: Qt.vector3d(0, 0, -1.0)
+ rotateAxis: Qt.vector3d(1.0, 0.0, 0.0)
+ rotateAngle: 90
+ }
+
+ // YZ
+ ClipPlaneEntity {
+ id: clipPlane2
+ visualMaterial: clipPlanesMaterial
+ center: Qt.vector3d(-10, 0, 0)
+ normal: Qt.vector3d(1.0, 0, 0)
+ rotateAxis: Qt.vector3d(0.0, 0.0, 1.0)
+ rotateAngle: -90
+ }
+
+ QQ2.SequentialAnimation {
+ running: true
+ loops: QQ2.Animation.Infinite
+ QQ2.NumberAnimation {
+ target: clipPlane0
+ property: "center.y"
+ from: 10
+ to: 0
+ duration: 2000
+ easing.type: QQ2.Easing.InOutQuart
+ }
+
+ QQ2.NumberAnimation {
+ target: clipPlane1
+ property: "center.z"
+ from: 10
+ to: 0
+ duration: 2000
+ easing.type: QQ2.Easing.InOutQuart
+ }
+ QQ2.NumberAnimation {
+ target: clipPlane2
+ property: "center.x"
+ from: -10
+ to: 0
+ duration: 4000
+ easing.type: QQ2.Easing.InOutQuart
+ }
+ QQ2.NumberAnimation {
+ target: clipPlane1
+ property: "center.z"
+ from: 0
+ to: 10
+ duration: 4000
+ easing.type: QQ2.Easing.InOutQuint
+ }
+ QQ2.NumberAnimation {
+ target: clipPlane0
+ property: "center.y"
+ from: 0
+ to: 10
+ duration: 2000
+ easing.type: QQ2.Easing.InOutQuint
+ }
+ QQ2.NumberAnimation {
+ target: clipPlane2
+ property: "center.x"
+ from: 0
+ to: -10
+ duration: 2000
+ easing.type: QQ2.Easing.InOutQuint
+ }
+ }
+}
diff --git a/examples/qt3d/clip-planes-qml/PlaneVisualizationMaterial.qml b/examples/qt3d/clip-planes-qml/PlaneVisualizationMaterial.qml
new file mode 100644
index 000000000..2e7579de6
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/PlaneVisualizationMaterial.qml
@@ -0,0 +1,120 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Paul Lemire
+** 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 2.0
+import Qt3D.Renderer 2.0
+
+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
+ property real alpha: 0.5
+
+
+ ShaderProgram {
+ id: gl3PhongAlphaShader
+ vertexShaderCode: loadSource("qrc:/shaders/gl3/phongalpha.vert")
+ fragmentShaderCode: loadSource("qrc:/shaders/gl3/phongalpha.frag")
+ }
+
+ ShaderProgram {
+ id: gl2es2PhongAlphaShader
+ vertexShaderCode: loadSource("qrc:/shaders/es2/phongalpha.vert")
+ fragmentShaderCode: loadSource("qrc:/shaders/es2/phongalpha.frag")
+ }
+
+ effect: Effect {
+
+ parameters: [
+ Parameter { name: "alpha"; value: root.alpha },
+ Parameter { name: "ka"; value: Qt.vector3d(root.ambient.r, root.ambient.g, root.ambient.b) },
+ Parameter { name: "kd"; value: Qt.vector3d(root.diffuse.r, root.diffuse.g, root.diffuse.b) },
+ Parameter { name: "ks"; value: Qt.vector3d(root.specular.r, root.specular.g, root.specular.b) },
+ Parameter { name: "shininess"; value: root.shininess },
+ Parameter { name: "lightPosition"; value: Qt.vector4d(1.0, 1.0, 0.0, 1.0) },
+ Parameter { name: "lightIntensity"; value: Qt.vector3d(1.0, 1.0, 1.0) }
+ ]
+
+ techniques: [
+ // GL 3 Technique
+ Technique {
+ openGLFilter {
+ api: OpenGLFilter.Desktop
+ profile: OpenGLFilter.Core
+ majorVersion: 3
+ minorVersion: 1
+ }
+ renderPasses: RenderPass {
+ shaderProgram: gl3PhongAlphaShader
+ renderStates: [
+ DepthMask { mask: false },
+ BlendState {
+ srcRGB: BlendState.SrcAlpha
+ dstRGB: BlendState.OneMinusSrcAlpha
+ },
+ BlendEquation {mode: BlendEquation.FuncAdd}
+ ]
+ annotations: Annotation { name: "pass"; value: "material" }
+ }
+ },
+
+ // GL 2 Technique
+ Technique {
+ openGLFilter {
+ api: OpenGLFilter.Desktop
+ profile: OpenGLFilter.None
+ majorVersion: 2
+ minorVersion: 0
+ }
+ renderPasses: RenderPass {
+ shaderProgram: gl2es2PhongAlphaShader
+ renderStates: [
+ DepthMask { mask: false },
+ BlendState {
+ srcRGB: BlendState.SrcAlpha
+ dstRGB: BlendState.OneMinusSrcAlpha
+ },
+ BlendEquation {mode: BlendEquation.FuncAdd}
+ ]
+ annotations: Annotation { name: "pass"; value: "material" }
+ }
+ }
+ ]
+ }
+}
+
diff --git a/examples/qt3d/clip-planes-qml/capping.frag b/examples/qt3d/clip-planes-qml/capping.frag
new file mode 100644
index 000000000..78c94b1d7
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/capping.frag
@@ -0,0 +1,13 @@
+#version 150 core
+
+out vec4 fragColor;
+
+in FragData {
+ vec3 fragPosition;
+ vec3 fragNormal;
+} f_in;
+
+void main()
+{
+ fragColor = vec4(0.0, 1.0, 0.0, 1.0) + (1.0 * vec4(f_in.fragPosition, 1.0));
+}
diff --git a/examples/qt3d/clip-planes-qml/capping.geom b/examples/qt3d/clip-planes-qml/capping.geom
new file mode 100644
index 000000000..a34d5e87b
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/capping.geom
@@ -0,0 +1,80 @@
+#version 150 core
+
+layout( triangles ) in;
+layout( triangle_strip, max_vertices = 24 ) out;
+
+struct Section {
+ vec4 equation;
+ vec3 center;
+};
+
+struct SectionsData {
+ int sectionsCount;
+ Section sections[8];
+};
+
+in VertexData {
+ vec3 position;
+} v_in[];
+
+out FragData {
+ vec3 fragPosition;
+ vec3 fragNormal;
+} v_out;
+
+uniform SectionsData sectionsData;
+uniform mat4 mvp;
+
+const float radius = 1000.0;
+
+void emitQuad(Section section)
+{
+ vec4 equation = section.equation;
+ vec3 center = section.center;
+ v_out.fragNormal = equation.xyz;
+
+ // generate tangent and bitangent
+ vec3 u = vec3(1.0f, 1.0f, 1.0f);
+
+ // 2 vectors a (xa, ya, za), b (xb, yb, zb) are orthogonal if:
+ // xaxb + yayb + zazb = 0 <=>
+ // zb = -(xaxb + yayb) / za
+ // yb = -(xaxb + zazb) / ya
+ // xb = -(yayb + zazb) / xa
+
+ if (equation.x != 0)
+ u.x = -(u.y * equation.y + u.z * equation.z) / equation.x;
+ else if (equation.y != 0)
+ u.y = -(u.x * equation.x + u.z * equation.z) / equation.y;
+ else if (equation.z != 0)
+ u.z = -(u.x* equation.x + u.y * equation.y) / equation.z;
+
+ u = normalize(u);
+ vec3 v = normalize(cross(u, equation.xyz)) * radius;
+ u *= radius;
+
+ v_out.fragPosition = v_in[0].position;
+ gl_Position = mvp * vec4(center + u + v, 1.0);
+ EmitVertex();
+
+ v_out.fragPosition = v_in[1].position;
+ gl_Position = mvp * vec4(center + u - v, 1.0);
+ EmitVertex();
+
+ v_out.fragPosition = v_in[2].position;
+ gl_Position = mvp * vec4(center - u + v, 1.0);
+ EmitVertex();
+
+ v_out.fragPosition = v_in[0].position;
+ gl_Position = mvp * vec4(center - u - v, 1.0);
+ EmitVertex();
+
+ EndPrimitive();
+}
+
+void main()
+{
+ for (int i = 0; i < sectionsData.sectionsCount; ++i) {
+ emitQuad(sectionsData.sections[i]);
+ }
+}
diff --git a/examples/qt3d/clip-planes-qml/capping.vert b/examples/qt3d/clip-planes-qml/capping.vert
new file mode 100644
index 000000000..6c270c418
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/capping.vert
@@ -0,0 +1,15 @@
+#version 150 core
+
+in vec3 vertexPosition;
+
+out VertexData {
+ vec3 position;
+} v_out;
+
+uniform mat4 mvp;
+
+void main()
+{
+ v_out.position = vertexPosition;
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}
diff --git a/examples/qt3d/clip-planes-qml/clip-planes-qml.pro b/examples/qt3d/clip-planes-qml/clip-planes-qml.pro
new file mode 100644
index 000000000..2f0a0500a
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/clip-planes-qml.pro
@@ -0,0 +1,11 @@
+!include( ../examples.pri ) {
+ error( "Couldn't find the examples.pri file!" )
+}
+
+QT += qml quick 3dcore 3drenderer 3dinput 3dquick
+
+SOURCES += main.cpp
+
+RESOURCES += \
+ clip-planes-qml.qrc \
+ ../exampleresources/obj.qrc
diff --git a/examples/qt3d/clip-planes-qml/clip-planes-qml.qrc b/examples/qt3d/clip-planes-qml/clip-planes-qml.qrc
new file mode 100644
index 000000000..54a145a14
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/clip-planes-qml.qrc
@@ -0,0 +1,17 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>ClipMaterialEffect.qml</file>
+ <file>ClipCappingFrameGraph.qml</file>
+ <file>ClipPlaneEntity.qml</file>
+ <file>phong-clip.frag</file>
+ <file>phong-clip.vert</file>
+ <file>passthrough.frag</file>
+ <file>capping.geom</file>
+ <file>ClippingPlanes.qml</file>
+ <file>CappingMaterialEffect.qml</file>
+ <file>PlaneVisualizationMaterial.qml</file>
+ <file>capping.frag</file>
+ <file>capping.vert</file>
+ </qresource>
+</RCC>
diff --git a/examples/qt3d/clip-planes-qml/main.cpp b/examples/qt3d/clip-planes-qml/main.cpp
new file mode 100644
index 000000000..1f2035d3e
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Paul Lemire
+** 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$
+**
+****************************************************************************/
+
+#include <window.h>
+#include <Qt3DRenderer/QRenderAspect>
+#include <Qt3DInput/QInputAspect>
+#include <Qt3DQuick/QQmlAspectEngine>
+
+#include <QGuiApplication>
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ Window view;
+ Qt3D::Quick::QQmlAspectEngine engine;
+ engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect());
+ engine.aspectEngine()->registerAspect(new Qt3D::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.setSource(QUrl("qrc:/main.qml"));
+
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/qt3d/clip-planes-qml/main.qml b/examples/qt3d/clip-planes-qml/main.qml
new file mode 100644
index 000000000..d12ff44f6
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/main.qml
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Paul Lemire
+** 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 2.0
+import Qt3D.Renderer 2.0
+
+Entity {
+ id: root
+
+ Camera {
+ id: camera
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 45
+ aspectRatio: 800/600
+ nearPlane : 0.1
+ farPlane : 1000.0
+ position: Qt.vector3d( 0.0, 0.0, 40.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
+ }
+
+ Configuration { controlledCamera: camera }
+
+ components: FrameGraph {
+ ClipCappingFrameGraph {
+ camera: camera;
+ clearColor: Qt.rgba(0.0, 0.5, 1, 1)
+ }
+ }
+
+ ClipMaterialEffect {
+ id: clipMaterialEffect
+ sectionsData: clippingPlanes.sectionData
+ }
+
+ ClippingPlanes {
+ id: clippingPlanes
+ }
+
+ // Entity being clipped
+ Entity {
+
+ property Material material: Material {
+ effect: clipMaterialEffect
+ parameters: [
+ Parameter { name: "ka"; value: "black" },
+ Parameter { name: "kd"; value: "blue" },
+ Parameter { name: "ks"; value: "white" }
+ ]
+ }
+
+ property Mesh mesh: Mesh {
+ source: "assets/obj/trefoil.obj"
+ }
+
+// property SphereMesh mesh: SphereMesh {
+// radius: 3
+// }
+
+ property Transform transform: Transform {
+ Translate { dx: 0 }
+ Scale { scale: 3 }
+ }
+
+ property Layer layer: Layer {
+ names: "content"
+ }
+
+ components: [material, transform, mesh, layer]
+ }
+}
diff --git a/examples/qt3d/clip-planes-qml/passthrough.frag b/examples/qt3d/clip-planes-qml/passthrough.frag
new file mode 100644
index 000000000..ab8310e07
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/passthrough.frag
@@ -0,0 +1,13 @@
+#version 150 core
+
+out vec4 fragColor;
+
+in VertexData {
+ vec3 position;
+ vec3 normal;
+} f_in;
+
+void main()
+{
+ fragColor = vec4(1.0, 1.0, 1.0, 1.0) * vec4(f_in.position, 1.0);
+}
diff --git a/examples/qt3d/clip-planes-qml/phong-clip.frag b/examples/qt3d/clip-planes-qml/phong-clip.frag
new file mode 100644
index 000000000..6ca37e764
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/phong-clip.frag
@@ -0,0 +1,47 @@
+#version 150 core
+
+// TODO: Replace with a uniform block
+uniform vec4 lightPosition;
+uniform vec3 lightIntensity;
+
+// 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 VertexData {
+ in vec4 position;
+ in vec3 normal;
+} v_in;
+
+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( v_in.position.xyz, normalize( v_in.normal ) ), 1.0 );
+}
diff --git a/examples/qt3d/clip-planes-qml/phong-clip.vert b/examples/qt3d/clip-planes-qml/phong-clip.vert
new file mode 100644
index 000000000..95b83bf75
--- /dev/null
+++ b/examples/qt3d/clip-planes-qml/phong-clip.vert
@@ -0,0 +1,38 @@
+#version 150 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+
+out VertexData {
+ vec3 position;
+ vec3 normal;
+} v_out;
+
+struct Section {
+ vec4 equation;
+ vec3 center;
+};
+
+struct SectionsData {
+ int sectionsCount;
+ Section sections[8];
+};
+
+uniform SectionsData sectionsData;
+uniform mat4 modelView;
+uniform mat4 modelMatrix;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+void main()
+{
+ v_out.normal = normalize( modelViewNormal * vertexNormal );
+ v_out.position = vec4(modelView * vec4( vertexPosition, 1.0 )).xyz;
+ vec3 worldPos = vec4(modelMatrix * vec4(vertexPosition, 1.0)).xyz;
+
+ for (int i = 0; i < sectionsData.sectionsCount; ++i) {
+ gl_ClipDistance[i] = dot(vec4(worldPos, 1.0), sectionsData.sections[i].equation);
+ }
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}