1 | // Copyright (C) 2019 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QSSGSCENEENVIRONMENT_H |
5 | #define QSSGSCENEENVIRONMENT_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 <QtCore/QObject> |
19 | #include <QtCore/QVector> |
20 | |
21 | #include <QtGui/QColor> |
22 | |
23 | #include <QtQuick3D/private/qquick3dnode_p.h> |
24 | |
25 | #include <QtQml/QQmlListProperty> |
26 | |
27 | #include <QtQuick3D/private/qquick3deffect_p.h> |
28 | #include <QtQuick3D/private/qquick3dlightmapper_p.h> |
29 | #include <QtQuick3D/private/qquick3ddebugsettings_p.h> |
30 | #include <QtQuick3D/private/qquick3dfog_p.h> |
31 | |
32 | QT_BEGIN_NAMESPACE |
33 | |
34 | class QQuick3DTexture; |
35 | class QQuick3DCubeMapTexture; |
36 | class Q_QUICK3D_EXPORT QQuick3DSceneEnvironment : public QQuick3DObject |
37 | { |
38 | Q_OBJECT |
39 | Q_PROPERTY(QQuick3DEnvironmentAAModeValues antialiasingMode READ antialiasingMode WRITE setAntialiasingMode NOTIFY antialiasingModeChanged) |
40 | Q_PROPERTY(QQuick3DEnvironmentAAQualityValues antialiasingQuality READ antialiasingQuality WRITE setAntialiasingQuality NOTIFY antialiasingQualityChanged) |
41 | |
42 | Q_PROPERTY(bool temporalAAEnabled READ temporalAAEnabled WRITE setTemporalAAEnabled NOTIFY temporalAAEnabledChanged) |
43 | Q_PROPERTY(float temporalAAStrength READ temporalAAStrength WRITE setTemporalAAStrength NOTIFY temporalAAStrengthChanged) |
44 | Q_PROPERTY(QQuick3DEnvironmentBackgroundTypes backgroundMode READ backgroundMode WRITE setBackgroundMode NOTIFY backgroundModeChanged) |
45 | Q_PROPERTY(QColor clearColor READ clearColor WRITE setClearColor NOTIFY clearColorChanged) |
46 | Q_PROPERTY(bool depthTestEnabled READ depthTestEnabled WRITE setDepthTestEnabled NOTIFY depthTestEnabledChanged) |
47 | Q_PROPERTY(bool depthPrePassEnabled READ depthPrePassEnabled WRITE setDepthPrePassEnabled NOTIFY depthPrePassEnabledChanged) |
48 | |
49 | Q_PROPERTY(float aoStrength READ aoStrength WRITE setAoStrength NOTIFY aoStrengthChanged) |
50 | Q_PROPERTY(float aoDistance READ aoDistance WRITE setAoDistance NOTIFY aoDistanceChanged) |
51 | Q_PROPERTY(float aoSoftness READ aoSoftness WRITE setAoSoftness NOTIFY aoSoftnessChanged) |
52 | Q_PROPERTY(bool aoDither READ aoDither WRITE setAoDither NOTIFY aoDitherChanged) |
53 | Q_PROPERTY(int aoSampleRate READ aoSampleRate WRITE setAoSampleRate NOTIFY aoSampleRateChanged) |
54 | Q_PROPERTY(float aoBias READ aoBias WRITE setAoBias NOTIFY aoBiasChanged) |
55 | Q_PROPERTY(bool aoEnabled READ aoEnabled WRITE setAoEnabled NOTIFY aoEnabledChanged REVISION(6, 5)) |
56 | |
57 | Q_PROPERTY(QQuick3DTexture *lightProbe READ lightProbe WRITE setLightProbe NOTIFY lightProbeChanged) |
58 | Q_PROPERTY(float probeExposure READ probeExposure WRITE setProbeExposure NOTIFY probeExposureChanged) |
59 | Q_PROPERTY(float probeHorizon READ probeHorizon WRITE setProbeHorizon NOTIFY probeHorizonChanged) |
60 | Q_PROPERTY(QVector3D probeOrientation READ probeOrientation WRITE setProbeOrientation NOTIFY probeOrientationChanged) |
61 | |
62 | Q_PROPERTY(QQuick3DCubeMapTexture *skyBoxCubeMap READ skyBoxCubeMap WRITE setSkyBoxCubeMap NOTIFY skyBoxCubeMapChanged REVISION(6, 4)) |
63 | |
64 | Q_PROPERTY(QQuick3DEnvironmentTonemapModes tonemapMode READ tonemapMode WRITE setTonemapMode NOTIFY tonemapModeChanged) |
65 | |
66 | Q_PROPERTY(QQmlListProperty<QQuick3DEffect> effects READ effects) |
67 | |
68 | Q_PROPERTY(float skyboxBlurAmount READ skyboxBlurAmount WRITE setSkyboxBlurAmount NOTIFY skyboxBlurAmountChanged REVISION(6, 4)) |
69 | Q_PROPERTY(bool specularAAEnabled READ specularAAEnabled WRITE setSpecularAAEnabled NOTIFY specularAAEnabledChanged REVISION(6, 4)) |
70 | |
71 | Q_PROPERTY(QQuick3DLightmapper *lightmapper READ lightmapper WRITE setLightmapper NOTIFY lightmapperChanged REVISION(6, 4)) |
72 | |
73 | Q_PROPERTY(QQuick3DDebugSettings *debugSettings READ debugSettings WRITE setDebugSettings NOTIFY debugSettingsChanged REVISION(6, 5)) |
74 | Q_PROPERTY(QRect scissorRect READ scissorRect WRITE setScissorRect NOTIFY scissorRectChanged REVISION(6, 5)) |
75 | |
76 | Q_PROPERTY(QQuick3DFog *fog READ fog WRITE setFog NOTIFY fogChanged REVISION(6, 5)) |
77 | |
78 | QML_NAMED_ELEMENT(SceneEnvironment) |
79 | |
80 | public: |
81 | |
82 | enum QQuick3DEnvironmentAAModeValues { |
83 | NoAA = 0, |
84 | SSAA, |
85 | MSAA, |
86 | ProgressiveAA |
87 | }; |
88 | Q_ENUM(QQuick3DEnvironmentAAModeValues) |
89 | |
90 | enum QQuick3DEnvironmentAAQualityValues { |
91 | Medium = 2, |
92 | High = 4, |
93 | VeryHigh = 8 |
94 | }; |
95 | Q_ENUM(QQuick3DEnvironmentAAQualityValues) |
96 | |
97 | enum QQuick3DEnvironmentBackgroundTypes { |
98 | Transparent = 0, |
99 | Unspecified, |
100 | Color, |
101 | SkyBox, |
102 | SkyBoxCubeMap |
103 | }; |
104 | Q_ENUM(QQuick3DEnvironmentBackgroundTypes) |
105 | |
106 | enum QQuick3DEnvironmentTonemapModes { |
107 | TonemapModeNone = 0, |
108 | TonemapModeLinear, |
109 | TonemapModeAces, |
110 | TonemapModeHejlDawson, |
111 | TonemapModeFilmic |
112 | }; |
113 | Q_ENUM(QQuick3DEnvironmentTonemapModes) |
114 | |
115 | explicit QQuick3DSceneEnvironment(QQuick3DObject *parent = nullptr); |
116 | ~QQuick3DSceneEnvironment() override; |
117 | |
118 | QQuick3DEnvironmentAAModeValues antialiasingMode() const; |
119 | QQuick3DEnvironmentAAQualityValues antialiasingQuality() const; |
120 | bool temporalAAEnabled() const; |
121 | float temporalAAStrength() const; |
122 | |
123 | QQuick3DEnvironmentBackgroundTypes backgroundMode() const; |
124 | QColor clearColor() const; |
125 | |
126 | float aoStrength() const; |
127 | float aoDistance() const; |
128 | float aoSoftness() const; |
129 | bool aoDither() const; |
130 | int aoSampleRate() const; |
131 | float aoBias() const; |
132 | Q_REVISION(6, 5) bool aoEnabled() const; |
133 | Q_REVISION(6, 5) void setAoEnabled(bool newAoEnabled); |
134 | |
135 | QQuick3DTexture *lightProbe() const; |
136 | float probeExposure() const; |
137 | float probeHorizon() const; |
138 | QVector3D probeOrientation() const; |
139 | |
140 | bool depthTestEnabled() const; |
141 | bool depthPrePassEnabled() const; |
142 | |
143 | QQuick3DEnvironmentTonemapModes tonemapMode() const; |
144 | |
145 | QQmlListProperty<QQuick3DEffect> effects(); |
146 | |
147 | Q_REVISION(6, 4) float skyboxBlurAmount() const; |
148 | Q_REVISION(6, 4) bool specularAAEnabled() const; |
149 | Q_REVISION(6, 4) QQuick3DLightmapper *lightmapper() const; |
150 | Q_REVISION(6, 4) QQuick3DCubeMapTexture *skyBoxCubeMap() const; |
151 | |
152 | Q_REVISION(6, 5) QQuick3DDebugSettings *debugSettings() const; |
153 | Q_REVISION(6, 5) QRect scissorRect() const; |
154 | |
155 | Q_REVISION(6, 5) QQuick3DFog *fog() const; |
156 | |
157 | bool gridEnabled() const; |
158 | void setGridEnabled(bool newGridEnabled); |
159 | |
160 | float gridScale() const; |
161 | void setGridScale(float newGridScale); |
162 | |
163 | uint gridFlags() const; |
164 | void setGridFlags(uint newGridFlags); |
165 | |
166 | public Q_SLOTS: |
167 | void setAntialiasingMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentAAModeValues antialiasingMode); |
168 | void setAntialiasingQuality(QQuick3DSceneEnvironment::QQuick3DEnvironmentAAQualityValues antialiasingQuality); |
169 | void setTemporalAAEnabled(bool temporalAAEnabled); |
170 | void setTemporalAAStrength(float strength); |
171 | |
172 | void setBackgroundMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes backgroundMode); |
173 | void setClearColor(const QColor &clearColor); |
174 | |
175 | void setAoStrength(float aoStrength); |
176 | void setAoDistance(float aoDistance); |
177 | void setAoSoftness(float aoSoftness); |
178 | void setAoDither(bool aoDither); |
179 | void setAoSampleRate(int aoSampleRate); |
180 | void setAoBias(float aoBias); |
181 | |
182 | void setLightProbe(QQuick3DTexture *lightProbe); |
183 | void setProbeExposure(float probeExposure); |
184 | void setProbeHorizon(float probeHorizon); |
185 | void setProbeOrientation(const QVector3D &orientation); |
186 | |
187 | void setDepthTestEnabled(bool depthTestEnabled); |
188 | void setDepthPrePassEnabled(bool depthPrePassEnabled); |
189 | |
190 | void setTonemapMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentTonemapModes tonemapMode); |
191 | |
192 | Q_REVISION(6, 4) void setSkyboxBlurAmount(float newSkyboxBlurAmount); |
193 | Q_REVISION(6, 4) void setSpecularAAEnabled(bool enabled); |
194 | Q_REVISION(6, 4) void setSkyBoxCubeMap(QQuick3DCubeMapTexture *newSkyBoxCubeMap); |
195 | |
196 | Q_REVISION(6, 4) void setLightmapper(QQuick3DLightmapper *lightmapper); |
197 | |
198 | Q_REVISION(6, 5) void setDebugSettings(QQuick3DDebugSettings *newDebugSettings); |
199 | Q_REVISION(6, 5) void setScissorRect(QRect scissorRect); |
200 | |
201 | Q_REVISION(6, 5) void setFog(QQuick3DFog *fog); |
202 | |
203 | Q_SIGNALS: |
204 | void antialiasingModeChanged(); |
205 | void antialiasingQualityChanged(); |
206 | void temporalAAEnabledChanged(); |
207 | void temporalAAStrengthChanged(); |
208 | |
209 | void backgroundModeChanged(); |
210 | void clearColorChanged(); |
211 | |
212 | void aoStrengthChanged(); |
213 | void aoDistanceChanged(); |
214 | void aoSoftnessChanged(); |
215 | void aoDitherChanged(); |
216 | void aoSampleRateChanged(); |
217 | void aoBiasChanged(); |
218 | Q_REVISION(6, 5) void aoEnabledChanged(); |
219 | |
220 | void lightProbeChanged(); |
221 | void probeExposureChanged(); |
222 | void probeHorizonChanged(); |
223 | void probeOrientationChanged(); |
224 | |
225 | void depthTestEnabledChanged(); |
226 | void depthPrePassEnabledChanged(); |
227 | |
228 | void tonemapModeChanged(); |
229 | |
230 | Q_REVISION(6, 4) void skyboxBlurAmountChanged(); |
231 | Q_REVISION(6, 4) void specularAAEnabledChanged(); |
232 | Q_REVISION(6, 4) void lightmapperChanged(); |
233 | Q_REVISION(6, 4) void skyBoxCubeMapChanged(); |
234 | |
235 | Q_REVISION(6, 5) void debugSettingsChanged(); |
236 | Q_REVISION(6, 5) void scissorRectChanged(); |
237 | |
238 | Q_REVISION(6, 5) void fogChanged(); |
239 | |
240 | protected: |
241 | QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override; |
242 | void itemChange(ItemChange, const ItemChangeData &) override; |
243 | virtual const QVector<QQuick3DEffect *> &effectList() const; |
244 | virtual bool useBuiltinTonemapper() const; |
245 | |
246 | private: |
247 | friend class QQuick3DSceneRenderer; |
248 | |
249 | static constexpr float defaultAoDistance() { return 5.0f; } |
250 | |
251 | QVector<QQuick3DEffect *> m_effects; |
252 | |
253 | static void qmlAppendEffect(QQmlListProperty<QQuick3DEffect> *list, QQuick3DEffect *effect); |
254 | static QQuick3DEffect *qmlEffectAt(QQmlListProperty<QQuick3DEffect> *list, qsizetype index); |
255 | static qsizetype qmlEffectsCount(QQmlListProperty<QQuick3DEffect> *list); |
256 | static void qmlClearEffects(QQmlListProperty<QQuick3DEffect> *list); |
257 | |
258 | void updateSceneManager(QQuick3DSceneManager *manager); |
259 | |
260 | QQuick3DEnvironmentAAModeValues m_antialiasingMode = NoAA; |
261 | QQuick3DEnvironmentAAQualityValues m_antialiasingQuality = High; |
262 | bool m_temporalAAEnabled = false; |
263 | float m_temporalAAStrength = 0.3f; |
264 | bool m_specularAAEnabled = false; |
265 | |
266 | QQuick3DEnvironmentBackgroundTypes m_backgroundMode = Transparent; |
267 | QColor m_clearColor = Qt::black; |
268 | |
269 | float m_aoStrength = 0.0f; |
270 | float m_aoDistance = defaultAoDistance(); |
271 | float m_aoSoftness = 50.0f; |
272 | float m_aoBias = 0.0f; |
273 | int m_aoSampleRate = 2; |
274 | bool m_aoDither = false; |
275 | bool m_aoEnabled = false; |
276 | QQuick3DTexture *m_lightProbe = nullptr; |
277 | float m_probeExposure = 1.0f; |
278 | float m_probeHorizon = 0.0f; |
279 | QVector3D m_probeOrientation; |
280 | |
281 | bool m_depthTestEnabled = true; |
282 | bool m_depthPrePassEnabled = false; |
283 | QQuick3DEnvironmentTonemapModes m_tonemapMode = QQuick3DEnvironmentTonemapModes::TonemapModeLinear; |
284 | float m_skyboxBlurAmount = 0.0f; |
285 | QQuick3DLightmapper *m_lightmapper = nullptr; |
286 | QMetaObject::Connection m_lightmapperSignalConnection; |
287 | QQuick3DCubeMapTexture *m_skyBoxCubeMap = nullptr; |
288 | QQuick3DDebugSettings *m_debugSettings = nullptr; |
289 | QRect m_scissorRect; |
290 | QMetaObject::Connection m_debugSettingsSignalConnection; |
291 | bool m_gridEnabled = false; |
292 | uint m_gridFlags = 0; |
293 | float m_gridScale = 1.0f; |
294 | QQuick3DFog *m_fog = nullptr; |
295 | QMetaObject::Connection m_fogSignalConnection; |
296 | }; |
297 | |
298 | QT_END_NAMESPACE |
299 | |
300 | #endif // QSSGSCENEENVIRONMENT_H |
301 | |