Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquick3dfog.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
6
#
include
"qquick3dfog_p.h"
7
8
QT_BEGIN_NAMESPACE
9
10
/*!
11
\qmltype Fog
12
\inherits QtObject
13
\inqmlmodule QtQuick3D
14
\brief Specifies fog settings for a scene.
15
\since 6.5
16
17
When the \l{SceneEnvironment::fog}{fog} property of a \l
18
SceneEnvironment is set to a valid Fog object, the properties are used to
19
configure the rendering of fog.
20
21
\image fog.jpg
22
{Scene with fog effect}
23
24
The simple fog provided by this type is implemented by the materials. It is
25
not a post-processing effect, meaning it does not involve additional render
26
passes processing the texture with the output of the \l View3D, but is
27
rather implemented in the fragment shader for each renderable object
28
(submesh of \l Model) with a \l PrincipledMaterial or shaded \l
29
CustomMaterial.
30
31
Fog is configured by a number of properties:
32
33
\list
34
35
\li General settings: \l color and \l density
36
37
\li Depth fog settings: \l depthEnabled, \l depthNear, \l depthFar, \l depthCurve
38
39
\li Height fog settings: \l heightEnabled, \l leastIntenseY, \l mostIntenseY, \l heightCurve
40
41
\li Color transmission settings: \l transmitEnabled, \l transmitCurve
42
43
\endlist
44
45
For example, the following snippet enables depth (but not height) fog using
46
the default fog parameters:
47
48
\qml
49
environment: SceneEnvironment {
50
backgroundMode: SceneEnvironment.Color
51
clearColor: theFog.color
52
fog: Fog {
53
id: theFog
54
enabled: true
55
depthEnabled: true
56
}
57
}
58
\endqml
59
60
Instead of defining the Fog object inline, it is also possible to reference
61
a Fog object by \c id. And since \l ExtendedSceneEnvironment inherits
62
everything from its parent type \l SceneEnvironment, fog can be used with
63
\l ExtendedSceneEnvironment as well:
64
65
\qml
66
Fog {
67
id: theFog
68
enabled: true
69
depthEnabled: true
70
}
71
environment: ExtendedSceneEnvironment {
72
fog: theFog
73
}
74
\endqml
75
76
\sa {Qt Quick 3D - Simple Fog Example}, {Qt Quick 3D - Scene Effects Example}
77
*/
78
79
/*!
80
\qmlproperty bool Fog::enabled
81
82
Controls whether fog is applied to the scene. The default value is false.
83
84
Enabling depth or height fog has no effect without setting this value to
85
true.
86
87
\sa depthEnabled, heightEnabled
88
*/
89
90
bool
QQuick3DFog::isEnabled()
const
91
{
92
return
m_enabled;
93
}
94
95
void
QQuick3DFog::setEnabled(
bool
newEnabled)
96
{
97
if
(m_enabled == newEnabled)
98
return
;
99
100
m_enabled = newEnabled;
101
emit enabledChanged();
102
emit changed();
103
}
104
105
/*!
106
\qmlproperty color Fog::color
107
108
The color of the fog. The default value is "#8099b3"
109
110
\image fog_color_1.jpg
111
{Scene with slightly desaturated blue fog}
112
113
114
The same scene with color changed to be more blueish:
115
116
\image fog_color_2.jpg
117
{Scene with blue fog}
118
119
\sa density
120
*/
121
122
QColor QQuick3DFog::color()
const
123
{
124
return
m_color;
125
}
126
127
void
QQuick3DFog::setColor(
const
QColor &newColor)
128
{
129
if
(m_color == newColor)
130
return
;
131
132
m_color = newColor;
133
emit colorChanged();
134
emit changed();
135
}
136
137
/*!
138
\qmlproperty real Fog::density
139
140
Controls the fog amount, in practice this is a multiplier in range 0-1. The
141
default value is 1.0. Reducing the value decreases the strength of the fog
142
effect. Applicable only when depthEnabled is set to true.
143
144
The on-screen visual effect may be affected by a number of other settings
145
from \l ExtendedSceneEnvironment, such as tonemapping or glow and bloom.
146
The same density value may give different results depending on what other
147
effects are enabled, and how those are configured.
148
149
An example scene with density set to \c{0.95}:
150
151
\image fog_density_095.jpg
152
{Scene with fog density of 95 percent}
153
154
The same scene with density reduced to \c{0.15}:
155
156
\image fog_density_015.jpg
157
{Scene with fog density of 15 percent}
158
159
\sa color
160
*/
161
162
float
QQuick3DFog::density()
const
163
{
164
return
m_density;
165
}
166
167
void
QQuick3DFog::setDensity(
float
newDensity)
168
{
169
if
(qFuzzyCompare(m_density, newDensity))
170
return
;
171
172
m_density = newDensity;
173
emit densityChanged();
174
emit changed();
175
}
176
177
/*!
178
\qmlproperty bool Fog::depthEnabled
179
180
Controls if the fog appears in the distance. The default value is false.
181
182
\sa heightEnabled, enabled, depthNear, depthFar, depthCurve
183
*/
184
185
bool
QQuick3DFog::isDepthEnabled()
const
186
{
187
return
m_depthEnabled;
188
}
189
190
void
QQuick3DFog::setDepthEnabled(
bool
newDepthEnabled)
191
{
192
if
(m_depthEnabled == newDepthEnabled)
193
return
;
194
195
m_depthEnabled = newDepthEnabled;
196
emit depthEnabledChanged();
197
emit changed();
198
}
199
200
/*!
201
\qmlproperty real Fog::depthNear
202
203
Starting distance from the camera. The default value is 10.0. Applicable
204
only when depthEnabled is set to true.
205
206
As an example, take this scene, first with a higher depthNear value.
207
208
\image fog_depthnear_higher.jpg
209
{Scene with higher depthNear fog value}
210
211
Decreasing the value of depthNear results in the fog effectively "moving
212
closer" to the camera as it now starts from a smaller distance from the
213
camera:
214
215
\image fog_depthnear_lower.jpg
216
{Scene with lower depthNear fog value}
217
218
\note The scene, including the camera and the models, are expected to be set
219
up accordingly, so that sensible ranges can be defined by properties such
220
as depthNear and depthFar. Do not expect that fog can always be enabled on
221
a scene containing assets imported as-is, without tuning the transforms
222
first. For example, the example screenshots on this page with the
223
\l{https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Sponza}{Sponza}
224
model are generated after manually applying an additional scale of \c{(100,
225
100, 100)} on the instantiated Sponza component that was generated by the
226
\c balsam tool from the glTF source asset. This then gave a sufficient Z
227
range to get good looking results by tuning the depthNear and depthFar
228
values.
229
230
\sa depthFar, depthEnabled
231
*/
232
233
float
QQuick3DFog::depthNear()
const
234
{
235
return
m_depthNear;
236
}
237
238
void
QQuick3DFog::setDepthNear(
float
newDepthNear)
239
{
240
if
(qFuzzyCompare(m_depthNear, newDepthNear))
241
return
;
242
243
m_depthNear = newDepthNear;
244
emit depthNearChanged();
245
emit changed();
246
}
247
248
/*!
249
\qmlproperty real Fog::depthFar
250
251
Ending distance from the camera. The default value is 1000.0. Applicable
252
only when depthEnabled is set to true.
253
254
\note The scene, including the camera and the models, are expected to be set
255
up accordingly, so that sensible ranges can be defined by properties such
256
as depthNear and depthFar. Do not expect that fog can always be enabled on
257
a scene containing assets imported as-is, without tuning the transforms
258
first. For example, the example screenshots on this page with the
259
\l{https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Sponza}{Sponza}
260
model are generated after manually applying an additional scale of \c{(100,
261
100, 100)} on the instantiated Sponza component that was generated by the
262
\c balsam tool from the glTF source asset. This then gave a sufficient Z
263
range to get good looking results by tuning the depthNear and depthFar
264
values.
265
266
\sa depthNear, depthEnabled
267
*/
268
269
float
QQuick3DFog::depthFar()
const
270
{
271
return
m_depthFar;
272
}
273
274
void
QQuick3DFog::setDepthFar(
float
newDepthFar)
275
{
276
if
(qFuzzyCompare(m_depthFar, newDepthFar))
277
return
;
278
279
m_depthFar = newDepthFar;
280
emit depthFarChanged();
281
emit changed();
282
}
283
284
/*!
285
\qmlproperty real Fog::depthCurve
286
287
The default value is 1.0.
288
289
Applicable only when depthEnabled is set to true.
290
291
\sa depthEnabled
292
*/
293
294
float
QQuick3DFog::depthCurve()
const
295
{
296
return
m_depthCurve;
297
}
298
299
void
QQuick3DFog::setDepthCurve(
float
newDepthCurve)
300
{
301
if
(qFuzzyCompare(m_depthCurve, newDepthCurve))
302
return
;
303
304
m_depthCurve = newDepthCurve;
305
emit depthCurveChanged();
306
emit changed();
307
}
308
309
/*!
310
\qmlproperty bool Fog::heightEnabled
311
312
Controls if a height fog is enabled. The default value is false.
313
314
\sa depthEnabled, enabled, leastIntenseY, mostIntenseY, heightCurve
315
*/
316
317
bool
QQuick3DFog::isHeightEnabled()
const
318
{
319
return
m_heightEnabled;
320
}
321
322
void
QQuick3DFog::setHeightEnabled(
bool
newHeightEnabled)
323
{
324
if
(m_heightEnabled == newHeightEnabled)
325
return
;
326
327
m_heightEnabled = newHeightEnabled;
328
emit heightEnabledChanged();
329
emit changed();
330
}
331
332
/*!
333
\qmlproperty real Fog::leastIntenseY
334
335
Specifies the position (Y coordinate) where the fog is the least intense.
336
The default value is 10.0. Applicable only when heightEnabled is set to
337
true.
338
339
\note By default the value is larger than mostIntenseY. As long as this is
340
true, the fog is rendered top to bottom. When this value is smaller than
341
mostIntenseY, the fog will render bottom to top.
342
343
\note The Y axis points upwards in Qt Quick 3D scenes.
344
345
Pictured here is a scene with height fog enabled (no depth fog), and
346
leastIntenseY set to a value so the fog is only spreading around the bottom
347
of the Sponza scene.
348
349
\image fog_height_least_y_smaller.jpg
350
{Scene with lower leastIntenseY fog value}
351
352
Increasing the value of leastIntenseY makes the fog spread higher since it
353
now effectively starts at a higher Y position in the scene. (remember that
354
the Y axis points upwards)
355
356
\image fog_height_least_y_bigger.jpg
357
{Scene with higher leastIntenseY fog value}
358
359
\note As with depth fog, the scene is expected to be set up accordingly, so
360
that sensible Y coordinate ranges can be defined by leastIntenseY and
361
mostIntenseY. Do not expect that fog can always be enabled on a scene
362
containing assets imported as-is, without tuning the transforms first. For
363
example, the example screenshots on this page with the
364
\l{https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Sponza}{Sponza}
365
model are generated after manually applying an additional scale of \c{(100,
366
100, 100)} on the instantiated Sponza component that was generated by the
367
\c balsam tool from the glTF source asset.
368
369
\sa mostIntenseY, heightEnabled
370
*/
371
372
float
QQuick3DFog::leastIntenseY()
const
373
{
374
return
m_leastIntenseY;
375
}
376
377
void
QQuick3DFog::setLeastIntenseY(
float
newLeastIntenseY)
378
{
379
if
(qFuzzyCompare(m_leastIntenseY, newLeastIntenseY))
380
return
;
381
382
m_leastIntenseY = newLeastIntenseY;
383
emit leastIntenseYChanged();
384
emit changed();
385
}
386
387
/*!
388
\qmlproperty real Fog::mostIntenseY
389
390
Specifies the position (Y coordinate) where the fog is the most intense.
391
The default value is 0. Applicable only when heightEnabled is set to true.
392
393
\note By default the value is smaller than leastIntenseY. As long as this is
394
true, the fog is rendered top to bottom. When this value is larger than
395
leastIntenseY, the fog will render bottom to top.
396
397
\note The Y axis points upwards in Qt Quick 3D scenes.
398
399
\note As with depth fog, the scene is expected to be set up accordingly, so
400
that sensible Y coordinate ranges can be defined by leastIntenseY and
401
mostIntenseY. Do not expect that fog can always be enabled on a scene
402
containing assets imported as-is, without tuning the transforms first. For
403
example, the example screenshots on this page with the
404
\l{https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Sponza}{Sponza}
405
model are generated after manually applying an additional scale of \c{(100,
406
100, 100)} on the instantiated Sponza component that was generated by the
407
\c balsam tool from the glTF source asset.
408
409
\sa leastIntenseY, heightEnabled
410
*/
411
412
float
QQuick3DFog::mostIntenseY()
const
413
{
414
return
m_mostIntenseY;
415
}
416
417
void
QQuick3DFog::setMostIntenseY(
float
newMostIntenseY)
418
{
419
if
(qFuzzyCompare(m_mostIntenseY, newMostIntenseY))
420
return
;
421
422
m_mostIntenseY = newMostIntenseY;
423
emit mostIntenseYChanged();
424
emit changed();
425
}
426
427
/*!
428
\qmlproperty real Fog::heightCurve
429
430
Specifies the intensity of the height fog. The default value is 1.0.
431
Applicable only when heightEnabled is set to true.
432
433
\sa heightEnabled
434
*/
435
436
float
QQuick3DFog::heightCurve()
const
437
{
438
return
m_heightCurve;
439
}
440
441
void
QQuick3DFog::setHeightCurve(
float
newHeightCurve)
442
{
443
if
(qFuzzyCompare(m_heightCurve, newHeightCurve))
444
return
;
445
446
m_heightCurve = newHeightCurve;
447
emit heightCurveChanged();
448
emit changed();
449
}
450
451
/*!
452
\qmlproperty bool Fog::transmitEnabled
453
454
Controls if the fog has a light transmission effect. The default value is
455
false.
456
*/
457
458
bool
QQuick3DFog::isTransmitEnabled()
const
459
{
460
return
m_transmitEnabled;
461
}
462
463
void
QQuick3DFog::setTransmitEnabled(
bool
newTransmitEnabled)
464
{
465
if
(m_transmitEnabled == newTransmitEnabled)
466
return
;
467
468
m_transmitEnabled = newTransmitEnabled;
469
emit transmitEnabledChanged();
470
emit changed();
471
}
472
473
/*!
474
\qmlproperty real Fog::transmitCurve
475
476
Intensity of the light transmission effect. The default value is 1.0.
477
Applicable only when transmitEnabled is set to true.
478
*/
479
480
float
QQuick3DFog::transmitCurve()
const
481
{
482
return
m_transmitCurve;
483
}
484
485
void
QQuick3DFog::setTransmitCurve(
float
newTransmitCurve)
486
{
487
if
(qFuzzyCompare(m_transmitCurve, newTransmitCurve))
488
return
;
489
490
m_transmitCurve = newTransmitCurve;
491
emit transmitCurveChanged();
492
emit changed();
493
}
494
495
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtquick3d
src
quick3d
qquick3dfog.cpp
Generated on
for Qt by
1.18.0