1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSGABSTRACTLIGHT_H
5#define QSSGABSTRACTLIGHT_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3D/private/qquick3dnode_p.h>
19
20#include <QColor>
21
22QT_BEGIN_NAMESPACE
23
24class Q_QUICK3D_EXPORT QQuick3DAbstractLight : public QQuick3DNode
25{
26 Q_OBJECT
27 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
28 Q_PROPERTY(QColor ambientColor READ ambientColor WRITE setAmbientColor NOTIFY ambientColorChanged)
29 Q_PROPERTY(float brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
30 Q_PROPERTY(QQuick3DNode *scope READ scope WRITE setScope NOTIFY scopeChanged)
31 Q_PROPERTY(bool castsShadow READ castsShadow WRITE setCastsShadow NOTIFY castsShadowChanged)
32 Q_PROPERTY(float shadowBias READ shadowBias WRITE setShadowBias NOTIFY shadowBiasChanged)
33 Q_PROPERTY(float shadowFactor READ shadowFactor WRITE setShadowFactor NOTIFY shadowFactorChanged)
34 Q_PROPERTY(QSSGShadowMapQuality shadowMapQuality READ shadowMapQuality WRITE setShadowMapQuality NOTIFY shadowMapQualityChanged)
35 Q_PROPERTY(float shadowMapFar READ shadowMapFar WRITE setShadowMapFar NOTIFY shadowMapFarChanged)
36 Q_PROPERTY(float shadowFilter READ shadowFilter WRITE setShadowFilter NOTIFY shadowFilterChanged)
37 Q_PROPERTY(QSSGBakeMode bakeMode READ bakeMode WRITE setBakeMode NOTIFY bakeModeChanged)
38
39 QML_NAMED_ELEMENT(Light)
40 QML_UNCREATABLE("Light is Abstract")
41public:
42 ~QQuick3DAbstractLight() override;
43
44 enum class QSSGShadowMapQuality {
45 ShadowMapQualityLow,
46 ShadowMapQualityMedium,
47 ShadowMapQualityHigh,
48 ShadowMapQualityVeryHigh,
49 };
50 Q_ENUM(QSSGShadowMapQuality)
51
52 enum class QSSGBakeMode {
53 BakeModeDisabled,
54 BakeModeIndirect,
55 BakeModeAll
56 };
57 Q_ENUM(QSSGBakeMode)
58
59 QColor color() const;
60 QColor ambientColor() const;
61 float brightness() const;
62 QQuick3DNode *scope() const;
63 bool castsShadow() const;
64 float shadowBias() const;
65 float shadowFactor() const;
66 QSSGShadowMapQuality shadowMapQuality() const;
67 float shadowMapFar() const;
68 float shadowFilter() const;
69 QSSGBakeMode bakeMode() const;
70
71public Q_SLOTS:
72 void setColor(const QColor &color);
73 void setAmbientColor(const QColor &ambientColor);
74 void setBrightness(float brightness);
75 void setScope(QQuick3DNode *scope);
76 void setCastsShadow(bool castsShadow);
77 void setShadowBias(float shadowBias);
78 void setShadowFactor(float shadowFactor);
79 void setShadowMapQuality(QQuick3DAbstractLight::QSSGShadowMapQuality shadowMapQuality);
80 void setShadowMapFar(float shadowMapFar);
81 void setShadowFilter(float shadowFilter);
82 void setBakeMode(QQuick3DAbstractLight::QSSGBakeMode bakeMode);
83
84Q_SIGNALS:
85 void colorChanged();
86 void ambientColorChanged();
87 void brightnessChanged();
88 void scopeChanged();
89 void castsShadowChanged();
90 void shadowBiasChanged();
91 void shadowFactorChanged();
92 void shadowMapQualityChanged();
93 void shadowMapFarChanged();
94 void shadowFilterChanged();
95 void bakeModeChanged();
96
97protected:
98 explicit QQuick3DAbstractLight(QQuick3DNodePrivate &dd, QQuick3DNode *parent = nullptr);
99
100 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
101 void markAllDirty() override;
102
103 enum class DirtyFlag {
104 ShadowDirty = (1 << 0),
105 ColorDirty = (1 << 1),
106 BrightnessDirty = (1 << 2),
107 FadeDirty = (1 << 3),
108 AreaDirty = (1 << 4),
109 BakeModeDirty = (1 << 5)
110 };
111 Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
112
113 DirtyFlags m_dirtyFlags = DirtyFlags(DirtyFlag::ShadowDirty)
114 | DirtyFlags(DirtyFlag::ColorDirty)
115 | DirtyFlags(DirtyFlag::BrightnessDirty)
116 | DirtyFlags(DirtyFlag::FadeDirty)
117 | DirtyFlags(DirtyFlag::AreaDirty);
118private:
119 quint32 mapToShadowResolution(QSSGShadowMapQuality resolution);
120
121 QColor m_color;
122 QColor m_ambientColor;
123 float m_brightness = 1.0f;
124 QQuick3DNode *m_scope = nullptr;
125 bool m_castsShadow = false;
126 float m_shadowBias = 0.0f;
127 float m_shadowFactor = 5.0f;
128 QSSGShadowMapQuality m_shadowMapQuality = QSSGShadowMapQuality::ShadowMapQualityLow;
129 float m_shadowMapFar = 5000.0f;
130 float m_shadowFilter = 5.0f;
131 QSSGBakeMode m_bakeMode = QSSGBakeMode::BakeModeDisabled;
132};
133
134QT_END_NAMESPACE
135#endif // QSSGDIRECTIONALLIGHT_H
136

source code of qtquick3d/src/quick3d/qquick3dabstractlight_p.h