diff options
author | Andy Nichols <andy.nichols@qt.io> | 2017-11-20 10:11:24 +0100 |
---|---|---|
committer | Andy Nichols <andy.nichols@qt.io> | 2017-11-20 10:11:45 +0100 |
commit | e611d7f28c2bf5eb7963d8d1e4779293b29b7123 (patch) | |
tree | 37de5fb61bcf1f3e4fe5ef87c91d0dbd0a275d69 /src/extras | |
parent | ab2d05d06b37fe875d360f92fe67e103ae17d80b (diff) | |
parent | 5e94e34c5b9567980929e677357467806aacaf1a (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Change-Id: Ia6496e1ea22f2393a28e37cdd9f6e34f7613db49
Diffstat (limited to 'src/extras')
-rw-r--r-- | src/extras/defaults/defaults.pri | 3 | ||||
-rw-r--r-- | src/extras/defaults/qdiffusemapmaterial.cpp | 3 | ||||
-rw-r--r-- | src/extras/defaults/qdiffusespecularmapmaterial.cpp | 3 | ||||
-rw-r--r-- | src/extras/defaults/qdiffusespecularmaterial.cpp | 496 | ||||
-rw-r--r-- | src/extras/defaults/qdiffusespecularmaterial.h | 102 | ||||
-rw-r--r-- | src/extras/defaults/qdiffusespecularmaterial_p.h | 120 | ||||
-rw-r--r-- | src/extras/defaults/qnormaldiffusemapalphamaterial.cpp | 3 | ||||
-rw-r--r-- | src/extras/defaults/qnormaldiffusemapmaterial.cpp | 3 | ||||
-rw-r--r-- | src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp | 3 | ||||
-rw-r--r-- | src/extras/defaults/qphongalphamaterial.cpp | 3 | ||||
-rw-r--r-- | src/extras/defaults/qphongmaterial.cpp | 3 |
11 files changed, 742 insertions, 0 deletions
diff --git a/src/extras/defaults/defaults.pri b/src/extras/defaults/defaults.pri index 4fe79e0d9..db4db24db 100644 --- a/src/extras/defaults/defaults.pri +++ b/src/extras/defaults/defaults.pri @@ -1,6 +1,8 @@ INCLUDEPATH += $$PWD HEADERS += \ + $$PWD/qdiffusespecularmaterial.h \ + $$PWD/qdiffusespecularmaterial_p.h \ $$PWD/qphongmaterial.h \ $$PWD/qphongmaterial_p.h \ $$PWD/qdiffusemapmaterial_p.h \ @@ -47,6 +49,7 @@ HEADERS += \ $$PWD/qmorphphongmaterial_p.h SOURCES += \ + $$PWD/qdiffusespecularmaterial.cpp \ $$PWD/qphongmaterial.cpp \ $$PWD/qdiffusemapmaterial.cpp \ $$PWD/qnormaldiffusespecularmapmaterial.cpp \ diff --git a/src/extras/defaults/qdiffusemapmaterial.cpp b/src/extras/defaults/qdiffusemapmaterial.cpp index 29e8586e3..26fb99c2c 100644 --- a/src/extras/defaults/qdiffusemapmaterial.cpp +++ b/src/extras/defaults/qdiffusemapmaterial.cpp @@ -201,6 +201,9 @@ void QDiffuseMapMaterialPrivate::handleTextureScaleChanged(const QVariant &var) \since 5.7 \inherits Qt3DRender::QMaterial + \deprecated + \see Qt3DExtras::QDiffuseSpecularMaterial + The specular lighting effect is based on the combination of 3 lighting components ambient, diffuse and specular. The relative strengths of these components are controlled by means of their reflectivity coefficients which are modelled as RGB triplets: diff --git a/src/extras/defaults/qdiffusespecularmapmaterial.cpp b/src/extras/defaults/qdiffusespecularmapmaterial.cpp index cc5facd8c..727eaed27 100644 --- a/src/extras/defaults/qdiffusespecularmapmaterial.cpp +++ b/src/extras/defaults/qdiffusespecularmapmaterial.cpp @@ -208,6 +208,9 @@ void QDiffuseSpecularMapMaterialPrivate::handleTextureScaleChanged(const QVarian \since 5.7 \inherits Qt3DRender::QMaterial + \deprecated + \see Qt3DExtras::QDiffuseSpecularMaterial + The specular lighting effect is based on the combination of 3 lighting components ambient, diffuse and specular. The relative strengths of these components are controlled by means of their reflectivity coefficients which are modelled as RGB triplets: diff --git a/src/extras/defaults/qdiffusespecularmaterial.cpp b/src/extras/defaults/qdiffusespecularmaterial.cpp new file mode 100644 index 000000000..83bba9e41 --- /dev/null +++ b/src/extras/defaults/qdiffusespecularmaterial.cpp @@ -0,0 +1,496 @@ +/**************************************************************************** +** +** 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 "qdiffusespecularmaterial.h" +#include "qdiffusespecularmaterial_p.h" + +#include <Qt3DRender/qfilterkey.h> +#include <Qt3DRender/qmaterial.h> +#include <Qt3DRender/qeffect.h> +#include <Qt3DRender/qtechnique.h> +#include <Qt3DRender/qtexture.h> +#include <Qt3DRender/qshaderprogram.h> +#include <Qt3DRender/qshaderprogrambuilder.h> +#include <Qt3DRender/qparameter.h> +#include <Qt3DRender/qrenderpass.h> +#include <Qt3DRender/qgraphicsapifilter.h> +#include <Qt3DRender/qblendequation.h> +#include <Qt3DRender/qblendequationarguments.h> +#include <Qt3DRender/qnodepthmask.h> +#include <QtCore/QUrl> +#include <QtGui/QVector3D> +#include <QtGui/QVector4D> + + +QT_BEGIN_NAMESPACE + +using namespace Qt3DRender; + +namespace Qt3DExtras { + +QDiffuseSpecularMaterialPrivate::QDiffuseSpecularMaterialPrivate() + : QMaterialPrivate() + , m_effect(new QEffect()) + , m_ambientParameter(new QParameter(QStringLiteral("ka"), QColor::fromRgbF(0.05f, 0.05f, 0.05f, 1.0f))) + , m_diffuseParameter(new QParameter(QStringLiteral("kd"), QColor::fromRgbF(0.7f, 0.7f, 0.7f, 1.0f))) + , m_specularParameter(new QParameter(QStringLiteral("ks"), QColor::fromRgbF(0.01f, 0.01f, 0.01f, 1.0f))) + , m_diffuseTextureParameter(new QParameter(QStringLiteral("diffuseTexture"), QVariant())) + , m_specularTextureParameter(new QParameter(QStringLiteral("specularTexture"), QVariant())) + , m_shininessParameter(new QParameter(QStringLiteral("shininess"), 150.0f)) + , m_normalTextureParameter(new QParameter(QStringLiteral("normalTexture"), QVariant())) + , m_textureScaleParameter(new QParameter(QStringLiteral("texCoordScale"), 1.0f)) + , m_gl3Technique(new QTechnique()) + , m_gl2Technique(new QTechnique()) + , m_es2Technique(new QTechnique()) + , m_gl3RenderPass(new QRenderPass()) + , m_gl2RenderPass(new QRenderPass()) + , m_es2RenderPass(new QRenderPass()) + , m_gl3Shader(new QShaderProgram()) + , m_gl3ShaderBuilder(new QShaderProgramBuilder()) + , m_gl2es2Shader(new QShaderProgram()) + , m_gl2es2ShaderBuilder(new QShaderProgramBuilder()) + , m_noDepthMask(new QNoDepthMask()) + , m_blendState(new QBlendEquationArguments()) + , m_blendEquation(new QBlendEquation()) + , m_filterKey(new QFilterKey) +{ +} + +void QDiffuseSpecularMaterialPrivate::init() +{ + Q_Q(QDiffuseSpecularMaterial); + + connect(m_ambientParameter, &Qt3DRender::QParameter::valueChanged, + this, &QDiffuseSpecularMaterialPrivate::handleAmbientChanged); + QObject::connect(m_diffuseParameter, &Qt3DRender::QParameter::valueChanged, + q, &QDiffuseSpecularMaterial::diffuseChanged); + QObject::connect(m_specularParameter, &Qt3DRender::QParameter::valueChanged, + q, &QDiffuseSpecularMaterial::specularChanged); + connect(m_shininessParameter, &Qt3DRender::QParameter::valueChanged, + this, &QDiffuseSpecularMaterialPrivate::handleShininessChanged); + QObject::connect(m_normalTextureParameter, &Qt3DRender::QParameter::valueChanged, + q, &QDiffuseSpecularMaterial::normalChanged); + connect(m_textureScaleParameter, &Qt3DRender::QParameter::valueChanged, + this, &QDiffuseSpecularMaterialPrivate::handleTextureScaleChanged); + QObject::connect(m_noDepthMask, &QNoDepthMask::enabledChanged, + q, &QDiffuseSpecularMaterial::alphaBlendingEnabledChanged); + + m_gl3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert")))); + m_gl3ShaderBuilder->setParent(q); + m_gl3ShaderBuilder->setShaderProgram(m_gl3Shader); + m_gl3ShaderBuilder->setFragmentShaderGraph(QUrl(QStringLiteral("qrc:/shaders/graphs/phong.frag.json"))); + m_gl3ShaderBuilder->setEnabledLayers({QStringLiteral("diffuse"), + QStringLiteral("specular"), + QStringLiteral("normal")}); + + m_gl2es2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/default.vert")))); + m_gl2es2ShaderBuilder->setParent(q); + m_gl2es2ShaderBuilder->setShaderProgram(m_gl2es2Shader); + m_gl2es2ShaderBuilder->setFragmentShaderGraph(QUrl(QStringLiteral("qrc:/shaders/graphs/phong.frag.json"))); + m_gl2es2ShaderBuilder->setEnabledLayers({QStringLiteral("diffuse"), + QStringLiteral("specular"), + QStringLiteral("normal")}); + + + m_gl3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL); + m_gl3Technique->graphicsApiFilter()->setMajorVersion(3); + m_gl3Technique->graphicsApiFilter()->setMinorVersion(1); + m_gl3Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::CoreProfile); + + m_gl2Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL); + m_gl2Technique->graphicsApiFilter()->setMajorVersion(2); + m_gl2Technique->graphicsApiFilter()->setMinorVersion(0); + m_gl2Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::NoProfile); + + m_es2Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGLES); + m_es2Technique->graphicsApiFilter()->setMajorVersion(2); + m_es2Technique->graphicsApiFilter()->setMinorVersion(0); + m_es2Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::NoProfile); + + m_noDepthMask->setEnabled(false); + m_blendState->setEnabled(false); + m_blendState->setSourceRgb(QBlendEquationArguments::SourceAlpha); + m_blendState->setDestinationRgb(QBlendEquationArguments::OneMinusSourceAlpha); + m_blendEquation->setEnabled(false); + m_blendEquation->setBlendFunction(QBlendEquation::Add); + + m_gl3RenderPass->setShaderProgram(m_gl3Shader); + m_gl2RenderPass->setShaderProgram(m_gl2es2Shader); + m_es2RenderPass->setShaderProgram(m_gl2es2Shader); + + m_gl3RenderPass->addRenderState(m_noDepthMask); + m_gl3RenderPass->addRenderState(m_blendState); + m_gl3RenderPass->addRenderState(m_blendEquation); + + m_gl2RenderPass->addRenderState(m_noDepthMask); + m_gl2RenderPass->addRenderState(m_blendState); + m_gl2RenderPass->addRenderState(m_blendEquation); + + m_es2RenderPass->addRenderState(m_noDepthMask); + m_es2RenderPass->addRenderState(m_blendState); + m_es2RenderPass->addRenderState(m_blendEquation); + + m_gl3Technique->addRenderPass(m_gl3RenderPass); + m_gl2Technique->addRenderPass(m_gl2RenderPass); + m_es2Technique->addRenderPass(m_es2RenderPass); + + m_filterKey->setParent(q); + m_filterKey->setName(QStringLiteral("renderingStyle")); + m_filterKey->setValue(QStringLiteral("forward")); + + m_gl3Technique->addFilterKey(m_filterKey); + m_gl2Technique->addFilterKey(m_filterKey); + m_es2Technique->addFilterKey(m_filterKey); + + m_effect->addTechnique(m_gl3Technique); + m_effect->addTechnique(m_gl2Technique); + m_effect->addTechnique(m_es2Technique); + + m_effect->addParameter(m_ambientParameter); + m_effect->addParameter(m_diffuseParameter); + m_effect->addParameter(m_specularParameter); + m_effect->addParameter(m_shininessParameter); + m_effect->addParameter(m_textureScaleParameter); + + q->setEffect(m_effect); +} + +void QDiffuseSpecularMaterialPrivate::handleAmbientChanged(const QVariant &var) +{ + Q_Q(QDiffuseSpecularMaterial); + emit q->ambientChanged(var.value<QColor>()); +} + +void QDiffuseSpecularMaterialPrivate::handleShininessChanged(const QVariant &var) +{ + Q_Q(QDiffuseSpecularMaterial); + emit q->shininessChanged(var.toFloat()); +} + +void QDiffuseSpecularMaterialPrivate::handleTextureScaleChanged(const QVariant &var) +{ + Q_Q(QDiffuseSpecularMaterial); + emit q->textureScaleChanged(var.toFloat()); +} + +/*! + \class Qt3DExtras::QDiffuseSpecularMaterial + \brief The QDiffuseSpecularMaterial class provides a default implementation + of the phong lighting effect. + \inmodule Qt3DExtras + \since 5.10 + \inherits Qt3DRender::QMaterial + + The phong lighting effect is based on the combination of 3 lighting + components ambient, diffuse and specular. The relative strengths of these + components are controlled by means of their reflectivity coefficients which + are modelled as RGB triplets: + + \list + \li Ambient is the color that is emitted by an object without any other + light source. + \li Diffuse is the color that is emitted for rought surface reflections + with the lights. + \li Specular is the color emitted for shiny surface reflections with the + lights. + \li The shininess of a surface is controlled by a float property. + \endlist + + This material uses an effect with a single render pass approach and + performs per fragment lighting. Techniques are provided for OpenGL 2, + OpenGL 3 or above as well as OpenGL ES 2. +*/ +/*! + \qmltype DiffuseSpecularMaterial + \brief The DiffuseSpecularMaterial class provides a default implementation + of the phong lighting effect. + \since 5.10 + \inqmlmodule Qt3D.Extras + \instantiates Qt3DExtras::QDiffuseSpecularMaterial + + The phong lighting effect is based on the combination of 3 lighting + components ambient, diffuse and specular. The relative strengths of these + components are controlled by means of their reflectivity coefficients which + are modelled as RGB triplets: + + \list + \li Ambient is the color that is emitted by an object without any other + light source. + \li Diffuse is the color that is emitted for rought surface reflections + with the lights. + \li Specular is the color emitted for shiny surface reflections with the + lights. + \li The shininess of a surface is controlled by a float property. + \endlist + + This material uses an effect with a single render pass approach and + performs per fragment lighting. Techniques are provided for OpenGL 2, + OpenGL 3 or above as well as OpenGL ES 2. + */ + +/*! + Constructs a new QDiffuseSpecularMaterial instance with parent object \a parent. +*/ +QDiffuseSpecularMaterial::QDiffuseSpecularMaterial(QNode *parent) + : QMaterial(*new QDiffuseSpecularMaterialPrivate, parent) +{ + Q_D(QDiffuseSpecularMaterial); + d->init(); +} + +/*! + Destroys the QDiffuseSpecularMaterial. +*/ +QDiffuseSpecularMaterial::~QDiffuseSpecularMaterial() +{ +} + +/*! + \property QDiffuseSpecularMaterial::ambient + + Holds the ambient color. +*/ +/*! + \qmlproperty color DiffuseSpecularMaterial::ambient + + Holds the ambient color. +*/ +QColor QDiffuseSpecularMaterial::ambient() const +{ + Q_D(const QDiffuseSpecularMaterial); + return d->m_ambientParameter->value().value<QColor>(); +} + +/*! + \property QDiffuseSpecularMaterial::diffuse + + Holds the diffuse color of the material. This can be either a plain color + value or a texture. +*/ +/*! + \qmlproperty var DiffuseSpecularMaterial::diffuse + + Holds the diffuse color of the material. This can be either a plain color + value or a texture. +*/ +QVariant QDiffuseSpecularMaterial::diffuse() const +{ + Q_D(const QDiffuseSpecularMaterial); + return d->m_diffuseParameter->value(); +} + +/*! + \property QDiffuseSpecularMaterial::specular + + Holds the specular color of the material. This can be either a plain color + value or a texture. +*/ +/*! + \qmlproperty var DiffuseSpecularMaterial::specular + + Holds the specular color of the material. This can be either a plain color + value or a texture. +*/ +QVariant QDiffuseSpecularMaterial::specular() const +{ + Q_D(const QDiffuseSpecularMaterial); + return d->m_specularParameter->value(); +} + +/*! + \property QDiffuseSpecularMaterial::shininess + + Holds the shininess exponent. +*/ +/*! + \qmlproperty real DiffuseSpecularMaterial::shininess + + Holds the shininess exponent. +*/ +float QDiffuseSpecularMaterial::shininess() const +{ + Q_D(const QDiffuseSpecularMaterial); + return d->m_shininessParameter->value().toFloat(); +} + +/*! + \property QDiffuseSpecularMaterial::normal + + Holds the current normal map texture of the material. This can only be a + texture, otherwise it is ignored. By default this map is not set. +*/ +/*! + \qmlproperty var DiffuseSpecularMaterial::normal + + Holds the current normal map texture of the material. This can only be a + texture, otherwise it is ignored. By default this map is not set. +*/ +QVariant QDiffuseSpecularMaterial::normal() const +{ + Q_D(const QDiffuseSpecularMaterial); + return d->m_normalTextureParameter->value(); +} + +/*! + \property QDiffuseSpecularMaterial::textureScale + + Holds the current texture scale. It is applied as a multiplier to texture + coordinates at render time. Defaults to 1.0. +*/ +/*! + \qmlproperty real DiffuseSpecularMaterial::textureScale + + Holds the current texture scale. It is applied as a multiplier to texture + coordinates at render time. Defaults to 1.0. +*/ +float QDiffuseSpecularMaterial::textureScale() const +{ + Q_D(const QDiffuseSpecularMaterial); + return d->m_textureScaleParameter->value().toFloat(); +} + +/*! + \property QDiffuseSpecularMaterial::alphaBlending + + Indicates if the alpha information coming from the diffuse property will + be taken into account during rendering. Defaults to false. +*/ +/*! + \qmlproperty bool DiffuseSpecularMaterial::alphaBlending + + Indicates if the alpha information coming from the diffuse property will + be taken into account during rendering. Defaults to false. +*/ +bool QDiffuseSpecularMaterial::isAlphaBlendingEnabled() const +{ + Q_D(const QDiffuseSpecularMaterial); + return d->m_noDepthMask->isEnabled(); +} + +void QDiffuseSpecularMaterial::setAmbient(const QColor &ambient) +{ + Q_D(QDiffuseSpecularMaterial); + d->m_ambientParameter->setValue(ambient); +} + +void QDiffuseSpecularMaterial::setDiffuse(const QVariant &diffuse) +{ + Q_D(QDiffuseSpecularMaterial); + d->m_diffuseParameter->setValue(diffuse); + d->m_diffuseTextureParameter->setValue(diffuse); + + auto layers = d->m_gl3ShaderBuilder->enabledLayers(); + if (diffuse.value<QAbstractTexture *>()) { + layers.removeAll(QStringLiteral("diffuse")); + layers.append(QStringLiteral("diffuseTexture")); + d->m_effect->addParameter(d->m_diffuseTextureParameter); + d->m_effect->removeParameter(d->m_diffuseParameter); + } else { + layers.removeAll(QStringLiteral("diffuseTexture")); + layers.append(QStringLiteral("diffuse")); + d->m_effect->removeParameter(d->m_diffuseTextureParameter); + d->m_effect->addParameter(d->m_diffuseParameter); + } + d->m_gl3ShaderBuilder->setEnabledLayers(layers); + d->m_gl2es2ShaderBuilder->setEnabledLayers(layers); +} + +void QDiffuseSpecularMaterial::setSpecular(const QVariant &specular) +{ + Q_D(QDiffuseSpecularMaterial); + d->m_specularParameter->setValue(specular); + d->m_specularTextureParameter->setValue(specular); + + auto layers = d->m_gl3ShaderBuilder->enabledLayers(); + if (specular.value<QAbstractTexture *>()) { + layers.removeAll(QStringLiteral("specular")); + layers.append(QStringLiteral("specularTexture")); + d->m_effect->addParameter(d->m_specularTextureParameter); + d->m_effect->removeParameter(d->m_specularParameter); + } else { + layers.removeAll(QStringLiteral("specularTexture")); + layers.append(QStringLiteral("specular")); + d->m_effect->removeParameter(d->m_specularTextureParameter); + d->m_effect->addParameter(d->m_specularParameter); + } + d->m_gl3ShaderBuilder->setEnabledLayers(layers); + d->m_gl2es2ShaderBuilder->setEnabledLayers(layers); +} + +void QDiffuseSpecularMaterial::setShininess(float shininess) +{ + Q_D(QDiffuseSpecularMaterial); + d->m_shininessParameter->setValue(shininess); +} + +void QDiffuseSpecularMaterial::setNormal(const QVariant &normal) +{ + Q_D(QDiffuseSpecularMaterial); + d->m_normalTextureParameter->setValue(normal); + + auto layers = d->m_gl3ShaderBuilder->enabledLayers(); + if (normal.value<QAbstractTexture *>()) { + layers.removeAll(QStringLiteral("normal")); + layers.append(QStringLiteral("normalTexture")); + d->m_effect->addParameter(d->m_normalTextureParameter); + } else { + layers.removeAll(QStringLiteral("normalTexture")); + layers.append(QStringLiteral("normal")); + d->m_effect->removeParameter(d->m_normalTextureParameter); + } + d->m_gl3ShaderBuilder->setEnabledLayers(layers); +} + +void QDiffuseSpecularMaterial::setTextureScale(float textureScale) +{ + Q_D(QDiffuseSpecularMaterial); + d->m_textureScaleParameter->setValue(textureScale); +} + +void QDiffuseSpecularMaterial::setAlphaBlendingEnabled(bool enabled) +{ + Q_D(QDiffuseSpecularMaterial); + d->m_noDepthMask->setEnabled(enabled); + d->m_blendState->setEnabled(enabled); + d->m_blendEquation->setEnabled(enabled); +} + +} // namespace Qt3DExtras + +QT_END_NAMESPACE diff --git a/src/extras/defaults/qdiffusespecularmaterial.h b/src/extras/defaults/qdiffusespecularmaterial.h new file mode 100644 index 000000000..5f21da093 --- /dev/null +++ b/src/extras/defaults/qdiffusespecularmaterial.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** 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 QT3DEXTRAS_QDIFFUSESPECULARMATERIAL_H +#define QT3DEXTRAS_QDIFFUSESPECULARMATERIAL_H + +#include <Qt3DExtras/qt3dextras_global.h> +#include <Qt3DRender/qmaterial.h> +#include <QtGui/QColor> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { + +class QDiffuseSpecularMaterialPrivate; + +class QT3DEXTRASSHARED_EXPORT QDiffuseSpecularMaterial : public Qt3DRender::QMaterial +{ + Q_OBJECT + Q_PROPERTY(QColor ambient READ ambient WRITE setAmbient NOTIFY ambientChanged) + Q_PROPERTY(QVariant diffuse READ diffuse WRITE setDiffuse NOTIFY diffuseChanged) + Q_PROPERTY(QVariant specular READ specular WRITE setSpecular NOTIFY specularChanged) + Q_PROPERTY(float shininess READ shininess WRITE setShininess NOTIFY shininessChanged) + Q_PROPERTY(QVariant normal READ normal WRITE setNormal NOTIFY normalChanged) + Q_PROPERTY(float textureScale READ textureScale WRITE setTextureScale NOTIFY textureScaleChanged) + Q_PROPERTY(bool alphaBlending READ isAlphaBlendingEnabled WRITE setAlphaBlendingEnabled NOTIFY alphaBlendingEnabledChanged) + +public: + explicit QDiffuseSpecularMaterial(Qt3DCore::QNode *parent = nullptr); + ~QDiffuseSpecularMaterial(); + + QColor ambient() const; + QVariant diffuse() const; + QVariant specular() const; + float shininess() const; + QVariant normal() const; + float textureScale() const; + bool isAlphaBlendingEnabled() const; + +public Q_SLOTS: + void setAmbient(const QColor &ambient); + void setDiffuse(const QVariant &diffuse); + void setSpecular(const QVariant &specular); + void setShininess(float shininess); + void setNormal(const QVariant &normal); + void setTextureScale(float textureScale); + void setAlphaBlendingEnabled(bool enabled); + +Q_SIGNALS: + void ambientChanged(const QColor &ambient); + void diffuseChanged(const QVariant &diffuse); + void specularChanged(const QVariant &specular); + void shininessChanged(float shininess); + void normalChanged(const QVariant &normal); + void textureScaleChanged(float textureScale); + void alphaBlendingEnabledChanged(bool enabled); + +private: + Q_DECLARE_PRIVATE(QDiffuseSpecularMaterial) +}; + +} // namespace Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_QDIFFUSESPECULARMATERIAL_H diff --git a/src/extras/defaults/qdiffusespecularmaterial_p.h b/src/extras/defaults/qdiffusespecularmaterial_p.h new file mode 100644 index 000000000..2b0b2184f --- /dev/null +++ b/src/extras/defaults/qdiffusespecularmaterial_p.h @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** 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 QT3DEXTRAS_QDIFFUSESPECULARMATERIAL_P_H +#define QT3DEXTRAS_QDIFFUSESPECULARMATERIAL_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/qmaterial_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QFilterKey; +class QEffect; +class QTechnique; +class QParameter; +class QShaderProgram; +class QShaderProgramBuilder; +class QRenderPass; +class QNoDepthMask; +class QBlendEquationArguments; +class QBlendEquation; + +} // namespace Qt3DRender + +namespace Qt3DExtras { + +class QDiffuseSpecularMaterial; + +class QDiffuseSpecularMaterialPrivate : public Qt3DRender::QMaterialPrivate +{ +public: + QDiffuseSpecularMaterialPrivate(); + + void init(); + + void handleAmbientChanged(const QVariant &var); + void handleShininessChanged(const QVariant &var); + void handleTextureScaleChanged(const QVariant &var); + + Qt3DRender::QEffect *m_effect; + Qt3DRender::QParameter *m_ambientParameter; + Qt3DRender::QParameter *m_diffuseParameter; + Qt3DRender::QParameter *m_specularParameter; + Qt3DRender::QParameter *m_diffuseTextureParameter; + Qt3DRender::QParameter *m_specularTextureParameter; + Qt3DRender::QParameter *m_shininessParameter; + Qt3DRender::QParameter *m_normalTextureParameter; + Qt3DRender::QParameter *m_textureScaleParameter; + Qt3DRender::QTechnique *m_gl3Technique; + Qt3DRender::QTechnique *m_gl2Technique; + Qt3DRender::QTechnique *m_es2Technique; + Qt3DRender::QRenderPass *m_gl3RenderPass; + Qt3DRender::QRenderPass *m_gl2RenderPass; + Qt3DRender::QRenderPass *m_es2RenderPass; + Qt3DRender::QShaderProgram *m_gl3Shader; + Qt3DRender::QShaderProgramBuilder *m_gl3ShaderBuilder; + Qt3DRender::QShaderProgram *m_gl2es2Shader; + Qt3DRender::QShaderProgramBuilder *m_gl2es2ShaderBuilder; + Qt3DRender::QNoDepthMask *m_noDepthMask; + Qt3DRender::QBlendEquationArguments *m_blendState; + Qt3DRender::QBlendEquation *m_blendEquation; + Qt3DRender::QFilterKey *m_filterKey; + + Q_DECLARE_PUBLIC(QDiffuseSpecularMaterial) +}; + +} // Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_QDIFFUSESPECULARMATERIAL_P_H + diff --git a/src/extras/defaults/qnormaldiffusemapalphamaterial.cpp b/src/extras/defaults/qnormaldiffusemapalphamaterial.cpp index c276c9717..9b2a64520 100644 --- a/src/extras/defaults/qnormaldiffusemapalphamaterial.cpp +++ b/src/extras/defaults/qnormaldiffusemapalphamaterial.cpp @@ -165,6 +165,9 @@ void QNormalDiffuseMapAlphaMaterialPrivate::init() \since 5.7 \inherits Qt3DExtras::QNormalDiffuseMapMaterial + \deprecated + \see Qt3DExtras::QDiffuseSpecularMaterial + The specular lighting effect is based on the combination of 3 lighting components ambient, diffuse and specular. The relative strengths of these components are controlled by means of their reflectivity coefficients which are modelled as RGB triplets: diff --git a/src/extras/defaults/qnormaldiffusemapmaterial.cpp b/src/extras/defaults/qnormaldiffusemapmaterial.cpp index 687e59751..beed4085e 100644 --- a/src/extras/defaults/qnormaldiffusemapmaterial.cpp +++ b/src/extras/defaults/qnormaldiffusemapmaterial.cpp @@ -218,6 +218,9 @@ void QNormalDiffuseMapMaterialPrivate::handleTextureScaleChanged(const QVariant \since 5.7 \inherits Qt3DRender::QMaterial + \deprecated + \see Qt3DExtras::QDiffuseSpecularMaterial + The specular lighting effect is based on the combination of 3 lighting components ambient, diffuse and specular. The relative strengths of these components are controlled by means of their reflectivity coefficients which are modelled as RGB triplets: diff --git a/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp b/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp index 7665c07a7..028fd14e7 100644 --- a/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp +++ b/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp @@ -226,6 +226,9 @@ void QNormalDiffuseSpecularMapMaterialPrivate::handleTextureScaleChanged(const Q \since 5.7 \inherits Qt3DRender::QMaterial + \deprecated + \see Qt3DExtras::QDiffuseSpecularMaterial + The specular lighting effect is based on the combination of 3 lighting components ambient, diffuse and specular. The relative strengths of these components are controlled by means of their reflectivity coefficients which are modelled as RGB triplets: diff --git a/src/extras/defaults/qphongalphamaterial.cpp b/src/extras/defaults/qphongalphamaterial.cpp index fb0871ee4..24cff94e9 100644 --- a/src/extras/defaults/qphongalphamaterial.cpp +++ b/src/extras/defaults/qphongalphamaterial.cpp @@ -209,6 +209,9 @@ void QPhongAlphaMaterialPrivate::handleShininessChanged(const QVariant &var) \since 5.7 \inherits Qt3DRender::QMaterial + \deprecated + \see Qt3DExtras::QDiffuseSpecularMaterial + The phong lighting effect is based on the combination of 3 lighting components ambient, diffuse and specular. The relative strengths of these components are controlled by means of their reflectivity coefficients which are modelled as RGB triplets: diff --git a/src/extras/defaults/qphongmaterial.cpp b/src/extras/defaults/qphongmaterial.cpp index c76e3a6ef..17d837568 100644 --- a/src/extras/defaults/qphongmaterial.cpp +++ b/src/extras/defaults/qphongmaterial.cpp @@ -184,6 +184,9 @@ void QPhongMaterialPrivate::handleShininessChanged(const QVariant &var) \since 5.7 \inherits Qt3DRender::QMaterial + \deprecated + \see Qt3DExtras::QDiffuseSpecularMaterial + The phong lighting effect is based on the combination of 3 lighting components ambient, diffuse and specular. The relative strengths of these components are controlled by means of their reflectivity coefficients which are modelled as RGB triplets: |