summaryrefslogtreecommitdiffstats
path: root/src/render/lights
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-11-26 15:06:50 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-11-27 15:15:27 +0000
commit303101facc6f2f88b64c578d047de46f2508e822 (patch)
tree40464463e40b51d9fc8f88d9df0de681ce0d8e24 /src/render/lights
parent422f8d389a5fc17b8bb0d607aaad8239003db50d (diff)
Add attenuation factors for point lights
For decent results the distance and the attenuation factors will have to be taken into account. Task-number: QTBUG-44875 Change-Id: Idc1b1d063802ea350a6da6509bf967e898712f4d Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'src/render/lights')
-rw-r--r--src/render/lights/qpointlight.cpp61
-rw-r--r--src/render/lights/qpointlight.h16
-rw-r--r--src/render/lights/qpointlight_p.h2
3 files changed, 79 insertions, 0 deletions
diff --git a/src/render/lights/qpointlight.cpp b/src/render/lights/qpointlight.cpp
index 539e99b00..58ff5b25e 100644
--- a/src/render/lights/qpointlight.cpp
+++ b/src/render/lights/qpointlight.cpp
@@ -63,6 +63,7 @@ namespace Qt3DRender {
\internal
*/
QPointLightPrivate::QPointLightPrivate()
+ : m_attenuation(0.0f, 0.0f, 0.002f)
{
}
@@ -97,6 +98,66 @@ QPointLight::QPointLight(QPointLightPrivate &dd, QNode *parent)
{
}
+QVector3D QPointLight::attenuation() const
+{
+ Q_D(const QPointLight);
+ return d->m_attenuation;
+}
+
+void QPointLight::setAttenuation(const QVector3D &value)
+{
+ Q_D(QPointLight);
+ if (d->m_attenuation != value) {
+ d->m_attenuation = value;
+ emit attenuationChanged();
+ }
+}
+
+float QPointLight::constantAttenuation() const
+{
+ Q_D(const QPointLight);
+ return d->m_attenuation.x();
+}
+
+void QPointLight::setConstantAttenuation(float value)
+{
+ Q_D(QPointLight);
+ if (d->m_attenuation.x() != value) {
+ d->m_attenuation.setX(value);
+ emit attenuationChanged();
+ }
+}
+
+float QPointLight::linearAttenuation() const
+{
+ Q_D(const QPointLight);
+ return d->m_attenuation.y();
+}
+
+void QPointLight::setLinearAttenuation(float value)
+{
+ Q_D(QPointLight);
+ if (d->m_attenuation.y() != value) {
+ d->m_attenuation.setY(value);
+ emit attenuationChanged();
+ }
+}
+
+float QPointLight::quadraticAttenuation() const
+{
+ Q_D(const QPointLight);
+ return d->m_attenuation.z();
+}
+
+void QPointLight::setQuadraticAttenuation(float value)
+{
+ Q_D(QPointLight);
+ if (d->m_attenuation.z() != value) {
+ d->m_attenuation.setZ(value);
+ emit attenuationChanged();
+ }
+}
+
} // namespace Qt3DRender
QT_END_NAMESPACE
diff --git a/src/render/lights/qpointlight.h b/src/render/lights/qpointlight.h
index eb8b447d7..75b4671d0 100644
--- a/src/render/lights/qpointlight.h
+++ b/src/render/lights/qpointlight.h
@@ -48,10 +48,26 @@ class QPointLightPrivate;
class QT3DRENDERSHARED_EXPORT QPointLight : public QLight
{
Q_OBJECT
+ Q_PROPERTY(QVector3D attenuation READ attenuation WRITE setAttenuation NOTIFY attenuationChanged)
public:
explicit QPointLight(Qt3DCore::QNode *parent = 0);
+ QVector3D attenuation() const;
+ void setAttenuation(const QVector3D &value);
+
+ float constantAttenuation() const;
+ void setConstantAttenuation(float value);
+
+ float linearAttenuation() const;
+ void setLinearAttenuation(float value);
+
+ float quadraticAttenuation() const;
+ void setQuadraticAttenuation(float value);
+
+Q_SIGNALS:
+ void attenuationChanged();
+
protected:
Q_DECLARE_PRIVATE(QPointLight)
QPointLight(QPointLightPrivate &dd, Qt3DCore::QNode *parent);
diff --git a/src/render/lights/qpointlight_p.h b/src/render/lights/qpointlight_p.h
index 2e2cd652e..2929ffd97 100644
--- a/src/render/lights/qpointlight_p.h
+++ b/src/render/lights/qpointlight_p.h
@@ -61,6 +61,8 @@ class QPointLightPrivate : public QLightPrivate
public:
QPointLightPrivate();
+ QVector3D m_attenuation;
+
Q_DECLARE_PUBLIC(QPointLight)
};