diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2016-06-01 16:53:47 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-06-29 09:25:34 +0000 |
commit | b70cf23d8ccc09419c57d0856f47eb3019c4b22b (patch) | |
tree | b445e585067fb0fb881b44d39d5b7b9583bc1805 /tests/manual/deferred-renderer-qml | |
parent | b0a8cd54e02c698b3dd5a01e5d43702a55d05e66 (diff) |
Fix deferred-renderer-qml
Change-Id: I4da72e96120c3afe1e555a3f89f920cd5e91e088
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/manual/deferred-renderer-qml')
-rw-r--r-- | tests/manual/deferred-renderer-qml/DeferredRenderer.qml | 78 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/FinalEffect.qml | 119 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/GBufferDebugger.qml | 115 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/SceneEntity.qml | 195 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/ScreenQuadEntity.qml | 64 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/deferred-renderer-qml.qrc | 7 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/final_es2.frag | 62 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/final_es2.vert | 9 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/final_gl3.frag | 64 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/final_gl3.vert | 9 | ||||
-rw-r--r-- | tests/manual/deferred-renderer-qml/main.qml | 191 |
11 files changed, 589 insertions, 324 deletions
diff --git a/tests/manual/deferred-renderer-qml/DeferredRenderer.qml b/tests/manual/deferred-renderer-qml/DeferredRenderer.qml index 6f70d2d87..9ee2c2345 100644 --- a/tests/manual/deferred-renderer-qml/DeferredRenderer.qml +++ b/tests/manual/deferred-renderer-qml/DeferredRenderer.qml @@ -55,48 +55,72 @@ Viewport { id: root normalizedRect : Qt.rect(0.0, 0.0, 1.0, 1.0) - property alias gBuffer : gBufferTargetSelector.target + property GBuffer gBuffer property alias camera : sceneCameraSelector.camera - - readonly property Layer sceneLayer: Layer {} - readonly property Layer screenQuadLayer: Layer {} + property alias sceneLayer: sceneLayerFilter.layers + property alias screenQuadLayer: screenQuadLayerFilter.layers + property alias debugLayer: debugLayerFilter.layers RenderSurfaceSelector { - LayerFilter { - layers : root.sceneLayer - - RenderTargetSelector { - id : gBufferTargetSelector + CameraSelector { + id : sceneCameraSelector - ClearBuffers { - buffers: ClearBuffers.ColorDepthBuffer + // Fill G-Buffer + LayerFilter { + id: sceneLayerFilter + RenderTargetSelector { + id : gBufferTargetSelector + target: gBuffer - RenderPassFilter { - id : geometryPass - matchAny : FilterKey { name : "pass"; value : "geometry" } + ClearBuffers { + buffers: ClearBuffers.ColorDepthBuffer - CameraSelector { - id : sceneCameraSelector + RenderPassFilter { + id : geometryPass + matchAny : FilterKey { name : "pass"; value : "geometry" } } } } } - } - LayerFilter { - layers : root.screenQuadLayer + TechniqueFilter { + parameters: [ + Parameter { name: "color"; value : gBuffer.color }, + Parameter { name: "position"; value : gBuffer.position }, + Parameter { name: "normal"; value : gBuffer.normal }, + Parameter { name: "depth"; value : gBuffer.depth }, + Parameter { name: "winSize"; value : Qt.size(1024, 1024) } + ] - ClearBuffers { - buffers: ClearBuffers.ColorDepthBuffer + RenderStateSet { + // Render FullScreen Quad + renderStates: [ + BlendEquation { blendFunction: BlendEquation.Add }, + BlendEquationArguments { sourceRgb: BlendEquationArguments.SourceAlpha; destinationRgb: BlendEquationArguments.DestinationColor } + ] + LayerFilter { + id: screenQuadLayerFilter + ClearBuffers { + buffers: ClearBuffers.ColorDepthBuffer + RenderPassFilter { + matchAny : FilterKey { name : "pass"; value : "final" } + parameters: Parameter { name: "winSize"; value : Qt.size(1024, 768) } - RenderPassFilter { - id : finalPass - matchAny : FilterKey { name : "pass"; value : "final" } - CameraSelector { - camera: sceneCameraSelector.camera + } + } + } + // RenderDebug layer + LayerFilter { + id: debugLayerFilter + Viewport { + normalizedRect : Qt.rect(0.5, 0.5, 0.5, 0.5) + RenderPassFilter { + matchAny : FilterKey { name : "pass"; value : "final" } + parameters: Parameter { name: "winSize"; value : Qt.size(1024 * 0.5, 768 * 0.5) } + } + } } } - } } } diff --git a/tests/manual/deferred-renderer-qml/FinalEffect.qml b/tests/manual/deferred-renderer-qml/FinalEffect.qml index 482ad91cc..27539d9bc 100644 --- a/tests/manual/deferred-renderer-qml/FinalEffect.qml +++ b/tests/manual/deferred-renderer-qml/FinalEffect.qml @@ -56,135 +56,24 @@ Effect { // OpenGL 3.1 Technique { graphicsApiFilter {api : GraphicsApiFilter.OpenGL; profile : GraphicsApiFilter.CoreProfile; minorVersion : 1; majorVersion : 3 } - parameters: Parameter { name: "PointLightBlock"; value: ShaderData { - property ShaderDataArray lights: ShaderDataArray { - // hard coded lights until we have a way to filter - // ShaderData in a scene - values: [sceneEntity.light, sphere1.light, sphere2.light, light3.light, light4.light] - } - } - } renderPasses : RenderPass { filterKeys : FilterKey { name : "pass"; value : "final" } shaderProgram : ShaderProgram { id : finalShaderGL3 - vertexShaderCode: - "#version 140 - - in vec4 vertexPosition; - uniform mat4 modelMatrix; - - void main() - { - gl_Position = modelMatrix * vertexPosition; - } - " - fragmentShaderCode: - "#version 140 - - uniform sampler2D color; - uniform sampler2D position; - uniform sampler2D normal; - uniform vec2 winSize; - - out vec4 fragColor; - - struct PointLight - { - vec3 position; - vec3 direction; - vec4 color; - float intensity; - }; - - const int lightCount = 5; - uniform PointLightBlock { - PointLight lights[lightCount]; - }; - - void main() - { - vec2 texCoord = gl_FragCoord.xy / winSize; - vec4 col = texture(color, texCoord); - vec3 pos = texture(position, texCoord).xyz; - vec3 norm = texture(normal, texCoord).xyz; - - vec4 lightColor; - for (int i = 0; i < lightCount; i++) { - vec3 s = normalize(lights[i].position - pos); - lightColor += lights[i].color * (lights[i].intensity * max(dot(s, norm), 0.0)); - } - lightColor /= float(lightCount); - fragColor = col; - } - " + vertexShaderCode: loadSource("qrc:/final_gl3.vert") + fragmentShaderCode: loadSource("qrc:/final_gl3.frag") } } }, // OpenGL 2.0 with FBO extension Technique { graphicsApiFilter {api : GraphicsApiFilter.OpenGL; profile : GraphicsApiFilter.NoProfile; minorVersion : 0; majorVersion : 2 } - parameters: Parameter { name: "pointLights"; value: ShaderData { - property ShaderDataArray lights: ShaderDataArray { - // hard coded lights until we have a way to filter - // ShaderData in a scene - values: [sceneEntity.light, sphere1.light, sphere2.light, light3.light, light4.light] - } - } - } renderPasses : RenderPass { filterKeys : FilterKey { name : "pass"; value : "final" } shaderProgram : ShaderProgram { id : finalShaderGL2 - vertexShaderCode: - "#version 110 - - attribute vec4 vertexPosition; - uniform mat4 modelMatrix; - - void main() - { - gl_Position = modelMatrix * vertexPosition; - } - " - fragmentShaderCode: - "#version 110 - - uniform sampler2D color; - uniform sampler2D position; - uniform sampler2D normal; - uniform vec2 winSize; - - struct PointLight - { - vec3 position; - vec3 direction; - vec4 color; - float intensity; - }; - - const int lightCount = 5; - uniform struct - { - PointLight lights[lightCount]; - }; - - void main() - { - vec2 texCoord = gl_FragCoord.xy / winSize; - vec4 col = texture2D(color, texCoord); - vec3 pos = texture2D(position, texCoord).xyz; - vec3 norm = texture2D(normal, texCoord).xyz; - - vec4 lightColor; - for (int i = 0; i < lightCount; i++) { - vec3 s = lights[i].position - pos); - lightColor += lights[i].color * (lights[i].intensity * max(dot(s, norm), 0.0)); - } - lightColor /= float(lightCount); - gl_FragColor = col * lightColor; - } - " + vertexShaderCode: loadSource("qrc:/final_es2.vert") + fragmentShaderCode: loadSource("qrc:/final_es2.frag") } } }] diff --git a/tests/manual/deferred-renderer-qml/GBufferDebugger.qml b/tests/manual/deferred-renderer-qml/GBufferDebugger.qml new file mode 100644 index 000000000..f7c730cb1 --- /dev/null +++ b/tests/manual/deferred-renderer-qml/GBufferDebugger.qml @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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: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 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. +** +** 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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Extras 2.0 + +Entity { + readonly property Layer layer: debugLayer + + components : [ + Layer { id: debugLayer }, + + PlaneMesh { + width: 2.0 + height: 2.0 + meshResolution: Qt.size(2, 2) + }, + + Transform { // We rotate the plane so that it faces us + rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 90) + }, + + Material { + effect : Effect { + techniques: [ + Technique { + graphicsApiFilter {api : GraphicsApiFilter.OpenGL; profile : GraphicsApiFilter.NoProfile; minorVersion : 0; majorVersion : 2 } + renderPasses: RenderPass { + filterKeys: FilterKey { name: "pass"; value: "final" } + shaderProgram: ShaderProgram { + vertexShaderCode: + "#version 110 + + attribute vec4 vertexPosition; + uniform mat4 modelMatrix; + + void main() + { + gl_Position = modelMatrix * vertexPosition; + }" + + fragmentShaderCode: + "#version 110 + + uniform sampler2D color; + uniform sampler2D position; + uniform sampler2D normal; + uniform sampler2D depth; + uniform vec2 winSize; + + void main() + { + vec2 texCoord = (gl_FragCoord.xy + vec2(-winSize.x, 0)) / winSize; + + // Draw 4 quadrants + if (texCoord.x > 0.5) { // Right + if (texCoord.y > 0.5) { // Top + gl_FragColor = vec4(texture2D(normal, vec2(texCoord.x - 0.5, texCoord.y - 0.5) * 2.0).xyz, 1.0); + } else { // Bottom + gl_FragColor = vec4(texture2D(color, vec2(texCoord.x - 0.5, texCoord.y) * 2.0).xyz, 1.0); + } + } else { // Left + if (texCoord.y > 0.5) { // Top + gl_FragColor = texture2D(position, vec2(texCoord.x, texCoord.y - 0.5) * 2.0); + } else { // Bottom + gl_FragColor = vec4(texture2D(depth, texCoord * 2.0).rrr, 1.0); + } + } + gl_FragColor.a = 0.5; + }" + } + } + } + ] + } + } + ] +} diff --git a/tests/manual/deferred-renderer-qml/SceneEntity.qml b/tests/manual/deferred-renderer-qml/SceneEntity.qml new file mode 100644 index 000000000..001a24854 --- /dev/null +++ b/tests/manual/deferred-renderer-qml/SceneEntity.qml @@ -0,0 +1,195 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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: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 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. +** +** 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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 as QQ2 +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Input 2.0 +import Qt3D.Extras 2.0 + +Entity { + id : root + readonly property Camera camera: camera + readonly property Layer layer: sceneLayer + + property PointLight light: PointLight { + color : "white" + intensity : 4.0 + QQ2.ColorAnimation on color { from: "white"; to: "blue"; duration: 4000; loops: 2 } + QQ2.NumberAnimation on intensity { from: 0; to: 5.0; duration: 1000; loops: QQ2.Animation.Infinite } + } + + components: [ root.light ] + + // Global elements + Camera { + id: camera + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: 16/9 + nearPlane : 1.0 + farPlane : 1000.0 + position: Qt.vector3d( 0.0, 0.0, -25.0 ) + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 10.0 ) + } + + SphereMesh { + id : sphereMesh + rings: 50 + slices: 100 + } + + SceneEffect { id : sceneMaterialEffect } + + Layer { id: sceneLayer } + + // Scene + Entity { + id : sphere1 + + property Material material : Material { + effect : sceneMaterialEffect + parameters : Parameter { name : "meshColor"; value : "dodgerblue" } + } + + property Transform transform: Transform { + id: sphere1Transform + property real x: -10.0 + translation: Qt.vector3d(x, 0, 5) + } + + QQ2.SequentialAnimation { + loops: QQ2.Animation.Infinite + running: false + QQ2.NumberAnimation { target: sphere1Transform; property: "x"; to: 6; duration: 2000 } + QQ2.NumberAnimation { target: sphere1Transform; property: "x"; to: -10; duration: 2000 } + } + + property PointLight light : PointLight { + color : "green" + intensity : 0.3 + } + + components : [ + sphereMesh, + sphere1.material, + sphere1.transform, + sphere1.light, + sceneLayer + ] + } + + Entity { + id : sphere2 + + property Material material : Material { + effect : sceneMaterialEffect + parameters : Parameter { name : "meshColor"; value : "green" } + } + + property PointLight light : PointLight { + color : "orange" + intensity : 0.7 + } + + property Transform transform: Transform { + translation: Qt.vector3d(5, 0, 5) + } + + components : [ + sphereMesh, + sphere2.transform, + sphere2.material, + sphere2.light, + sceneLayer + ] + } + + Entity { + id: light3 + property PointLight light : PointLight { + color : "white" + intensity : 0.5 + } + + property Material material : Material { + effect : sceneMaterialEffect + parameters : Parameter { name : "meshColor"; value : "red" } + } + + property Transform transform: Transform { + id: light3Transform + property real y: 2.0 + translation: Qt.vector3d(2, y, 7) + } + + QQ2.SequentialAnimation { + loops: QQ2.Animation.Infinite + running: true + QQ2.NumberAnimation { target: light3Transform; property: "y"; to: 6; duration: 1000; easing.type: QQ2.Easing.InOutQuad } + QQ2.NumberAnimation { target: light3Transform; property: "y"; to: -6; duration: 1000; easing.type: QQ2.Easing.InOutQuint } + } + + components: [ + sphereMesh, + light3.material, + light3.light, + light3.transform, + sceneLayer + ] + } + + Entity { + id: light4 + property PointLight light : PointLight { + color : "white" + intensity : 0.2 + } + property Transform transform: Transform { + translation: Qt.vector3d(5, 2, 7) + } + + components: [ + light4.light, + light4.transform, + sceneLayer + ] + } +} diff --git a/tests/manual/deferred-renderer-qml/ScreenQuadEntity.qml b/tests/manual/deferred-renderer-qml/ScreenQuadEntity.qml new file mode 100644 index 000000000..6c5284d5e --- /dev/null +++ b/tests/manual/deferred-renderer-qml/ScreenQuadEntity.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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: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 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. +** +** 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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Extras 2.0 + +Entity { + readonly property Layer layer: screenQuadLayer + + components : [ + Layer { id: screenQuadLayer }, + + PlaneMesh { + width: 2.0 + height: 2.0 + meshResolution: Qt.size(2, 2) + }, + + Transform { // We rotate the plane so that it faces us + rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 90) + }, + + Material { + effect : FinalEffect {} + } + ] +} diff --git a/tests/manual/deferred-renderer-qml/deferred-renderer-qml.qrc b/tests/manual/deferred-renderer-qml/deferred-renderer-qml.qrc index 573b2337e..6ee17f42d 100644 --- a/tests/manual/deferred-renderer-qml/deferred-renderer-qml.qrc +++ b/tests/manual/deferred-renderer-qml/deferred-renderer-qml.qrc @@ -5,5 +5,12 @@ <file>FinalEffect.qml</file> <file>SceneEffect.qml</file> <file>GBuffer.qml</file> + <file>ScreenQuadEntity.qml</file> + <file>SceneEntity.qml</file> + <file>final_es2.vert</file> + <file>final_gl3.frag</file> + <file>final_gl3.vert</file> + <file>final_es2.frag</file> + <file>GBufferDebugger.qml</file> </qresource> </RCC> diff --git a/tests/manual/deferred-renderer-qml/final_es2.frag b/tests/manual/deferred-renderer-qml/final_es2.frag new file mode 100644 index 000000000..a1309112a --- /dev/null +++ b/tests/manual/deferred-renderer-qml/final_es2.frag @@ -0,0 +1,62 @@ +#version 110 + +uniform sampler2D color; +uniform sampler2D position; +uniform sampler2D normal; +uniform vec2 winSize; + +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; + +void main() +{ + vec2 texCoord = gl_FragCoord.xy / winSize; + vec4 col = texture2D(color, texCoord); + vec3 pos = texture2D(position, texCoord).xyz; + vec3 norm = texture2D(normal, texCoord).xyz; + + vec3 lightColor; + vec3 s; + + for (int i = 0; i < lightCount; ++i) { + float att = 1.0; + if ( lights[i].type != TYPE_DIRECTIONAL ) { + s = lights[i].position - pos; + if (lights[i].constantAttenuation != 0.0 + || lights[i].linearAttenuation != 0.0 + || lights[i].quadraticAttenuation != 0.0) { + float dist = length(s); + att = 1.0 / (lights[i].constantAttenuation + lights[i].linearAttenuation * dist + lights[i].quadraticAttenuation * dist * dist); + } + s = normalize( s ); + if ( lights[i].type == TYPE_SPOT ) { + if ( degrees(acos(dot(-s, normalize(lights[i].direction))) ) > lights[i].cutOffAngle) + att = 0.0; + } + } else { + s = normalize( -lights[i].direction ); + } + + float diffuse = max( dot( s, norm ), 0.0 ); + + lightColor += att * lights[i].intensity * diffuse * lights[i].color; + } + gl_FragColor = vec4(col.rgb * lightColor, col.a); +} diff --git a/tests/manual/deferred-renderer-qml/final_es2.vert b/tests/manual/deferred-renderer-qml/final_es2.vert new file mode 100644 index 000000000..a907e10ca --- /dev/null +++ b/tests/manual/deferred-renderer-qml/final_es2.vert @@ -0,0 +1,9 @@ +#version 110 + +attribute vec4 vertexPosition; +uniform mat4 modelMatrix; + +void main() +{ + gl_Position = modelMatrix * vertexPosition; +} diff --git a/tests/manual/deferred-renderer-qml/final_gl3.frag b/tests/manual/deferred-renderer-qml/final_gl3.frag new file mode 100644 index 000000000..d760e9844 --- /dev/null +++ b/tests/manual/deferred-renderer-qml/final_gl3.frag @@ -0,0 +1,64 @@ +#version 140 + +uniform sampler2D color; +uniform sampler2D position; +uniform sampler2D normal; +uniform vec2 winSize; + +out vec4 fragColor; + +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; + +void main() +{ + vec2 texCoord = gl_FragCoord.xy / winSize; + vec4 col = texture(color, texCoord); + vec3 pos = texture(position, texCoord).xyz; + vec3 norm = texture(normal, texCoord).xyz; + + vec3 lightColor; + vec3 s; + + for (int i = 0; i < lightCount; ++i) { + float att = 1.0; + if ( lights[i].type != TYPE_DIRECTIONAL ) { + s = lights[i].position - pos; + if (lights[i].constantAttenuation != 0.0 + || lights[i].linearAttenuation != 0.0 + || lights[i].quadraticAttenuation != 0.0) { + float dist = length(s); + att = 1.0 / (lights[i].constantAttenuation + lights[i].linearAttenuation * dist + lights[i].quadraticAttenuation * dist * dist); + } + s = normalize( s ); + if ( lights[i].type == TYPE_SPOT ) { + if ( degrees(acos(dot(-s, normalize(lights[i].direction))) ) > lights[i].cutOffAngle) + att = 0.0; + } + } else { + s = normalize( -lights[i].direction ); + } + + float diffuse = max( dot( s, norm ), 0.0 ); + + lightColor += att * lights[i].intensity * diffuse * lights[i].color; + } + fragColor = vec4(col.rgb * lightColor, col.a); +} diff --git a/tests/manual/deferred-renderer-qml/final_gl3.vert b/tests/manual/deferred-renderer-qml/final_gl3.vert new file mode 100644 index 000000000..60410d34d --- /dev/null +++ b/tests/manual/deferred-renderer-qml/final_gl3.vert @@ -0,0 +1,9 @@ +#version 140 + +in vec4 vertexPosition; +uniform mat4 modelMatrix; + +void main() +{ + gl_Position = modelMatrix * vertexPosition; +} diff --git a/tests/manual/deferred-renderer-qml/main.qml b/tests/manual/deferred-renderer-qml/main.qml index b56e0bd5d..790911723 100644 --- a/tests/manual/deferred-renderer-qml/main.qml +++ b/tests/manual/deferred-renderer-qml/main.qml @@ -57,197 +57,24 @@ import Qt3D.Extras 2.0 Entity { id : root - GBuffer { - id : gBuffer - } - components : [ RenderSettings { activeFrameGraph: DeferredRenderer { id: frameGraph - camera : camera - gBuffer: gBuffer + camera : sceneEntity.camera + gBuffer: GBuffer {} + sceneLayer: sceneEntity.layer + screenQuadLayer: screenQuadEntity.layer + debugLayer: debugEntity.layer } - renderPolicy: RenderSettings.Always }, InputSettings {} ] - FirstPersonCameraController { camera: camera } - - Entity { - id : screenQuadEntity - PlaneMesh { - id: mesh - width: 2.0 - height: 2.0 - meshResolution: Qt.size(2, 2) - } - - Transform { // We rotate the plane so that it faces us - id: transform - rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 90) - } - - Material { - id: material - parameters : [ - Parameter { name: "color"; value : gBuffer.color }, - Parameter { name: "position"; value : gBuffer.position }, - Parameter { name: "normal"; value : gBuffer.normal }, - Parameter { name: "winSize"; value : Qt.size(1024, 1024) } - ] - effect : FinalEffect {} - } - - components : [ frameGraph.screenQuadLayer, mesh, transform, material ] - } - - Entity { - id : sceneEntity - - property PointLight light: PointLight { - color : "white" - intensity : 4.0 - QQ2.ColorAnimation on color { from: "white"; to: "blue"; duration: 4000; loops: 2 } - QQ2.NumberAnimation on intensity { from: 0; to: 5.0; duration: 1000; loops: QQ2.Animation.Infinite } - } - - components: [ sceneEntity.light ] - - Camera { - id: camera - projectionType: CameraLens.PerspectiveProjection - fieldOfView: 45 - aspectRatio: 16/9 - nearPlane : 0.01 - farPlane : 1000.0 - position: Qt.vector3d( 0.0, 0.0, -25.0 ) - upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) - viewCenter: Qt.vector3d( 0.0, 0.0, 10.0 ) - } - - SphereMesh { - id : sphereMesh - rings: 50 - slices: 100 - } - - SceneEffect { - id : sceneMaterialEffect - } - - Entity { - id : sphere1 - - property Material material : Material { - effect : sceneMaterialEffect - parameters : Parameter { name : "meshColor"; value : "dodgerblue" } - } - - property Transform transform: Transform { - id: sphere1Transform - property real x: -10.0 - translation: Qt.vector3d(x, 0, 5) - } - - QQ2.SequentialAnimation { - loops: QQ2.Animation.Infinite - running: false - QQ2.NumberAnimation { target: sphere1Transform; property: "x"; to: 6; duration: 2000 } - QQ2.NumberAnimation { target: sphere1Transform; property: "x"; to: -10; duration: 2000 } - } - - property PointLight light : PointLight { - color : "green" - intensity : 5.0 - } - - components : [ - sphereMesh, - material, - sphere1.transform, - sphere1.light, - frameGraph.sceneLayer - ] - } - - Entity { - id : sphere2 - - property Material material : Material { - effect : sceneMaterialEffect - parameters : Parameter { name : "meshColor"; value : "green" } - } - - property PointLight light : PointLight { - color : "orange" - intensity : 2.0 - } - - property Transform transform: Transform { - translation: Qt.vector3d(5, 0, 5) - } - - components : [ - sphereMesh, - sphere2.transform, - material, - sphere2.light, - frameGraph.sceneLayer - ] - } - - Entity { - id: light3 - property PointLight light : PointLight { - color : "white" - intensity : 2.0 - } - - property Material material : Material { - effect : sceneMaterialEffect - parameters : Parameter { name : "meshColor"; value : "red" } - } - - property Transform transform: Transform { - id: light3Transform - property real y: 2.0 - translation: Qt.vector3d(2, y, 7) - } - - QQ2.SequentialAnimation { - loops: QQ2.Animation.Infinite - running: true - QQ2.NumberAnimation { target: light3Transform; property: "y"; to: 6; duration: 1000; easing.type: QQ2.Easing.InOutQuad } - QQ2.NumberAnimation { target: light3Transform; property: "y"; to: -6; duration: 1000; easing.type: QQ2.Easing.InOutQuint } - } - - components: [ - sphereMesh, - material, - light, - transform, - frameGraph.sceneLayer - ] - } - - Entity { - id: light4 - property PointLight light : PointLight { - color : "white" - intensity : 3.0 - } - property Transform transform: Transform { - translation: Qt.vector3d(5, 2, 7) - } + FirstPersonCameraController { camera: sceneEntity.camera } - components: [ - light4.light, - light4.transform, - frameGraph.sceneLayer - ] - } - } + ScreenQuadEntity { id: screenQuadEntity } + SceneEntity { id: sceneEntity } + GBufferDebugger { id: debugEntity } } |