summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2020-06-30 15:23:41 +0200
committerPaul Lemire <paul.lemire@kdab.com>2020-07-01 13:54:58 +0200
commitb449577d087ce02b99b5ca3e57fb80e16393af6f (patch)
tree3258698bb5f7726985bd36531afd7116ea88ee56 /tests
parent0c22568047c792a41b0cec43f85e1ce7fd54a35a (diff)
Fix clip-planes-qml manual test
- Add shaders that were removed - Use qrc: prefix on mesh source Change-Id: I2293a17572f7a5ff323beece0a860b7762265dbc Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/clip-planes-qml/CMakeLists.txt3
-rw-r--r--tests/manual/clip-planes-qml/PlaneVisualizationMaterial.qml32
-rw-r--r--tests/manual/clip-planes-qml/default.vert82
-rw-r--r--tests/manual/clip-planes-qml/light.inc.frag222
-rw-r--r--tests/manual/clip-planes-qml/main.qml2
-rw-r--r--tests/manual/clip-planes-qml/phongalpha.frag74
6 files changed, 384 insertions, 31 deletions
diff --git a/tests/manual/clip-planes-qml/CMakeLists.txt b/tests/manual/clip-planes-qml/CMakeLists.txt
index b29245c8a..b2bb7d110 100644
--- a/tests/manual/clip-planes-qml/CMakeLists.txt
+++ b/tests/manual/clip-planes-qml/CMakeLists.txt
@@ -34,6 +34,9 @@ set(clip-planes-qml_resource_files
"passthrough.frag"
"phong-clip.frag"
"phong-clip.vert"
+ "default.vert"
+ "phongalpha.frag"
+ "light.inc.frag"
)
qt_add_resource(clip-planes-qml "clip-planes-qml"
diff --git a/tests/manual/clip-planes-qml/PlaneVisualizationMaterial.qml b/tests/manual/clip-planes-qml/PlaneVisualizationMaterial.qml
index 72903c9d2..bc154ad28 100644
--- a/tests/manual/clip-planes-qml/PlaneVisualizationMaterial.qml
+++ b/tests/manual/clip-planes-qml/PlaneVisualizationMaterial.qml
@@ -62,14 +62,8 @@ Material {
ShaderProgram {
id: gl3PhongAlphaShader
- vertexShaderCode: loadSource("qrc:/shaders/gl3/phong.vert")
- fragmentShaderCode: loadSource("qrc:/shaders/gl3/phongalpha.frag")
- }
-
- ShaderProgram {
- id: gl2es2PhongAlphaShader
- vertexShaderCode: loadSource("qrc:/shaders/es2/phong.vert")
- fragmentShaderCode: loadSource("qrc:/shaders/es2/phongalpha.frag")
+ vertexShaderCode: loadSource("qrc:/default.vert")
+ fragmentShaderCode: loadSource("qrc:/phongalpha.frag")
}
effect: Effect {
@@ -105,28 +99,6 @@ Material {
]
filterKeys: FilterKey { name: "pass"; value: "material" }
}
- },
-
- // GL 2 Technique
- Technique {
- graphicsApiFilter {
- api: GraphicsApiFilter.OpenGL
- profile: GraphicsApiFilter.NoProfile
- majorVersion: 2
- minorVersion: 0
- }
- renderPasses: RenderPass {
- shaderProgram: gl2es2PhongAlphaShader
- renderStates: [
- NoDepthMask { },
- BlendEquationArguments {
- sourceRgb: BlendEquationArguments.SourceAlpha
- destinationRgb: BlendEquationArguments.OneMinusSourceAlpha
- },
- BlendEquation {blendFunction: BlendEquation.Add}
- ]
- filterKeys: FilterKey { name: "pass"; value: "material" }
- }
}
]
}
diff --git a/tests/manual/clip-planes-qml/default.vert b/tests/manual/clip-planes-qml/default.vert
new file mode 100644
index 000000000..f97cd099d
--- /dev/null
+++ b/tests/manual/clip-planes-qml/default.vert
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+in vec4 vertexTangent;
+in vec2 vertexTexCoord;
+
+out vec3 worldPosition;
+out vec3 worldNormal;
+out vec4 worldTangent;
+out vec2 texCoord;
+
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
+uniform mat4 modelViewProjection;
+
+uniform float texCoordScale;
+
+void main()
+{
+ // Pass through scaled texture coordinates
+ texCoord = vertexTexCoord * texCoordScale;
+
+ // Transform position, normal, and tangent to world space
+ worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0));
+ worldNormal = normalize(modelNormalMatrix * vertexNormal);
+ worldTangent.xyz = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0)));
+ worldTangent.w = vertexTangent.w;
+
+ // Calculate vertex position in clip coordinates
+ gl_Position = modelViewProjection * vec4(vertexPosition, 1.0);
+}
diff --git a/tests/manual/clip-planes-qml/light.inc.frag b/tests/manual/clip-planes-qml/light.inc.frag
new file mode 100644
index 000000000..ce5c581cf
--- /dev/null
+++ b/tests/manual/clip-planes-qml/light.inc.frag
@@ -0,0 +1,222 @@
+const int MAX_LIGHTS = 8;
+const int TYPE_POINT = 0;
+const int TYPE_DIRECTIONAL = 1;
+const int TYPE_SPOT = 2;
+struct Light {
+ int type;
+ vec3 position;
+ vec3 color;
+ float intensity;
+ vec3 direction;
+ float constantAttenuation;
+ float linearAttenuation;
+ float quadraticAttenuation;
+ float cutOffAngle;
+};
+uniform Light lights[MAX_LIGHTS];
+uniform int lightCount;
+
+// Pre-convolved environment maps
+struct EnvironmentLight {
+ samplerCube irradiance; // For diffuse contribution
+ samplerCube specular; // For specular contribution
+};
+uniform EnvironmentLight envLight;
+uniform int envLightCount = 0;
+
+void adsModelNormalMapped(const in vec3 worldPos,
+ const in vec3 tsNormal,
+ const in vec3 worldEye,
+ const in float shininess,
+ const in mat3 tangentMatrix,
+ out vec3 diffuseColor,
+ out vec3 specularColor)
+{
+ diffuseColor = vec3(0.0);
+ specularColor = vec3(0.0);
+
+ // We perform all work in tangent space, so we convert quantities from world space
+ vec3 tsPos = tangentMatrix * worldPos;
+ vec3 n = normalize(tsNormal);
+ vec3 v = normalize(tangentMatrix * (worldEye - worldPos));
+ vec3 s = vec3(0.0);
+
+ for (int i = 0; i < lightCount; ++i) {
+ float att = 1.0;
+ float sDotN = 0.0;
+
+ if (lights[i].type != TYPE_DIRECTIONAL) {
+ // Point and Spot lights
+
+ // Transform the light position from world to tangent space
+ vec3 tsLightPos = tangentMatrix * lights[i].position;
+ vec3 sUnnormalized = tsLightPos - tsPos;
+ s = normalize(sUnnormalized); // Light direction in tangent space
+
+ // Calculate the attenuation factor
+ sDotN = dot(s, n);
+ if (sDotN > 0.0) {
+ if (lights[i].constantAttenuation != 0.0
+ || lights[i].linearAttenuation != 0.0
+ || lights[i].quadraticAttenuation != 0.0) {
+ float dist = length(sUnnormalized);
+ att = 1.0 / (lights[i].constantAttenuation +
+ lights[i].linearAttenuation * dist +
+ lights[i].quadraticAttenuation * dist * dist);
+ }
+
+ // The light direction is in world space, convert to tangent space
+ if (lights[i].type == TYPE_SPOT) {
+ // Check if fragment is inside or outside of the spot light cone
+ vec3 tsLightDirection = tangentMatrix * lights[i].direction;
+ if (degrees(acos(dot(-s, tsLightDirection))) > lights[i].cutOffAngle)
+ sDotN = 0.0;
+ }
+ }
+ } else {
+ // Directional lights
+ // The light direction is in world space, convert to tangent space
+ s = normalize(tangentMatrix * -lights[i].direction);
+ sDotN = dot(s, n);
+ }
+
+ // Calculate the diffuse factor
+ float diffuse = max(sDotN, 0.0);
+
+ // Calculate the specular factor
+ float specular = 0.0;
+ if (diffuse > 0.0 && shininess > 0.0) {
+ float normFactor = (shininess + 2.0) / 2.0;
+ vec3 r = reflect(-s, n); // Reflection direction in tangent space
+ specular = normFactor * pow(max(dot(r, v), 0.0), shininess);
+ }
+
+ // Accumulate the diffuse and specular contributions
+ diffuseColor += att * lights[i].intensity * diffuse * lights[i].color;
+ specularColor += att * lights[i].intensity * specular * lights[i].color;
+ }
+}
+
+void adsModel(const in vec3 worldPos,
+ const in vec3 worldNormal,
+ const in vec3 worldEye,
+ const in float shininess,
+ out vec3 diffuseColor,
+ out vec3 specularColor)
+{
+ diffuseColor = vec3(0.0);
+ specularColor = vec3(0.0);
+
+ // We perform all work in world space
+ vec3 n = normalize(worldNormal);
+ vec3 v = normalize(worldEye - worldPos);
+ vec3 s = vec3(0.0);
+
+ for (int i = 0; i < lightCount; ++i) {
+ float att = 1.0;
+ float sDotN = 0.0;
+
+ if (lights[i].type != TYPE_DIRECTIONAL) {
+ // Point and Spot lights
+
+ // Light position is already in world space
+ vec3 sUnnormalized = lights[i].position - worldPos;
+ s = normalize(sUnnormalized); // Light direction
+
+ // Calculate the attenuation factor
+ sDotN = dot(s, n);
+ if (sDotN > 0.0) {
+ if (lights[i].constantAttenuation != 0.0
+ || lights[i].linearAttenuation != 0.0
+ || lights[i].quadraticAttenuation != 0.0) {
+ float dist = length(sUnnormalized);
+ att = 1.0 / (lights[i].constantAttenuation +
+ lights[i].linearAttenuation * dist +
+ lights[i].quadraticAttenuation * dist * dist);
+ }
+
+ // The light direction is in world space already
+ if (lights[i].type == TYPE_SPOT) {
+ // Check if fragment is inside or outside of the spot light cone
+ if (degrees(acos(dot(-s, lights[i].direction))) > lights[i].cutOffAngle)
+ sDotN = 0.0;
+ }
+ }
+ } else {
+ // Directional lights
+ // The light direction is in world space already
+ s = normalize(-lights[i].direction);
+ sDotN = dot(s, n);
+ }
+
+ // Calculate the diffuse factor
+ float diffuse = max(sDotN, 0.0);
+
+ // Calculate the specular factor
+ float specular = 0.0;
+ if (diffuse > 0.0 && shininess > 0.0) {
+ float normFactor = (shininess + 2.0) / 2.0;
+ vec3 r = reflect(-s, n); // Reflection direction in world space
+ specular = normFactor * pow(max(dot(r, v), 0.0), shininess);
+ }
+
+ // Accumulate the diffuse and specular contributions
+ diffuseColor += att * lights[i].intensity * diffuse * lights[i].color;
+ specularColor += att * lights[i].intensity * specular * lights[i].color;
+ }
+}
+
+void adModel(const in vec3 worldPos,
+ const in vec3 worldNormal,
+ out vec3 diffuseColor)
+{
+ diffuseColor = vec3(0.0);
+
+ // We perform all work in world space
+ vec3 n = normalize(worldNormal);
+ vec3 s = vec3(0.0);
+
+ for (int i = 0; i < lightCount; ++i) {
+ float att = 1.0;
+ float sDotN = 0.0;
+
+ if (lights[i].type != TYPE_DIRECTIONAL) {
+ // Point and Spot lights
+
+ // Light position is already in world space
+ vec3 sUnnormalized = lights[i].position - worldPos;
+ s = normalize(sUnnormalized); // Light direction
+
+ // Calculate the attenuation factor
+ sDotN = dot(s, n);
+ if (sDotN > 0.0) {
+ if (lights[i].constantAttenuation != 0.0
+ || lights[i].linearAttenuation != 0.0
+ || lights[i].quadraticAttenuation != 0.0) {
+ float dist = length(sUnnormalized);
+ att = 1.0 / (lights[i].constantAttenuation +
+ lights[i].linearAttenuation * dist +
+ lights[i].quadraticAttenuation * dist * dist);
+ }
+
+ // The light direction is in world space already
+ if (lights[i].type == TYPE_SPOT) {
+ // Check if fragment is inside or outside of the spot light cone
+ if (degrees(acos(dot(-s, lights[i].direction))) > lights[i].cutOffAngle)
+ sDotN = 0.0;
+ }
+ }
+ } else {
+ // Directional lights
+ // The light direction is in world space already
+ s = normalize(-lights[i].direction);
+ sDotN = dot(s, n);
+ }
+
+ // Calculate the diffuse factor
+ float diffuse = max(sDotN, 0.0);
+
+ // Accumulate the diffuse contributions
+ diffuseColor += att * lights[i].intensity * diffuse * lights[i].color;
+ }
+}
diff --git a/tests/manual/clip-planes-qml/main.qml b/tests/manual/clip-planes-qml/main.qml
index 7f449e291..fd43122dc 100644
--- a/tests/manual/clip-planes-qml/main.qml
+++ b/tests/manual/clip-planes-qml/main.qml
@@ -107,7 +107,7 @@ Entity {
}
property Mesh mesh: Mesh {
- source: "assets/obj/trefoil.obj"
+ source: "qrc:/assets/obj/trefoil.obj"
}
property Transform transform: Transform {
diff --git a/tests/manual/clip-planes-qml/phongalpha.frag b/tests/manual/clip-planes-qml/phongalpha.frag
new file mode 100644
index 000000000..fe2019b5a
--- /dev/null
+++ b/tests/manual/clip-planes-qml/phongalpha.frag
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#version 150 core
+
+// 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
+uniform float alpha;
+
+uniform vec3 eyePosition;
+
+in vec3 worldPosition;
+in vec3 worldNormal;
+
+out vec4 fragColor;
+
+#pragma include light.inc.frag
+
+void main()
+{
+ vec3 diffuseColor, specularColor;
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
+ fragColor = vec4( ka + kd * diffuseColor + ks * specularColor, alpha );
+}