diff options
author | Robert Brock <robert.brock@kdab.com> | 2016-05-07 15:33:52 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-05-15 13:44:29 +0000 |
commit | c5cb6a4783818386bd205a380d17987c45b6d742 (patch) | |
tree | 8013d6362c0e9b73b50bb652c05060be70d2f86e | |
parent | 1ad96b73c227ddf8974a7353bdc602230d865359 (diff) |
Moved deferred-renderer-cpp example to manual test
Part of an examples cleanup
Change-Id: I3b95590bef2261b1a4701b9b3fc35e9e909a0283
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
24 files changed, 925 insertions, 2 deletions
diff --git a/examples/qt3d/qt3d.pro b/examples/qt3d/qt3d.pro index 6ecf5f715..7621d54f6 100644 --- a/examples/qt3d/qt3d.pro +++ b/examples/qt3d/qt3d.pro @@ -10,7 +10,6 @@ SUBDIRS += \ wireframe \ tessellation-modes \ deferred-renderer-qml \ - deferred-renderer-cpp \ shadow-map-qml \ materials \ keyboardinput-qml \ diff --git a/tests/manual/deferred-renderer-cpp/deferred-renderer-cpp.pro b/tests/manual/deferred-renderer-cpp/deferred-renderer-cpp.pro new file mode 100644 index 000000000..579e61b68 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/deferred-renderer-cpp.pro @@ -0,0 +1,33 @@ +!include( ../manual.pri ) { + error( "Couldn't find the manual.pri file!" ) +} + +QT += 3dcore 3drender 3dinput 3dextras + +HEADERS += \ + gbuffer.h \ + deferredrenderer.h \ + finaleffect.h \ + sceneeffect.h \ + pointlightblock.h + +SOURCES += \ + main.cpp \ + gbuffer.cpp \ + deferredrenderer.cpp \ + finaleffect.cpp \ + sceneeffect.cpp \ + pointlightblock.cpp + +RESOURCES += \ + deferred-renderer-cpp.qrc + +OTHER_FILES += \ + geometry_gl2.vert \ + geometry_gl2.frag \ + geometry_gl3.frag \ + geometry_gl3.vert \ + final_gl2.vert \ + final_gl2.frag \ + final_gl3.frag \ + final_gl3.vert diff --git a/tests/manual/deferred-renderer-cpp/deferred-renderer-cpp.qrc b/tests/manual/deferred-renderer-cpp/deferred-renderer-cpp.qrc new file mode 100644 index 000000000..0e38e39ca --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/deferred-renderer-cpp.qrc @@ -0,0 +1,12 @@ +<RCC> + <qresource prefix="/"> + <file>geometry_gl2.frag</file> + <file>geometry_gl2.vert</file> + <file>geometry_gl3.frag</file> + <file>geometry_gl3.vert</file> + <file>final_gl2.frag</file> + <file>final_gl2.vert</file> + <file>final_gl3.frag</file> + <file>final_gl3.vert</file> + </qresource> +</RCC> diff --git a/examples/qt3d/deferred-renderer-cpp/deferredrenderer.cpp b/tests/manual/deferred-renderer-cpp/deferredrenderer.cpp index 391240108..391240108 100644 --- a/examples/qt3d/deferred-renderer-cpp/deferredrenderer.cpp +++ b/tests/manual/deferred-renderer-cpp/deferredrenderer.cpp diff --git a/examples/qt3d/deferred-renderer-cpp/deferredrenderer.h b/tests/manual/deferred-renderer-cpp/deferredrenderer.h index 85044838a..85044838a 100644 --- a/examples/qt3d/deferred-renderer-cpp/deferredrenderer.h +++ b/tests/manual/deferred-renderer-cpp/deferredrenderer.h diff --git a/tests/manual/deferred-renderer-cpp/doc/src/deferred-renderer-cpp.qdoc b/tests/manual/deferred-renderer-cpp/doc/src/deferred-renderer-cpp.qdoc new file mode 100644 index 000000000..65311e77f --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/doc/src/deferred-renderer-cpp.qdoc @@ -0,0 +1,32 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example deferred-renderer-cpp + \title Qt 3D: Deferred Renderer C++ Example + \ingroup qt3d-examples-cpp +*/ diff --git a/tests/manual/deferred-renderer-cpp/final_gl2.frag b/tests/manual/deferred-renderer-cpp/final_gl2.frag new file mode 100644 index 000000000..f384a2df4 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/final_gl2.frag @@ -0,0 +1,36 @@ +#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 = 3; +uniform struct +{ + PointLight lights[lightCount]; +} pointLights; + +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 < 3; i++) { + vec3 s = normalize(pointLights.lights[i].position - pos); + lightColor += pointLights.lights[i].color * (pointLights.lights[i].intensity * max(dot(s, norm), 0.0)); + } + lightColor /= float(lightCount); + gl_FragColor = col * lightColor; +} diff --git a/tests/manual/deferred-renderer-cpp/final_gl2.vert b/tests/manual/deferred-renderer-cpp/final_gl2.vert new file mode 100644 index 000000000..a907e10ca --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/final_gl2.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-cpp/final_gl3.frag b/tests/manual/deferred-renderer-cpp/final_gl3.frag new file mode 100644 index 000000000..88abd5cb1 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/final_gl3.frag @@ -0,0 +1,37 @@ +#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 = 3; +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 < 3; 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 * lightColor; +} diff --git a/tests/manual/deferred-renderer-cpp/final_gl3.vert b/tests/manual/deferred-renderer-cpp/final_gl3.vert new file mode 100644 index 000000000..60410d34d --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/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-cpp/finaleffect.cpp b/tests/manual/deferred-renderer-cpp/finaleffect.cpp new file mode 100644 index 000000000..63c821caa --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/finaleffect.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#include "finaleffect.h" + +#include <Qt3DRender/QGraphicsApiFilter> +#include <Qt3DRender/QShaderProgram> +#include <QUrl> + +FinalEffect::FinalEffect(Qt3DCore::QNode *parent) + : Qt3DRender::QEffect(parent) + , m_gl3Technique(new Qt3DRender::QTechnique()) + , m_gl2Technique(new Qt3DRender::QTechnique()) + , m_gl2Pass(new Qt3DRender::QRenderPass()) + , m_gl3Pass(new Qt3DRender::QRenderPass()) + , m_passCriterion(new Qt3DRender::QFilterKey(this)) +{ + m_gl3Technique->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); + m_gl3Technique->graphicsApiFilter()->setMajorVersion(3); + m_gl3Technique->graphicsApiFilter()->setMinorVersion(1); + m_gl3Technique->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile); + + m_gl2Technique->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); + m_gl2Technique->graphicsApiFilter()->setMajorVersion(2); + m_gl2Technique->graphicsApiFilter()->setMinorVersion(0); + m_gl2Technique->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile); + + m_passCriterion->setName(QStringLiteral("pass")); + m_passCriterion->setValue(QStringLiteral("final")); + + Qt3DRender::QShaderProgram *gl3Shader = new Qt3DRender::QShaderProgram(); + gl3Shader->setVertexShaderCode(gl3Shader->loadSource(QUrl(QStringLiteral("qrc:/final_gl3.vert")))); + gl3Shader->setFragmentShaderCode(gl3Shader->loadSource(QUrl(QStringLiteral("qrc:/final_gl3.frag")))); + + m_gl3Pass->addFilterKey(m_passCriterion); + m_gl3Pass->setShaderProgram(gl3Shader); + m_gl3Technique->addRenderPass(m_gl3Pass); + + Qt3DRender::QShaderProgram *gl2Shader = new Qt3DRender::QShaderProgram(); + gl2Shader->setVertexShaderCode(gl2Shader->loadSource(QUrl(QStringLiteral("qrc:/final_gl2.vert")))); + gl2Shader->setFragmentShaderCode(gl2Shader->loadSource(QUrl(QStringLiteral("qrc:/final_gl2.frag")))); + + m_gl2Pass->addFilterKey(m_passCriterion); + m_gl2Pass->setShaderProgram(gl2Shader); + m_gl2Technique->addRenderPass(m_gl2Pass); + + addTechnique(m_gl3Technique); + addTechnique(m_gl2Technique); +} + +QList<Qt3DRender::QFilterKey *> FinalEffect::passCriteria() const +{ + return QList<Qt3DRender::QFilterKey *>() << m_passCriterion; +} diff --git a/tests/manual/deferred-renderer-cpp/finaleffect.h b/tests/manual/deferred-renderer-cpp/finaleffect.h new file mode 100644 index 000000000..69a1b126c --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/finaleffect.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#ifndef FINALEFFECT_H +#define FINALEFFECT_H + +#include <Qt3DRender/QEffect> +#include <Qt3DRender/QTechnique> + +class FinalEffect : public Qt3DRender::QEffect +{ +public: + explicit FinalEffect(Qt3DCore::QNode *parent = 0); + + QList<Qt3DRender::QFilterKey *> passCriteria() const; + inline Qt3DRender::QTechnique *gl3Technique() const { return m_gl3Technique; } + inline Qt3DRender::QTechnique *gl2Technique() const { return m_gl2Technique; } + +private : + Qt3DRender::QTechnique *m_gl3Technique; + Qt3DRender::QTechnique *m_gl2Technique; + Qt3DRender::QRenderPass *m_gl2Pass; + Qt3DRender::QRenderPass *m_gl3Pass; + Qt3DRender::QFilterKey *m_passCriterion; +}; + +#endif // FINALEFFECT_H diff --git a/tests/manual/deferred-renderer-cpp/gbuffer.cpp b/tests/manual/deferred-renderer-cpp/gbuffer.cpp new file mode 100644 index 000000000..984dbb1f2 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/gbuffer.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#include "gbuffer.h" + +GBuffer::GBuffer(Qt3DCore::QNode *parent) + : Qt3DRender::QRenderTarget(parent) +{ + const Qt3DRender::QAbstractTexture::TextureFormat formats[AttachmentsCount] = { + Qt3DRender::QAbstractTexture::RGBA32F, + Qt3DRender::QAbstractTexture::RGB32F, + Qt3DRender::QAbstractTexture::RGB16F, + Qt3DRender::QAbstractTexture::D32F + }; + + const Qt3DRender::QRenderTargetOutput::AttachmentPoint attachmentPoints[AttachmentsCount] = { + Qt3DRender::QRenderTargetOutput::Color0, + Qt3DRender::QRenderTargetOutput::Color1, + Qt3DRender::QRenderTargetOutput::Color2, + Qt3DRender::QRenderTargetOutput::Depth + }; + + for (int i = 0; i < AttachmentsCount; i++) { + Qt3DRender::QRenderTargetOutput *output = new Qt3DRender::QRenderTargetOutput(this); + + m_textures[i] = new Qt3DRender::QTexture2D(); + m_textures[i]->setFormat(formats[i]); + m_textures[i]->setWidth(1024); + m_textures[i]->setHeight(1024); + m_textures[i]->setGenerateMipMaps(false); + m_textures[i]->setWrapMode(Qt3DRender::QTextureWrapMode(Qt3DRender::QTextureWrapMode::ClampToEdge)); + m_textures[i]->setMinificationFilter(Qt3DRender::QAbstractTexture::Linear); + m_textures[i]->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); + + output->setTexture(m_textures[i]); + output->setAttachmentPoint(attachmentPoints[i]); + addOutput(output); + } +} + +Qt3DRender::QAbstractTexture *GBuffer::colorTexture() const +{ + return m_textures[Color]; +} + +Qt3DRender::QAbstractTexture *GBuffer::positionTexture() const +{ + return m_textures[Position]; +} + +Qt3DRender::QAbstractTexture *GBuffer::normalTexture() const +{ + return m_textures[Normal]; +} + +Qt3DRender::QAbstractTexture *GBuffer::depthTexture() const +{ + return m_textures[Depth]; +} diff --git a/tests/manual/deferred-renderer-cpp/gbuffer.h b/tests/manual/deferred-renderer-cpp/gbuffer.h new file mode 100644 index 000000000..dab8b6752 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/gbuffer.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#ifndef GBUFFER_H +#define GBUFFER_H + +#include <Qt3DRender/QRenderTarget> +#include <Qt3DRender/qtexture.h> +#include <Qt3DRender/QRenderTargetOutput> + +class GBuffer : public Qt3DRender::QRenderTarget +{ +public: + explicit GBuffer(Qt3DCore::QNode *parent = 0); + + enum Attachments { + Color = 0, + Position, + Normal, + Depth, + AttachmentsCount + }; + + Qt3DRender::QAbstractTexture *colorTexture() const; + Qt3DRender::QAbstractTexture *positionTexture() const; + Qt3DRender::QAbstractTexture *normalTexture() const; + Qt3DRender::QAbstractTexture *depthTexture() const; + +private: + Qt3DRender::QAbstractTexture *m_textures[AttachmentsCount]; + Qt3DRender::QRenderTargetOutput *m_attachments[AttachmentsCount]; +}; + +#endif // GBUFFER_H diff --git a/tests/manual/deferred-renderer-cpp/geometry_gl2.frag b/tests/manual/deferred-renderer-cpp/geometry_gl2.frag new file mode 100644 index 000000000..0e7776f15 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/geometry_gl2.frag @@ -0,0 +1,12 @@ +#version 110 + +varying vec4 color0; +varying vec3 position0; +varying vec3 normal0; + +void main() +{ + gl_FragData[0] = color0; + gl_FragData[1] = vec4(position0, 0); + gl_FragData[2] = vec4(normal0, 0); +} diff --git a/tests/manual/deferred-renderer-cpp/geometry_gl2.vert b/tests/manual/deferred-renderer-cpp/geometry_gl2.vert new file mode 100644 index 000000000..72d5345f1 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/geometry_gl2.vert @@ -0,0 +1,21 @@ +#version 110 + +attribute vec4 vertexPosition; +attribute vec3 vertexNormal; + +varying vec4 color0; +varying vec3 position0; +varying vec3 normal0; + +uniform mat4 mvp; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform vec4 meshColor; + +void main() +{ + color0 = meshColor; + position0 = vec3(modelView * vertexPosition); + normal0 = normalize(modelViewNormal * vertexNormal); + gl_Position = mvp * vertexPosition; +} diff --git a/tests/manual/deferred-renderer-cpp/geometry_gl3.frag b/tests/manual/deferred-renderer-cpp/geometry_gl3.frag new file mode 100644 index 000000000..7d9c7d64e --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/geometry_gl3.frag @@ -0,0 +1,16 @@ +#version 140 + +in vec4 color0; +in vec3 position0; +in vec3 normal0; + +out vec4 color; +out vec3 position; +out vec3 normal; + +void main() +{ + color = color0; + position = position0; + normal = normal0; +} diff --git a/tests/manual/deferred-renderer-cpp/geometry_gl3.vert b/tests/manual/deferred-renderer-cpp/geometry_gl3.vert new file mode 100644 index 000000000..d3e302d16 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/geometry_gl3.vert @@ -0,0 +1,21 @@ +#version 140 + +in vec4 vertexPosition; +in vec3 vertexNormal; + +out vec4 color0; +out vec3 position0; +out vec3 normal0; + +uniform mat4 mvp; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform vec4 meshColor; + +void main() +{ + color0 = meshColor; + position0 = vec3(modelView * vertexPosition); + normal0 = normalize(modelViewNormal * vertexNormal); + gl_Position = mvp * vertexPosition; +} diff --git a/examples/qt3d/deferred-renderer-cpp/main.cpp b/tests/manual/deferred-renderer-cpp/main.cpp index 53caaaae5..53caaaae5 100644 --- a/examples/qt3d/deferred-renderer-cpp/main.cpp +++ b/tests/manual/deferred-renderer-cpp/main.cpp diff --git a/tests/manual/deferred-renderer-cpp/pointlightblock.cpp b/tests/manual/deferred-renderer-cpp/pointlightblock.cpp new file mode 100644 index 000000000..36bab9966 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/pointlightblock.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#include "pointlightblock.h" + +PointLightBlock::PointLightBlock(Qt3DCore::QNode *parent) + : Qt3DRender::QShaderData(parent) +{ + +} + +PointLightBlock::~PointLightBlock() +{ +} + +QVector<Qt3DRender::QAbstractLight *> PointLightBlock::lights() const +{ + return m_lights; +} + +void PointLightBlock::addLight(Qt3DRender::QAbstractLight *light) +{ + m_lights.append(light); + emit lightsChanged(); +} + diff --git a/tests/manual/deferred-renderer-cpp/pointlightblock.h b/tests/manual/deferred-renderer-cpp/pointlightblock.h new file mode 100644 index 000000000..9c93528c8 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/pointlightblock.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#ifndef POINTLIGHTBLOCK_H +#define POINTLIGHTBLOCK_H + +#include <Qt3DRender/QAbstractLight> +#include <Qt3DRender/QShaderData> + +class PointLightBlock : public Qt3DRender::QShaderData +{ + Q_OBJECT + Q_PROPERTY(QVector<Qt3DRender::QAbstractLight *> lights READ lights NOTIFY lightsChanged) +public: + explicit PointLightBlock(Qt3DCore::QNode *parent = 0); + ~PointLightBlock(); + + QVector<Qt3DRender::QAbstractLight *> lights() const; + void addLight(Qt3DRender::QAbstractLight *light); + +Q_SIGNALS: + void lightsChanged(); + +private: + QVector<Qt3DRender::QAbstractLight *> m_lights; +}; + +#endif // POINTLIGHTBLOCK_H diff --git a/tests/manual/deferred-renderer-cpp/sceneeffect.cpp b/tests/manual/deferred-renderer-cpp/sceneeffect.cpp new file mode 100644 index 000000000..bdb6ea76e --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/sceneeffect.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#include "sceneeffect.h" + +#include <Qt3DRender/QGraphicsApiFilter> +#include <Qt3DRender/QShaderProgram> +#include <QUrl> + +SceneEffect::SceneEffect(Qt3DCore::QNode *parent) + : Qt3DRender::QEffect(parent) + , m_gl3Technique(new Qt3DRender::QTechnique()) + , m_gl2Technique(new Qt3DRender::QTechnique()) + , m_gl2Pass(new Qt3DRender::QRenderPass()) + , m_gl3Pass(new Qt3DRender::QRenderPass()) + , m_passCriterion(new Qt3DRender::QFilterKey(this)) +{ + + m_gl3Technique->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile); + m_gl3Technique->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); + m_gl3Technique->graphicsApiFilter()->setMajorVersion(3); + m_gl3Technique->graphicsApiFilter()->setMinorVersion(3); + + m_gl2Technique->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); + m_gl2Technique->graphicsApiFilter()->setMajorVersion(2); + m_gl2Technique->graphicsApiFilter()->setMinorVersion(0); + m_gl2Technique->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile); + + + m_passCriterion->setName(QStringLiteral("pass")); + m_passCriterion->setValue(QStringLiteral("geometry")); + + Qt3DRender::QShaderProgram *gl3Shader = new Qt3DRender::QShaderProgram(); + gl3Shader->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/geometry_gl3.vert")))); + gl3Shader->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/geometry_gl3.frag")))); + + m_gl3Pass->addFilterKey(m_passCriterion); + m_gl3Pass->setShaderProgram(gl3Shader); + m_gl3Technique->addRenderPass(m_gl3Pass); + + Qt3DRender::QShaderProgram *gl2Shader = new Qt3DRender::QShaderProgram(); + gl2Shader->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/geometry_gl2.vert")))); + gl2Shader->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/geometry_gl2.frag")))); + + m_gl2Pass->addFilterKey(m_passCriterion); + m_gl2Pass->setShaderProgram(gl2Shader); + m_gl2Technique->addRenderPass(m_gl2Pass); + + addTechnique(m_gl3Technique); + addTechnique(m_gl2Technique); +} + +QList<Qt3DRender::QFilterKey *> SceneEffect::passCriteria() const +{ + return QList<Qt3DRender::QFilterKey *>() << m_passCriterion; +} diff --git a/tests/manual/deferred-renderer-cpp/sceneeffect.h b/tests/manual/deferred-renderer-cpp/sceneeffect.h new file mode 100644 index 000000000..eb361c273 --- /dev/null +++ b/tests/manual/deferred-renderer-cpp/sceneeffect.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#ifndef SCENEEFFECT_H +#define SCENEEFFECT_H + +#include <Qt3DRender/QEffect> +#include <Qt3DRender/QTechnique> + +class SceneEffect : public Qt3DRender::QEffect +{ +public: + explicit SceneEffect(Qt3DCore::QNode *parent = 0); + + QList<Qt3DRender::QFilterKey *> passCriteria() const; + +private: + Qt3DRender::QTechnique *m_gl3Technique; + Qt3DRender::QTechnique *m_gl2Technique; + Qt3DRender::QRenderPass *m_gl2Pass; + Qt3DRender::QRenderPass *m_gl3Pass; + Qt3DRender::QFilterKey *m_passCriterion; +}; + +#endif // SCENEEFFECT_H diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index 1a6ed6c42..f4c9b48ea 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -5,4 +5,5 @@ SUBDIRS += \ bigscene-cpp \ bigmodel-qml \ bigscene-instanced-qml \ - clip-planes-qml + clip-planes-qml \ + deferred-renderer-cpp |