summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin Ottens <kevin.ottens@kdab.com>2017-08-02 17:52:59 +0200
committerKevin Ottens <kevin.ottens@kdab.com>2017-09-27 18:10:46 +0000
commit62bee1381d979e8f98970eb4d7f47f6928d13494 (patch)
tree9c34f3863b89b29f98e5d3d945fa65e52b91f74f /src
parent16b0e6dc9b6043b8d98a661a3010879add15409d (diff)
Add textureScale to MetalRoughMaterial
This property was available in the textured phong variants but somehow we didn't implement it yet for metal/rough. This new parameter is not used yet, but will be in the next commit where we unify the vertex shaders. Change-Id: I0d5293f6413a4a0412d92d2d42bf700238938fc6 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/extras/defaults/qmetalroughmaterial.cpp28
-rw-r--r--src/extras/defaults/qmetalroughmaterial.h4
-rw-r--r--src/extras/defaults/qmetalroughmaterial_p.h3
3 files changed, 35 insertions, 0 deletions
diff --git a/src/extras/defaults/qmetalroughmaterial.cpp b/src/extras/defaults/qmetalroughmaterial.cpp
index 91388e905..ac6117101 100644
--- a/src/extras/defaults/qmetalroughmaterial.cpp
+++ b/src/extras/defaults/qmetalroughmaterial.cpp
@@ -71,6 +71,7 @@ QMetalRoughMaterialPrivate::QMetalRoughMaterialPrivate()
, m_roughnessMapParameter(new QParameter(QStringLiteral("roughnessMap"), QVariant()))
, m_ambientOcclusionMapParameter(new QParameter(QStringLiteral("ambientOcclusionMap"), QVariant()))
, m_normalMapParameter(new QParameter(QStringLiteral("normalMap"), QVariant()))
+ , m_textureScaleParameter(new QParameter(QStringLiteral("texCoordScale"), 1.0f))
, m_environmentIrradianceParameter(new QParameter(QStringLiteral("envLight.irradiance"), m_environmentIrradianceTexture))
, m_environmentSpecularParameter(new QParameter(QStringLiteral("envLight.specular"), m_environmentSpecularTexture))
, m_metalRoughEffect(new QEffect())
@@ -107,6 +108,8 @@ void QMetalRoughMaterialPrivate::init()
q, &QMetalRoughMaterial::roughnessChanged);
QObject::connect(m_normalMapParameter, &Qt3DRender::QParameter::valueChanged,
q, &QMetalRoughMaterial::roughnessChanged);
+ connect(m_textureScaleParameter, &Qt3DRender::QParameter::valueChanged,
+ this, &QMetalRoughMaterialPrivate::handleTextureScaleChanged);
m_metalRoughGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
@@ -136,6 +139,7 @@ void QMetalRoughMaterialPrivate::init()
m_metalRoughEffect->addParameter(m_baseColorParameter);
m_metalRoughEffect->addParameter(m_metalnessParameter);
m_metalRoughEffect->addParameter(m_roughnessParameter);
+ m_metalRoughEffect->addParameter(m_textureScaleParameter);
// Note that even though those parameters are not exposed in the API,
// they need to be kept around for now due to a bug in some drivers/GPUs
@@ -149,6 +153,12 @@ void QMetalRoughMaterialPrivate::init()
q->setEffect(m_metalRoughEffect);
}
+void QMetalRoughMaterialPrivate::handleTextureScaleChanged(const QVariant &var)
+{
+ Q_Q(QMetalRoughMaterial);
+ emit q->textureScaleChanged(var.toFloat());
+}
+
/*!
\class Qt3DExtras::QMetalRoughMaterial
\brief The QMetalRoughMaterial provides a default implementation of PBR
@@ -249,6 +259,18 @@ QVariant QMetalRoughMaterial::normal() const
return d->m_normalMapParameter->value();
}
+/*!
+ \property QMetalRoughMaterial::textureScale
+
+ Holds the current texture scale. It is applied as a multiplier to texture
+ coordinates at render time. Defaults to 1.0.
+*/
+float QMetalRoughMaterial::textureScale() const
+{
+ Q_D(const QMetalRoughMaterial);
+ return d->m_textureScaleParameter->value().toFloat();
+}
+
void QMetalRoughMaterial::setBaseColor(const QVariant &baseColor)
{
Q_D(QMetalRoughMaterial);
@@ -348,6 +370,12 @@ void QMetalRoughMaterial::setNormal(const QVariant &normal)
d->m_metalRoughGL3ShaderBuilder->setEnabledLayers(layers);
}
+void QMetalRoughMaterial::setTextureScale(float textureScale)
+{
+ Q_D(QMetalRoughMaterial);
+ d->m_textureScaleParameter->setValue(textureScale);
+}
+
} // namespace Qt3DExtras
QT_END_NAMESPACE
diff --git a/src/extras/defaults/qmetalroughmaterial.h b/src/extras/defaults/qmetalroughmaterial.h
index 6da00ec08..400437338 100644
--- a/src/extras/defaults/qmetalroughmaterial.h
+++ b/src/extras/defaults/qmetalroughmaterial.h
@@ -62,6 +62,7 @@ class QT3DEXTRASSHARED_EXPORT QMetalRoughMaterial : public Qt3DRender::QMaterial
Q_PROPERTY(QVariant roughness READ roughness WRITE setRoughness NOTIFY roughnessChanged)
Q_PROPERTY(QVariant ambientOcclusion READ ambientOcclusion WRITE setAmbientOcclusion NOTIFY ambientOcclusionChanged REVISION 10)
Q_PROPERTY(QVariant normal READ normal WRITE setNormal NOTIFY normalChanged REVISION 10)
+ Q_PROPERTY(float textureScale READ textureScale WRITE setTextureScale NOTIFY textureScaleChanged REVISION 10)
public:
explicit QMetalRoughMaterial(Qt3DCore::QNode *parent = nullptr);
@@ -72,6 +73,7 @@ public:
QVariant roughness() const;
QVariant ambientOcclusion() const;
QVariant normal() const;
+ float textureScale() const;
public Q_SLOTS:
void setBaseColor(const QVariant &baseColor);
@@ -79,6 +81,7 @@ public Q_SLOTS:
void setRoughness(const QVariant &roughness);
void setAmbientOcclusion(const QVariant &ambientOcclusion);
void setNormal(const QVariant &normal);
+ void setTextureScale(float textureScale);
Q_SIGNALS:
void baseColorChanged(const QVariant &baseColor);
@@ -86,6 +89,7 @@ Q_SIGNALS:
void roughnessChanged(const QVariant &roughness);
void ambientOcclusionChanged(const QVariant &ambientOcclusion);
void normalChanged(const QVariant &normal);
+ void textureScaleChanged(float textureScale);
protected:
explicit QMetalRoughMaterial(QMetalRoughMaterialPrivate &dd, Qt3DCore::QNode *parent = nullptr);
diff --git a/src/extras/defaults/qmetalroughmaterial_p.h b/src/extras/defaults/qmetalroughmaterial_p.h
index 8d6cbfcad..838474490 100644
--- a/src/extras/defaults/qmetalroughmaterial_p.h
+++ b/src/extras/defaults/qmetalroughmaterial_p.h
@@ -79,6 +79,8 @@ public:
void init();
+ void handleTextureScaleChanged(const QVariant &var);
+
Qt3DRender::QAbstractTexture *m_environmentIrradianceTexture;
Qt3DRender::QAbstractTexture *m_environmentSpecularTexture;
Qt3DRender::QParameter *m_baseColorParameter;
@@ -89,6 +91,7 @@ public:
Qt3DRender::QParameter *m_roughnessMapParameter;
Qt3DRender::QParameter *m_ambientOcclusionMapParameter;
Qt3DRender::QParameter *m_normalMapParameter;
+ Qt3DRender::QParameter *m_textureScaleParameter;
Qt3DRender::QParameter *m_environmentIrradianceParameter;
Qt3DRender::QParameter *m_environmentSpecularParameter;
Qt3DRender::QEffect *m_metalRoughEffect;