summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/wireframe
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qt3d/wireframe')
-rw-r--r--examples/qt3d/wireframe/BasicCamera.qml49
-rw-r--r--examples/qt3d/wireframe/TrefoilKnot.qml65
-rw-r--r--examples/qt3d/wireframe/WireframeEffect.qml86
-rw-r--r--examples/qt3d/wireframe/WireframeMaterial.qml58
-rw-r--r--examples/qt3d/wireframe/main.cpp71
-rw-r--r--examples/qt3d/wireframe/main.qml97
-rw-r--r--examples/qt3d/wireframe/shaders/robustwireframe.frag108
-rw-r--r--examples/qt3d/wireframe/shaders/robustwireframe.geom131
-rw-r--r--examples/qt3d/wireframe/shaders/robustwireframe.vert21
-rw-r--r--examples/qt3d/wireframe/wireframe.pro20
-rw-r--r--examples/qt3d/wireframe/wireframe.qrc12
11 files changed, 718 insertions, 0 deletions
diff --git a/examples/qt3d/wireframe/BasicCamera.qml b/examples/qt3d/wireframe/BasicCamera.qml
new file mode 100644
index 000000000..740dd54ce
--- /dev/null
+++ b/examples/qt3d/wireframe/BasicCamera.qml
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** 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 2.0
+import Qt3D.Render 2.0
+
+Camera {
+ id: mainCamera
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 22.5
+ aspectRatio: _window.width / _window.height
+ nearPlane: 0.01
+ farPlane: 1000.0
+ viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+}
diff --git a/examples/qt3d/wireframe/TrefoilKnot.qml b/examples/qt3d/wireframe/TrefoilKnot.qml
new file mode 100644
index 000000000..7b6faf852
--- /dev/null
+++ b/examples/qt3d/wireframe/TrefoilKnot.qml
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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 2.0
+import Qt3D.Render 2.0
+
+Entity {
+ id: root
+
+ property alias x: translation.dx
+ property alias y: translation.dy
+ property alias z: translation.dz
+ property alias scale: scaleTransform.scale
+ property alias theta: thetaRotation.angle
+ property alias phi: phiRotation.angle
+ property Material material
+
+ components: [ transform, mesh, root.material ]
+
+ Transform {
+ id: transform
+ Translate { id: translation }
+ Scale { id: scaleTransform }
+ Rotate{ id: thetaRotation; axis: Qt.vector3d( 1.0, 0.0, 0.0 ) }
+ Rotate{ id: phiRotation; axis: Qt.vector3d( 0.0, 1.0, 0.0 ) }
+ }
+
+ Mesh {
+ id: mesh
+ source: "assets/obj/trefoil.obj"
+ }
+}
diff --git a/examples/qt3d/wireframe/WireframeEffect.qml b/examples/qt3d/wireframe/WireframeEffect.qml
new file mode 100644
index 000000000..c8fe3bef8
--- /dev/null
+++ b/examples/qt3d/wireframe/WireframeEffect.qml
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** 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 2.0
+import Qt3D.Render 2.0
+
+Effect {
+ id: root
+
+ 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: 150.0 }
+ ]
+
+ techniques: [
+ Technique {
+ openGLFilter {
+ api: OpenGLFilter.Desktop
+ profile: OpenGLFilter.Core
+ majorVersion: 3
+ minorVersion: 1
+ }
+
+ annotations: [ Annotation { name: "renderingStyle"; value: "forward" } ]
+
+ parameters: [
+ Parameter { name: "light.position"; value: Qt.vector4d( 0.0, 0.0, 0.0, 1.0 ) },
+ Parameter { name: "light.intensity"; value: Qt.vector3d( 1.0, 1.0, 1.0 ) },
+ Parameter { name: "line.width"; value: 1.0 },
+ Parameter { name: "line.color"; value: Qt.vector4d( 1.0, 1.0, 1.0, 1.0 ) }
+ ]
+
+ renderPasses: [
+ RenderPass {
+
+ 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/robustwireframe.vert")
+ geometryShaderCode: loadSource("qrc:/shaders/robustwireframe.geom")
+ fragmentShaderCode: loadSource("qrc:/shaders/robustwireframe.frag")
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/examples/qt3d/wireframe/WireframeMaterial.qml b/examples/qt3d/wireframe/WireframeMaterial.qml
new file mode 100644
index 000000000..834ce657d
--- /dev/null
+++ b/examples/qt3d/wireframe/WireframeMaterial.qml
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** 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 2.0
+import Qt3D.Render 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 lineWidth: 0.8
+ property color lineColor: Qt.rgba( 0.0, 0.0, 0.0, 1.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 },
+ Parameter { name: "line.width"; value: root.lineWidth },
+ Parameter { name: "line.color"; value: root.lineColor }
+ ]
+}
diff --git a/examples/qt3d/wireframe/main.cpp b/examples/qt3d/wireframe/main.cpp
new file mode 100644
index 000000000..ecad579c9
--- /dev/null
+++ b/examples/qt3d/wireframe/main.cpp
@@ -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: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 <Qt3DCore/window.h>
+#include <Qt3DRenderer/qrenderaspect.h>
+#include <Qt3DInput/QInputAspect>
+#include <Qt3DQuick/QQmlAspectEngine>
+
+#include <exampleresources.h>
+
+#include <QGuiApplication>
+#include <QtQml>
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ initializeAssetResources("../exampleresources/example-assets.qrb");
+
+ Qt3D::Window view;
+ Qt3D::Quick::QQmlAspectEngine engine;
+
+ engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect());
+ engine.aspectEngine()->registerAspect(new Qt3D::QInputAspect());
+
+ // Expose the window as a context property so we can set the aspect ratio
+ engine.qmlEngine()->rootContext()->setContextProperty("_window", &view);
+ 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/wireframe/main.qml b/examples/qt3d/wireframe/main.qml
new file mode 100644
index 000000000..8a9506c1c
--- /dev/null
+++ b/examples/qt3d/wireframe/main.qml
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** 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 2.0
+import Qt3D.Render 2.0
+import QtQuick 2.1 as QQ2
+
+Entity {
+ id: root
+
+ // Render from the mainCamera
+ components: [
+ FrameGraph {
+ activeFrameGraph: ForwardRenderer {
+ id: renderer
+ camera: mainCamera
+ }
+ }
+ ]
+
+ BasicCamera {
+ id: mainCamera
+ position: Qt.vector3d( 0.0, 0.0, 15.0 )
+ }
+
+ Configuration {
+ controlledCamera: mainCamera
+ }
+
+ WireframeMaterial {
+ id: wireframeMaterial
+ effect: WireframeEffect {}
+ ambient: Qt.rgba( 0.2, 0.0, 0.0, 1.0 )
+ diffuse: Qt.rgba( 0.8, 0.0, 0.0, 1.0 )
+
+ QQ2.SequentialAnimation {
+ loops: QQ2.Animation.Infinite
+ running: true
+
+ QQ2.NumberAnimation {
+ target: wireframeMaterial;
+ property: "lineWidth";
+ duration: 1000;
+ from: 0.8
+ to: 1.8
+ }
+
+ QQ2.NumberAnimation {
+ target: wireframeMaterial;
+ property: "lineWidth";
+ duration: 1000;
+ from: 1.8
+ to: 0.8
+ }
+
+ QQ2.PauseAnimation { duration: 1500 }
+ }
+ }
+
+ TrefoilKnot {
+ id: trefoilKnot
+ material: wireframeMaterial
+ }
+}
diff --git a/examples/qt3d/wireframe/shaders/robustwireframe.frag b/examples/qt3d/wireframe/shaders/robustwireframe.frag
new file mode 100644
index 000000000..217e0e761
--- /dev/null
+++ b/examples/qt3d/wireframe/shaders/robustwireframe.frag
@@ -0,0 +1,108 @@
+#version 330 core
+
+uniform struct LightInfo {
+ vec4 position;
+ vec3 intensity;
+} light;
+
+uniform struct LineInfo {
+ float width;
+ vec4 color;
+} line;
+
+uniform vec3 ka; // Ambient reflectivity
+uniform vec3 kd; // Diffuse reflectivity
+uniform vec3 ks; // Specular reflectivity
+uniform float shininess; // Specular shininess factor
+
+in WireframeVertex {
+ vec3 position;
+ vec3 normal;
+ noperspective vec4 edgeA;
+ noperspective vec4 edgeB;
+ flat int configuration;
+} fs_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( light.position ) - pos );
+
+ // Calculate the vector from the fragment to the eye position (the
+ // origin since this is in "eye" or "camera" space
+ vec3 v = normalize( -pos );
+
+ // Refleft the light beam using the normal at this fragment
+ vec3 r = reflect( -s, n );
+
+ // Calculate the diffus component
+ vec3 diffuse = vec3( max( dot( s, n ), 0.0 ) );
+
+ // Calculate the specular component
+ vec3 specular = vec3( pow( max( dot( r, v ), 0.0 ), shininess ) );
+
+ // Combine the ambient, diffuse and specular contributions
+ return light.intensity * ( ka + kd * diffuse + ks * specular );
+}
+
+vec4 shadeLine( const in vec4 color )
+{
+ // Find the smallest distance between the fragment and a triangle edge
+ float d;
+ if ( fs_in.configuration == 0 )
+ {
+ // Common configuration
+ d = min( fs_in.edgeA.x, fs_in.edgeA.y );
+ d = min( d, fs_in.edgeA.z );
+ }
+ else
+ {
+ // Handle configuration where screen space projection breaks down
+ // Compute and compare the squared distances
+ vec2 AF = gl_FragCoord.xy - fs_in.edgeA.xy;
+ float sqAF = dot( AF, AF );
+ float AFcosA = dot( AF, fs_in.edgeA.zw );
+ d = abs( sqAF - AFcosA * AFcosA );
+
+ vec2 BF = gl_FragCoord.xy - fs_in.edgeB.xy;
+ float sqBF = dot( BF, BF );
+ float BFcosB = dot( BF, fs_in.edgeB.zw );
+ d = min( d, abs( sqBF - BFcosB * BFcosB ) );
+
+ // Only need to care about the 3rd edge for some configurations.
+ if ( fs_in.configuration == 1 || fs_in.configuration == 2 || fs_in.configuration == 4 )
+ {
+ float AFcosA0 = dot( AF, normalize( fs_in.edgeB.xy - fs_in.edgeA.xy ) );
+ d = min( d, abs( sqAF - AFcosA0 * AFcosA0 ) );
+ }
+
+ d = sqrt( d );
+ }
+
+ // Blend between line color and phong color
+ float mixVal;
+ if ( d < line.width - 1.0 )
+ {
+ mixVal = 1.0;
+ }
+ else if ( d > line.width + 1.0 )
+ {
+ mixVal = 0.0;
+ }
+ else
+ {
+ float x = d - ( line.width - 1.0 );
+ mixVal = exp2( -2.0 * ( x * x ) );
+ }
+
+ return mix( color, line.color, mixVal );
+}
+
+void main()
+{
+ // Calculate the color from the phong model
+ vec4 color = vec4( adsModel( fs_in.position, normalize( fs_in.normal ) ), 1.0 );
+ fragColor = shadeLine( color );
+}
diff --git a/examples/qt3d/wireframe/shaders/robustwireframe.geom b/examples/qt3d/wireframe/shaders/robustwireframe.geom
new file mode 100644
index 000000000..6eb0ecc76
--- /dev/null
+++ b/examples/qt3d/wireframe/shaders/robustwireframe.geom
@@ -0,0 +1,131 @@
+#version 330 core
+
+layout( triangles ) in;
+layout( triangle_strip, max_vertices = 3 ) out;
+
+in EyeSpaceVertex {
+ vec3 position;
+ vec3 normal;
+} gs_in[];
+
+out WireframeVertex {
+ vec3 position;
+ vec3 normal;
+ noperspective vec4 edgeA;
+ noperspective vec4 edgeB;
+ flat int configuration;
+} gs_out;
+
+uniform mat4 viewportMatrix;
+
+const int infoA[] = int[]( 0, 0, 0, 0, 1, 1, 2 );
+const int infoB[] = int[]( 1, 1, 2, 0, 2, 1, 2 );
+const int infoAd[] = int[]( 2, 2, 1, 1, 0, 0, 0 );
+const int infoBd[] = int[]( 2, 2, 1, 2, 0, 2, 1 );
+
+vec2 transformToViewport( const in vec4 p )
+{
+ return vec2( viewportMatrix * ( p / p.w ) );
+}
+
+void main()
+{
+ gs_out.configuration = int(gl_in[0].gl_Position.z < 0) * int(4)
+ + int(gl_in[1].gl_Position.z < 0) * int(2)
+ + int(gl_in[2].gl_Position.z < 0);
+
+ // If all vertices are behind us, cull the primitive
+ if (gs_out.configuration == 7)
+ return;
+
+ // Transform each vertex into viewport space
+ vec2 p[3];
+ p[0] = transformToViewport( gl_in[0].gl_Position );
+ p[1] = transformToViewport( gl_in[1].gl_Position );
+ p[2] = transformToViewport( gl_in[2].gl_Position );
+
+ if (gs_out.configuration == 0)
+ {
+ // Common configuration where all vertices are within the viewport
+ gs_out.edgeA = vec4(0.0);
+ gs_out.edgeB = vec4(0.0);
+
+ // Calculate lengths of 3 edges of triangle
+ float a = length( p[1] - p[2] );
+ float b = length( p[2] - p[0] );
+ float c = length( p[1] - p[0] );
+
+ // Calculate internal angles using the cosine rule
+ float alpha = acos( ( b * b + c * c - a * a ) / ( 2.0 * b * c ) );
+ float beta = acos( ( a * a + c * c - b * b ) / ( 2.0 * a * c ) );
+
+ // Calculate the perpendicular distance of each vertex from the opposing edge
+ float ha = abs( c * sin( beta ) );
+ float hb = abs( c * sin( alpha ) );
+ float hc = abs( b * sin( alpha ) );
+
+ // Now add this perpendicular distance as a per-vertex property in addition to
+ // the position and normal calculated in the vertex shader.
+
+ // Vertex 0 (a)
+ gs_out.edgeA = vec4( ha, 0.0, 0.0, 0.0 );
+ gs_out.normal = gs_in[0].normal;
+ gs_out.position = gs_in[0].position;
+ gl_Position = gl_in[0].gl_Position;
+ EmitVertex();
+
+ // Vertex 1 (b)
+ gs_out.edgeA = vec4( 0.0, hb, 0.0, 0.0 );
+ gs_out.normal = gs_in[1].normal;
+ gs_out.position = gs_in[1].position;
+ gl_Position = gl_in[1].gl_Position;
+ EmitVertex();
+
+ // Vertex 2 (c)
+ gs_out.edgeA = vec4( 0.0, 0.0, hc, 0.0 );
+ gs_out.normal = gs_in[2].normal;
+ gs_out.position = gs_in[2].position;
+ gl_Position = gl_in[2].gl_Position;
+ EmitVertex();
+
+ // Finish the primitive off
+ EndPrimitive();
+ }
+ else
+ {
+ // Viewport projection breaks down for one or two vertices.
+ // Caclulate what we can here and defer rest to fragment shader.
+ // Since this is coherent for the entire primitive the conditional
+ // in the fragment shader is still cheap as all concurrent
+ // fragment shader invocations will take the same code path.
+
+ // Copy across the viewport-space points for the (up to) two vertices
+ // in the viewport
+ gs_out.edgeA.xy = p[infoA[gs_out.configuration]];
+ gs_out.edgeB.xy = p[infoB[gs_out.configuration]];
+
+ // Copy across the viewport-space edge vectors for the (up to) two vertices
+ // in the viewport
+ gs_out.edgeA.zw = normalize( gs_out.edgeA.xy - p[ infoAd[gs_out.configuration] ] );
+ gs_out.edgeB.zw = normalize( gs_out.edgeB.xy - p[ infoBd[gs_out.configuration] ] );
+
+ // Pass through the other vertex attributes
+ gs_out.normal = gs_in[0].normal;
+ gs_out.position = gs_in[0].position;
+ gl_Position = gl_in[0].gl_Position;
+ EmitVertex();
+
+ gs_out.normal = gs_in[1].normal;
+ gs_out.position = gs_in[1].position;
+ gl_Position = gl_in[1].gl_Position;
+ EmitVertex();
+
+ gs_out.normal = gs_in[2].normal;
+ gs_out.position = gs_in[2].position;
+ gl_Position = gl_in[2].gl_Position;
+ EmitVertex();
+
+ // Finish the primitive off
+ EndPrimitive();
+ }
+}
diff --git a/examples/qt3d/wireframe/shaders/robustwireframe.vert b/examples/qt3d/wireframe/shaders/robustwireframe.vert
new file mode 100644
index 000000000..e53a2b594
--- /dev/null
+++ b/examples/qt3d/wireframe/shaders/robustwireframe.vert
@@ -0,0 +1,21 @@
+#version 330 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+
+out EyeSpaceVertex {
+ vec3 position;
+ vec3 normal;
+} vs_out;
+
+uniform mat4 modelView;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+void main()
+{
+ vs_out.normal = normalize( modelViewNormal * vertexNormal );
+ vs_out.position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
+}
diff --git a/examples/qt3d/wireframe/wireframe.pro b/examples/qt3d/wireframe/wireframe.pro
new file mode 100644
index 000000000..2b2fd991a
--- /dev/null
+++ b/examples/qt3d/wireframe/wireframe.pro
@@ -0,0 +1,20 @@
+TEMPLATE = app
+
+QT += 3dcore 3drenderer 3dinput 3dquick qml quick
+
+include("../exampleresources/exampleresources.pri")
+
+HEADERS += \
+
+SOURCES += \
+ main.cpp
+
+OTHER_FILES += \
+ main.qml \
+ BasicCamera.qml \
+ WireframeEffect.qml \
+ WireframeMaterial.qml \
+ TrefoilKnot.qml
+
+RESOURCES += \
+ wireframe.qrc
diff --git a/examples/qt3d/wireframe/wireframe.qrc b/examples/qt3d/wireframe/wireframe.qrc
new file mode 100644
index 000000000..c73c8418c
--- /dev/null
+++ b/examples/qt3d/wireframe/wireframe.qrc
@@ -0,0 +1,12 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>BasicCamera.qml</file>
+ <file>TrefoilKnot.qml</file>
+ <file>WireframeEffect.qml</file>
+ <file>WireframeMaterial.qml</file>
+ <file>shaders/robustwireframe.frag</file>
+ <file>shaders/robustwireframe.geom</file>
+ <file>shaders/robustwireframe.vert</file>
+ </qresource>
+</RCC>