diff options
author | Kevin Ottens <kevin.ottens@kdab.com> | 2017-02-23 15:13:28 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-02-24 16:58:54 +0000 |
commit | 67eec4f57a47271685e805c1ff74c80b2570c6ab (patch) | |
tree | 79388fc28deafb0642328a8c6fa1f6eeae9a597b /src/render/lights | |
parent | 12111fd494d927bb75a8a41e3771ff6983119274 (diff) |
Add QEnvironmentLight into Qt3DRender
This is a better API to set the environment lighting than what we
currently have on the metal/rough materials. Still needs to be
integrated in the renderer and to adjust the materials to make use of
it.
Change-Id: Ie1e46a0fa67916460147200c9cbbfbab8b037cee
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/lights')
-rw-r--r-- | src/render/lights/environmentlight.cpp | 66 | ||||
-rw-r--r-- | src/render/lights/environmentlight_p.h | 81 | ||||
-rw-r--r-- | src/render/lights/lights.pri | 5 | ||||
-rw-r--r-- | src/render/lights/qenvironmentlight.cpp | 189 | ||||
-rw-r--r-- | src/render/lights/qenvironmentlight.h | 86 | ||||
-rw-r--r-- | src/render/lights/qenvironmentlight_p.h | 85 |
6 files changed, 512 insertions, 0 deletions
diff --git a/src/render/lights/environmentlight.cpp b/src/render/lights/environmentlight.cpp new file mode 100644 index 000000000..d4245fb6e --- /dev/null +++ b/src/render/lights/environmentlight.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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: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$ +** +****************************************************************************/ + +#include "environmentlight_p.h" +#include "qenvironmentlight.h" +#include "qenvironmentlight_p.h" + +QT_BEGIN_NAMESPACE + +using namespace Qt3DCore; + +namespace Qt3DRender { +namespace Render { + +QNodeId EnvironmentLight::shaderData() const +{ + return m_shaderDataId; +} + +void EnvironmentLight::initializeFromPeer(const QNodeCreatedChangeBasePtr &change) +{ + const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QEnvironmentLightData>>(change); + const auto &data = typedChange->data; + m_shaderDataId = data.shaderDataId; +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/lights/environmentlight_p.h b/src/render/lights/environmentlight_p.h new file mode 100644 index 000000000..2ebe72b12 --- /dev/null +++ b/src/render/lights/environmentlight_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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: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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_ENVIRONMENTLIGHT_P_H +#define QT3DRENDER_RENDER_ENVIRONMENTLIGHT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DRender/private/backendnode_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace Render { + +class Q_AUTOTEST_EXPORT EnvironmentLight : public BackendNode +{ +public: + Qt3DCore::QNodeId shaderData() const; + +private: + void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; + + Qt3DCore::QNodeId m_shaderDataId; +}; + +} // namespace Render + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(Qt3DRender::Render::EnvironmentLight*) // LCOV_EXCL_LINE + +#endif // QT3DRENDER_RENDER_ENVIRONMENTLIGHT_P_H diff --git a/src/render/lights/lights.pri b/src/render/lights/lights.pri index 408253d74..dbaa4352f 100644 --- a/src/render/lights/lights.pri +++ b/src/render/lights/lights.pri @@ -5,17 +5,22 @@ HEADERS += \ $$PWD/qabstractlight_p.h \ $$PWD/qdirectionallight.h \ $$PWD/qdirectionallight_p.h \ + $$PWD/qenvironmentlight.h \ + $$PWD/qenvironmentlight_p.h \ $$PWD/qpointlight.h \ $$PWD/qpointlight_p.h \ $$PWD/qspotlight.h \ $$PWD/qspotlight_p.h \ + $$PWD/environmentlight_p.h \ $$PWD/light_p.h \ $$PWD/lightsource_p.h SOURCES += \ $$PWD/qabstractlight.cpp \ $$PWD/qdirectionallight.cpp \ + $$PWD/qenvironmentlight.cpp \ $$PWD/qpointlight.cpp \ $$PWD/qspotlight.cpp \ + $$PWD/environmentlight.cpp \ $$PWD/light.cpp \ $$PWD/lightsource.cpp diff --git a/src/render/lights/qenvironmentlight.cpp b/src/render/lights/qenvironmentlight.cpp new file mode 100644 index 000000000..a094af7b2 --- /dev/null +++ b/src/render/lights/qenvironmentlight.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** 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: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$ +** +****************************************************************************/ + +#include "qenvironmentlight.h" +#include "qenvironmentlight_p.h" +#include "qabstracttexture.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender +{ + +/*! + * \qmltype EnvironmentLight + * \inqmlmodule Qt3D.Render + * \instantiates Qt3DRender::QEnvironmentLight + * \brief Encapsulate an environment light object in a Qt 3D scene. + * \since 5.9 + */ + +QEnvironmentLightPrivate::QEnvironmentLightPrivate() + : m_shaderData(new QShaderData) + , m_irradiance(nullptr) + , m_specular(nullptr) +{ +} + +QEnvironmentLightPrivate::~QEnvironmentLightPrivate() +{ +} + +Qt3DCore::QNodeCreatedChangeBasePtr QEnvironmentLight::createNodeCreationChange() const +{ + auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QEnvironmentLightData>::create(this); + auto &data = creationChange->data; + Q_D(const QEnvironmentLight); + data.shaderDataId = qIdForNode(d->m_shaderData); + return creationChange; +} + +/*! + \class Qt3DRender::QEnvironmentLight + \inmodule Qt3DRender + \brief Encapsulate an environment light object in a Qt 3D scene. + \since 5.9 +*/ + +QEnvironmentLight::QEnvironmentLight(Qt3DCore::QNode *parent) + : QComponent(*new QEnvironmentLightPrivate, parent) +{ + Q_D(QEnvironmentLight); + d->m_shaderData->setParent(this); +} + +/*! \internal */ +QEnvironmentLight::QEnvironmentLight(QEnvironmentLightPrivate &dd, QNode *parent) + : QComponent(dd, parent) +{ + Q_D(QEnvironmentLight); + d->m_shaderData->setParent(this); +} + +QEnvironmentLight::~QEnvironmentLight() +{ +} + +/*! + \qmlproperty Texture EnvironmentLight::irradiance + + Holds the current environment irradiance map texture. + + By default, the environment irradiance texture is null. +*/ + +/*! + \property QEnvironmentLight::irradiance + + Holds the current environment irradiance map texture. + + By default, the environment irradiance texture is null. +*/ +QAbstractTexture *QEnvironmentLight::irradiance() const +{ + Q_D(const QEnvironmentLight); + return d->m_irradiance; +} + +/*! + \qmlproperty Texture EnvironmentLight::specular + + Holds the current environment specular map texture. + + By default, the environment specular texture is null. +*/ + +/*! + \property QEnvironmentLight::specular + + Holds the current environment specular map texture. + + By default, the environment specular texture is null. +*/ +QAbstractTexture *QEnvironmentLight::specular() const +{ + Q_D(const QEnvironmentLight); + return d->m_specular; +} + +void QEnvironmentLight::setIrradiance(QAbstractTexture *i) +{ + Q_D(QEnvironmentLight); + if (irradiance() == i) + return; + + if (irradiance()) + d->unregisterDestructionHelper(irradiance()); + + if (i && !i->parent()) + i->setParent(this); + + d->m_irradiance = i; + d->m_shaderData->setProperty("irradiance", QVariant::fromValue(i)); + + if (i) + d->registerDestructionHelper(i, &QEnvironmentLight::setIrradiance, i); + + emit irradianceChanged(i); +} + +void QEnvironmentLight::setSpecular(QAbstractTexture *s) +{ + Q_D(QEnvironmentLight); + if (specular() == s) + return; + + if (irradiance()) + d->unregisterDestructionHelper(specular()); + + if (s && !s->parent()) + s->setParent(this); + + d->m_specular = s; + d->m_shaderData->setProperty("specular", QVariant::fromValue(s)); + + if (s) + d->registerDestructionHelper(s, &QEnvironmentLight::setSpecular, s); + + emit specularChanged(s); +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/lights/qenvironmentlight.h b/src/render/lights/qenvironmentlight.h new file mode 100644 index 000000000..0a5087c42 --- /dev/null +++ b/src/render/lights/qenvironmentlight.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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: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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QENVIRONMENTLIGHT_H +#define QT3DRENDER_QENVIRONMENTLIGHT_H + +#include <Qt3DRender/qt3drender_global.h> +#include <Qt3DCore/qcomponent.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAbstractTexture; +class QEnvironmentLightPrivate; + +class QT3DRENDERSHARED_EXPORT QEnvironmentLight : public Qt3DCore::QComponent +{ + Q_OBJECT + Q_PROPERTY(Qt3DRender::QAbstractTexture *irradiance READ irradiance WRITE setIrradiance NOTIFY irradianceChanged) + Q_PROPERTY(Qt3DRender::QAbstractTexture *specular READ specular WRITE setSpecular NOTIFY specularChanged) + +public: + explicit QEnvironmentLight(Qt3DCore::QNode *parent = nullptr); + ~QEnvironmentLight(); + + Qt3DRender::QAbstractTexture *irradiance() const; + Qt3DRender::QAbstractTexture *specular() const; + +public Q_SLOTS: + void setIrradiance(Qt3DRender::QAbstractTexture *irradiance); + void setSpecular(Qt3DRender::QAbstractTexture *specular); + +protected: + explicit QEnvironmentLight(QEnvironmentLightPrivate &dd, Qt3DCore::QNode *parent = nullptr); + +Q_SIGNALS: + void irradianceChanged(Qt3DRender::QAbstractTexture *environmentIrradiance); + void specularChanged(Qt3DRender::QAbstractTexture *environmentSpecular); + +private: + Q_DECLARE_PRIVATE(QEnvironmentLight) + Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QENVIRONMENTLIGHT_H diff --git a/src/render/lights/qenvironmentlight_p.h b/src/render/lights/qenvironmentlight_p.h new file mode 100644 index 000000000..e98da5f59 --- /dev/null +++ b/src/render/lights/qenvironmentlight_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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: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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QENVIRONMENTLIGHT_P_H +#define QT3DRENDER_QENVIRONMENTLIGHT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <private/qcomponent_p.h> +#include <qshaderdata.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAbstractTexture; +class QEnvironmentLight; + +class Q_AUTOTEST_EXPORT QEnvironmentLightPrivate : public Qt3DCore::QComponentPrivate +{ +public: + explicit QEnvironmentLightPrivate(); + ~QEnvironmentLightPrivate(); + + Q_DECLARE_PUBLIC(QEnvironmentLight) + QShaderData *m_shaderData; + QAbstractTexture *m_irradiance; + QAbstractTexture *m_specular; +}; + +struct QEnvironmentLightData +{ + Qt3DCore::QNodeId shaderDataId; +}; + +} + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QENVIRONMENTLIGHT_P_H |