Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquick3dabstractlight.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5#include "qquick3dobject_p.h"
6#include "qquick3dnode_p_p.h"
7
8#include <QtQuick3DRuntimeRender/private/qssgrenderlight_p.h>
9#include <QtQuick3DUtils/private/qssgutils_p.h>
10
12
156 : QQuick3DNode(dd, parent)
157 , m_color(Qt::white)
158 , m_ambientColor(Qt::black) {}
159
161
163{
164 return m_color;
165}
166
168{
169 return m_ambientColor;
170}
171
173{
174 return m_brightness;
175}
176
178{
179 return m_scope;
180}
181
183{
184 return m_castsShadow;
185}
186
188{
189 return m_shadowBias;
190}
191
193{
194 return m_shadowFactor;
195}
196
201
203{
204 return m_shadowMapFar;
205}
206
208{
209 return m_shadowFilter;
210}
211
216
218{
220 | DirtyFlags(DirtyFlag::ColorDirty)
221 | DirtyFlags(DirtyFlag::BrightnessDirty)
222 | DirtyFlags(DirtyFlag::FadeDirty)
223 | DirtyFlags(DirtyFlag::AreaDirty)
224 | DirtyFlags(DirtyFlag::BakeModeDirty);
226}
227
229{
230 if (m_color == color)
231 return;
232
233 m_color = color;
236 update();
237}
238
240{
241 if (m_ambientColor == ambientColor)
242 return;
243
244 m_ambientColor = ambientColor;
247 update();
248}
249
251{
252 if (qFuzzyCompare(m_brightness, brightness))
253 return;
254
255 m_brightness = brightness;
258 update();
259}
260
262{
263 if (m_scope == scope)
264 return;
265
266 m_scope = scope;
268 update();
269}
270
272{
273 if (m_castsShadow == castsShadow)
274 return;
275
276 m_castsShadow = castsShadow;
279 update();
280}
281
283{
284 shadowBias = qBound(-1.0f, shadowBias, 1.0f);
285 if (qFuzzyCompare(m_shadowBias, shadowBias))
286 return;
287
288 m_shadowBias = shadowBias;
291 update();
292}
293
295{
296 shadowFactor = qBound(0.0f, shadowFactor, 100.0f);
297 if (qFuzzyCompare(m_shadowFactor, shadowFactor))
298 return;
299
300 m_shadowFactor = shadowFactor;
303 update();
304}
305
308{
309 if (m_shadowMapQuality == shadowMapQuality)
310 return;
311
312 m_shadowMapQuality = shadowMapQuality;
315 update();
316}
317
319{
320 if (m_bakeMode == bakeMode)
321 return;
322
323 m_bakeMode = bakeMode;
326 update();
327}
328
330{
331 if (qFuzzyCompare(m_shadowMapFar, shadowMapFar))
332 return;
333
334 m_shadowMapFar = shadowMapFar;
337 update();
338}
339
341{
342 if (qFuzzyCompare(m_shadowFilter, shadowFilter))
343 return;
344
345 m_shadowFilter = shadowFilter;
348 update();
349}
350
351quint32 QQuick3DAbstractLight::mapToShadowResolution(QSSGShadowMapQuality quality)
352{
353 switch (quality) {
355 return 512;
357 return 1024;
359 return 2048;
360 default:
361 break;
362 }
363 return 256;
364}
365
367{
368 Q_ASSERT_X(node, __FUNCTION__, "Node must have been created in parent class.");
369
371
372 QSSGRenderLight *light = static_cast<QSSGRenderLight *>(node);
373
374 if (m_dirtyFlags.toInt() != 0) // Some flag was set, so mark the light dirty!
376
377 if (m_dirtyFlags.testFlag(DirtyFlag::ColorDirty)) {
378 m_dirtyFlags.setFlag(DirtyFlag::ColorDirty, false);
379 light->m_diffuseColor = QSSGUtils::color::sRGBToLinear(m_color).toVector3D();
380 light->m_specularColor = light->m_diffuseColor;
381 light->m_ambientColor = QSSGUtils::color::sRGBToLinear(m_ambientColor).toVector3D();
382 }
383
386 light->m_brightness = m_brightness;
387 }
388
389 if (m_dirtyFlags.testFlag(DirtyFlag::ShadowDirty)) {
390 m_dirtyFlags.setFlag(DirtyFlag::ShadowDirty, false);
391 light->m_castShadow = m_castsShadow;
392 light->m_shadowBias = m_shadowBias;
393 light->m_shadowFactor = m_shadowFactor;
394 light->m_shadowMapRes = mapToShadowResolution(m_shadowMapQuality);
395 light->m_shadowMapFar = m_shadowMapFar;
396 light->m_shadowFilter = m_shadowFilter;
397 }
398
401 light->m_bakingEnabled = m_bakeMode != QSSGBakeMode::BakeModeDisabled;
402 light->m_fullyBaked = m_bakeMode == QSSGBakeMode::BakeModeAll;
403 }
404
405 if (m_scope) {
406 // Special case:
407 // If the 'scope' is 'this' and this is the first call, then the spatial node is the one we just created.
408 // This is not unlikely, as it can make sense to put all child nodes that should receive light under the light node...
409 if (m_scope == this)
410 light->m_scope = light;
411 else
412 light->m_scope = static_cast<QSSGRenderNode*>(QQuick3DObjectPrivate::get(m_scope)->spatialNode);
413 } else {
414 light->m_scope = nullptr;
415 }
416
417 return node;
418}
419
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
void setScope(QQuick3DNode *scope)
QSSGRenderGraphObject * updateSpatialNode(QSSGRenderGraphObject *node) override
void setCastsShadow(bool castsShadow)
void setBrightness(float brightness)
void setShadowBias(float shadowBias)
void setShadowMapQuality(QQuick3DAbstractLight::QSSGShadowMapQuality shadowMapQuality)
QQuick3DAbstractLight(QQuick3DNodePrivate &dd, QQuick3DNode *parent=nullptr)
\qmltype Light \inherits Node \inqmlmodule QtQuick3D
void setShadowFactor(float shadowFactor)
void setColor(const QColor &color)
void setBakeMode(QQuick3DAbstractLight::QSSGBakeMode bakeMode)
void setShadowFilter(float shadowFilter)
void setAmbientColor(const QColor &ambientColor)
void setShadowMapFar(float shadowMapFar)
QSSGShadowMapQuality shadowMapQuality
void markAllDirty() override
QSSGRenderGraphObject * updateSpatialNode(QSSGRenderGraphObject *node) override
static QQuick3DObjectPrivate * get(QQuick3DObject *item)
constexpr QVector3D toVector3D() const noexcept
Returns the 3D vector form of this 4D vector, dropping the w coordinate.
Definition qvectornd.h:1011
Combined button and popup list for selecting options.
Definition qcompare.h:63
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
GLuint color
[2]
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
#define emit
unsigned int quint32
Definition qtypes.h:50
QGraphicsSvgItem * black
QVector3D m_specularColor
QSSGRenderNode * m_scope
void markDirty(DirtyFlag dirtyFlag)