Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dsceneenvironment.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// Qt-Security score:significant reason:default
4
5
11
13
14/*!
15 \qmltype SceneEnvironment
16 \inherits Object3D
17 \inqmlmodule QtQuick3D
18 \brief Lets you configure how a scene is rendered.
19
20 SceneEnvironment defines a set of global properties for how a scene should be rendered.
21
22 \note The QtQuick3D.Helpers module offers an \l ExtendedSceneEnvironment
23 type which inherits from SceneEnvironment and adds a number of built-in
24 effects on top.
25
26 To use SceneEnvironment or \l ExtendedSceneEnvironment, associate the
27 \l{View3D::environment}{environment property} of a View3D with an instance
28 of these types. The object can be declared inline, for example like this:
29
30 \qml
31 View3D {
32 environment: SceneEnvironment {
33 antialiasingMode: SceneEnvironment.MSAA
34 tonemapMode: SceneEnvironment.TonemapModeFilmic
35 backgroundMode: SceneEnvironment.SkyBox
36 lightProbe: Texture {
37 source: "panoramic_hdri_background.hdr"
38 }
39 }
40 }
41 \endqml
42
43 Alternatively, the environment object can be defined separately. It can
44 then be referenced by one or more View3D objects. An example code snippet,
45 using \l ExtendedSceneEnvironment this time:
46
47 \qml
48 ExtendedSceneEnvironment {
49 id: myEnv
50 vignetteEnabled: true
51 }
52
53 View3D {
54 width: parent.width / 2
55 environment: myEnv
56 }
57
58 View3D {
59 width: parent.width / 2
60 x: parent.width / 2
61 environment: myEnv
62 }
63 \endqml
64
65 \section1 Feature Overview
66
67 \list
68
69 \li Anti-aliasing settings. See \l{Anti-Aliasing Best Practices} for an
70 overview of this topic. The relevant properties are \l antialiasingMode, \l
71 antialiasingQuality, \l specularAAEnabled, \l temporalAAEnabled, \l
72 temporalAAStrength. In addition, if \l ExtendedSceneEnvironment is used,
73 another method is available via
74 \l{ExtendedSceneEnvironment::fxaaEnabled}{fxaaEnabled}.
75
76 \li Screen space ambient occlusion. The relevant properties are \l
77 aoEnabled, \l aoStrength, \l aoBias, \l aoDistance, \l aoDither, \l
78 aoSampleRate, \l aoSoftness. Note that
79 \l{ExtendedSceneEnvironment::ssgiEnabled}{SSGI} also provides ambient
80 occlusion, and it will often give better quality results, albeit possibly at
81 a higher performance cost. Avoid enabling SceneEnvironment's ambient
82 occlusion and ExtendedSceneEnvironment's SSGI together.
83
84 \li Clear color, skybox, image-based lighting. For more information on IBL,
85 see \l{Using Image-Based Lighting}. The relevant properties are \l
86 backgroundMode, \l clearColor, \l lightProbe, \l probeExposure, \l
87 probeHorizon, \l probeOrientation, \l skyboxBlurAmount, \l skyBoxCubeMap.
88
89 \li Tonemapping. \l tonemapMode configures the tonemapping method that is
90 used to convert the high dynamic range color values to the 0-1 range at the
91 end of the graphics pipeline. \l ExtendedSceneEnvironment offers a few
92 additional properties, such as
93 \l{ExtendedSceneEnvironment::whitePoint}{whitePoint} and
94 \l{ExtendedSceneEnvironment::sharpnessAmount}{sharpnessAmount} that can be
95 used to tune the tonemapping calculations.
96
97 \li Depth buffer settings. The relevant properties are \l
98 depthPrePassEnabled, \l depthTestEnabled.
99
100 \li Post-processing effects. In addition to the built-in post-processing
101 effects provided by \l ExtendedSceneEnvironment, applications can provide
102 their own custom effects via the \l Effect type. The \l effects property is
103 a list of \l Effect instances.
104
105 \li Debug visualization settings, such as wireframe mode or rendering only
106 certain color contributions for the materials. This is controlled by the \l
107 DebugSettings object referenced from the \l debugSettings property. Most of
108 these settings can also be controlled interactively when a \l DebugView
109 item is added to the scene.
110
111 \li Fog settings. To enable fog, set an appropriately configured
112 \l [QML] Fog object in the \l [QML] fog property.
113
114 \li Lightmap baking settings. When pre-baked lightmaps are used for some
115 models in the scene, the \l Lightmapper object set in the \l lightmapper
116 property defines the settings used during the baking process.
117
118 \li Scissor settings. To apply a scissor different than the viewport, set
119 the \l scissorRect property.
120
121 \endlist
122
123 \sa ExtendedSceneEnvironment
124*/
125
126QQuick3DSceneEnvironment::QQuick3DSceneEnvironment(QQuick3DObject *parent)
127 : QQuick3DObject(*(new QQuick3DObjectPrivate(QQuick3DObjectPrivate::Type::SceneEnvironment)), parent)
128{
129 m_debugSettings = new QQuick3DDebugSettings(this);
130 m_debugSettingsSignalConnection = QObject::connect(m_debugSettings, &QQuick3DDebugSettings::changed, this,
131 [this] { update(); });
132 QObject::connect(m_debugSettings, &QObject::destroyed, this,
133 [this](QObject *obj) {
134 if (m_debugSettings == obj) {
135 m_debugSettings = nullptr;
136 update();
137 }
138 });
139}
140
141QQuick3DSceneEnvironment::~QQuick3DSceneEnvironment()
142{
143}
144
145/*!
146 \qmlproperty enumeration QtQuick3D::SceneEnvironment::antialiasingMode
147 \since 5.15
148
149 This property controls the antialiasing mode that is applied when rendering
150 the scene.
151
152 Possible values are:
153 \value SceneEnvironment.NoAA No antialiasing is applied.
154 \value SceneEnvironment.SSAA Supersample antialiasing is applied.
155 \value SceneEnvironment.MSAA Multisample antialiasing is applied.
156 \value SceneEnvironment.ProgressiveAA Progressive antialiasing is applied.
157
158 The default value is \c SceneEnvironment.NoAA.
159
160 \b Supersampling
161
162 The scene is rendered in a higher resolution, and then scaled down to
163 actual resolution.
164
165 \b Pros: High quality. Antialiases all scene content and not just geometry
166 silhouettes.
167
168 \b Cons: Usually more expensive than MSAA. Increases video memory usage.
169 Supported with View3D items with all renderMode except Inline, but since
170 the technique implies rendering to a texture first, enabling SSAA with a
171 renderMode of Underlay or Overlay will result in using an intermediate
172 texture and render pass that would normally not be needed, meaning the
173 performance costs may be more noticeable. It is recommended to use SSAA
174 only when the renderMode is the default Offscreen.
175
176 \b Multisampling
177
178 The edges of geometry are super-sampled, resulting in smoother silhouettes.
179 This technique has no effect on the materials inside geometry, however.
180
181 \b Pros: Works with any View3D item regardless of the renderMode. Good
182 results on geometry silhouettes, where aliasing is often most noticeable;
183 works with fast animation without issues. Performance depends purely on the
184 system's (GPU) capabilities.
185
186 \b Cons: Does not help with texture or reflection issues. Increases video
187 memory usage. Can be expensive to use on less powerful graphics hardware.
188 Can be controlled on a per-window basis or for individual View3D items
189 depending on the renderMode. When using Underlay/Overlay with an effect
190 applied or Offscreen, MSAA can be controlled for each View3D item. On the
191 other hand, using Underlay/Overlay without any effect or Inline will make
192 MSAA controlled per-window.
193
194 \note For View3D items with a \l{QtQuick3D::View3D::renderMode}{renderMode}
195 other than Underlay/Overlay with effects or Offscreen, multisampling can only
196 be enabled via the \l{QSurfaceFormat::setSamples()}{QSurfaceFormat} of the
197 QQuickWindow or QQuickView. This will then affect all content,
198 both 2D and 3D, in that window.
199
200 \b {Progressive antialiasing}
201
202 This property enables and sets the level of progressive antialiasing
203 applied to the scene.
204
205 When all content of the scene has stopped moving, the camera is jiggled
206 very slightly between frames, and the result of each new frame is blended
207 with the previous frames. The more frames you accumulate, the better
208 looking the result.
209
210 \b Pros: Provides great results when all content in the scene is standing still.
211
212 \b Cons: Does not take effect if any visual changes are occurring.
213 Expensive due to having to accumulate and blend. Increases video memory
214 usage.
215
216 \note Progressing antialiasing is not currently supported with multiview
217 rendering, and should not be used in VR/AR applications.
218
219 See \l{Anti-Aliasing Best Practices} for further discussion on
220 anti-aliasing methods.
221*/
222QQuick3DSceneEnvironment::QQuick3DEnvironmentAAModeValues QQuick3DSceneEnvironment::antialiasingMode() const
223{
224 return m_antialiasingMode;
225}
226
227/*!
228 \qmlproperty enumeration QtQuick3D::SceneEnvironment::antialiasingQuality
229 \since 5.15
230
231 This property sets the level of antialiasing applied to the scene.
232 Behavior depends on used antialiasingMode. With antialiasingMode
233 property set to \c NoAA this property doesn't have an effect.
234
235 Possible values are:
236 \value SceneEnvironment.Medium
237 SSAA: Antialiasing uses 1.2x supersampling resolution.\br
238 MSAA: Antialiasing uses 2 samples per pixel.\br
239 ProgressiveAA: Antialiasing uses 2 frames for final image.
240 \value SceneEnvironment.High
241 SSAA: Antialiasing uses 1.5x supersampling resolution.\br
242 MSAA: Antialiasing uses 4 samples per pixel.\br
243 ProgressiveAA: Antialiasing uses 4 frames for final image.
244 \value SceneEnvironment.VeryHigh
245 SSAA: Antialiasing uses 2.0x supersampling resolution.\br
246 MSAA: Antialiasing uses 8 samples per pixel.\br
247 ProgressiveAA: Antialiasing uses 8 frames for final image.
248
249 The default value is \c SceneEnvironment.High
250*/
251
252QQuick3DSceneEnvironment::QQuick3DEnvironmentAAQualityValues QQuick3DSceneEnvironment::antialiasingQuality() const
253{
254 return m_antialiasingQuality;
255}
256
257/*!
258 \qmlproperty enumeration QtQuick3D::SceneEnvironment::backgroundMode
259
260 This property controls if and how the background of the scene should be
261 cleared.
262
263 \note The clearing of the color buffer backing the View 3D does not always
264 happen: depending on the \l{QtQuick3D::View3D::renderMode}{renderMode}
265 property the View3D may not perform any clearing on its own, in which case
266 \c{SceneEnvironment.Transparent} and \c{SceneEnvironment.Color} have no
267 effect. Only the default \c Offscreen \l{View3D::renderMode}{render mode}
268 (rendering into a texture) supports all clearing modes. With the \c
269 Underlay mode, use \l{QQuickWindow::setColor()} or
270 \l[QtQuick]{Window::color}{Window.color} to control the clear color for the
271 Qt Quick scene. SkyBox is handled differently, as it implies drawing actual
272 geometry, so that works identically across all render modes.
273
274 \value SceneEnvironment.Transparent
275 The scene is cleared to be transparent. This is useful to render 3D content on top of another item.
276 This mode has no effect when the View3D is using a renderMode of Underlay or Overlay without any
277 post processing enabled.
278 \value SceneEnvironment.Color
279 The scene is cleared with the color specified by the clearColor property.
280 This mode has no effect when the View3D is using a renderMode of Underlay or Overlay without any
281 post processing enabled.
282 \value SceneEnvironment.SkyBox
283 The scene will not be cleared, but instead a SkyBox or Skydome will be rendered. The SkyBox
284 is defined using the HDRI map defined in the lightProbe property.
285 \value SceneEnvironment.SkyBoxCubeMap
286 The scene will not be cleared, but instead a SkyBox or Skydome will be rendered. The SkyBox
287 is defined using the cubemap defined in the skyBoxCubeMap property.
288 \value SceneEnvironment.SkyMaterial
289 The scene will not be cleared, but instead a SkyBox or Skydome will be rendered. The SkyBox
290 is sampled from the cubemap generated by the SkyMaterial defined in the skyMaterial property.
291 (Since Qt 6.12)
292
293 The default value is \c SceneEnvironment.Transparent
294
295 Take the following example. The Suzanne model is expected to be
296 pre-processed with the \c balsam tool and is sourced from the
297 \l{https://github.com/KhronosGroup/glTF-Sample-Models}{glTF Sample Models}
298 repository.
299
300 \qml
301 import QtQuick
302 import QtQuick3D
303 import QtQuick3D.Helpers
304
305 Item {
306 width: 1280
307 height: 720
308
309 View3D {
310 id: v3d
311 anchors.fill: parent
312
313 environment: ExtendedSceneEnvironment {
314 backgroundMode: SceneEnvironment.SkyBox
315 lightProbe: Texture { source: "00455_OpenfootageNET_field_low.hdr" }
316
317 glowEnabled: true
318 glowStrength: 1.25
319 glowBloom: 0.25
320 glowBlendMode: ExtendedSceneEnvironment.GlowBlendMode.Additive
321 }
322
323 DirectionalLight {
324 }
325
326 Suzanne {
327 scale: Qt.vector3d(50, 50, 50)
328 z: -500
329 }
330
331 PerspectiveCamera {
332 id: camera
333 }
334
335 WasdController {
336 controlledObject: camera
337 }
338 }
339 }
340 \endqml
341
342 Using image-based lighting in additional to the DirectionalLight and also
343 using the light probe texture as the skybox gives us the following:
344
345 \image sceneenvironment_background_ibl.jpg
346 {3D object with environment background}
347
348 What happens if there is no light probe?
349
350 \qml
351 backgroundMode: SceneEnvironment.Transparent
352 \endqml
353
354 Here the background is provided not by the View3D but by the QQuickWindow
355 or QQuickView hosting the 2D and 3D scene. Lighting is based on the
356 DirectionalLight only.
357
358 \image sceneenvironment_background_transparent.jpg
359 {3D object with transparent background}
360
361 Using a fixed clear color:
362
363 \qml
364 backgroundMode: SceneEnvironment.Color
365 clearColor: "green"
366 \endqml
367
368 \image sceneenvironment_background_color.jpg
369 {3D object with green background}
370
371 \sa lightProbe, QQuickWindow::setColor(), Window::color, View3D
372*/
373
374QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes QQuick3DSceneEnvironment::backgroundMode() const
375{
376 return m_backgroundMode;
377}
378
379/*!
380 \qmlproperty color QtQuick3D::SceneEnvironment::clearColor
381
382 This property defines which color will be used to clear the viewport when
383 using \c SceneEnvironment.Color for the backgroundMode property.
384
385 The default value is \c Qt::black
386
387 \sa backgroundMode
388*/
389
390QColor QQuick3DSceneEnvironment::clearColor() const
391{
392 return m_clearColor;
393}
394
395/*!
396 \qmlproperty real QtQuick3D::SceneEnvironment::aoStrength
397
398 This property defines the amount of ambient occulusion applied. Ambient
399 occulusion is a form of approximated global illumination which causes
400 non-directional self-shadowing where objects are close together.
401 A value of 100 causes full darkness shadows; lower values cause the
402 shadowing to appear lighter. A value of 0 disables ambient occlusion
403 entirely, improving performance at a cost to the visual realism of 3D
404 objects rendered in the scene.
405
406 All values other than 0 have the same impact to the performance.
407
408 The default value is 0.0. The maximum value is 100.0.
409
410 A value of 0 is equivalent to setting \l aoEnabled to false.
411
412 Pictured here with the default aoSoftness and aoDistance:
413
414 \table
415 \header
416 \li aoStrength of 0 (AO disabled)
417 \li aoStrength of 100
418 \li aoStrength of 50
419 \row
420 \li \image sceneenvironment_ao_off.jpg
421 {Scene with ambient occlusion strength of 0}
422 \li \image sceneenvironment_ao_full_strength.jpg
423 {Scene with ambient occlusion strength of 100}
424 \li \image sceneenvironment_ao_half_strength.jpg
425 {Scene with ambient occlusion strength of 50}
426 \endtable
427
428 \note Getting visually good-looking screen space ambient occlusion is
429 dependent on carefully tuning a number of related parameters, such as \l
430 aoStrength, \l aoSoftness, \l aoDistance, \l aoDither, \l aoBias, and \l
431 aoSampleRate.
432
433 \sa aoEnabled, aoDistance, aoSoftness
434*/
435float QQuick3DSceneEnvironment::aoStrength() const
436{
437 return m_aoStrength;
438}
439
440/*!
441 \qmlproperty real QtQuick3D::SceneEnvironment::aoDistance
442
443 This property defines roughly how far ambient occlusion shadows spread away
444 from objects. Greater distances cause increasing impact to performance.
445
446 The default value is 5.0.
447
448 Pictured here with the default aoSoftness and the maximum aoStrength:
449
450 \table
451 \header
452 \li aoDistance of 5
453 \li aoDistance of 1
454 \row
455 \li \image sceneenvironment_ao_distance_5.jpg
456 {Scene with ambient occlusion distance of 5}
457 \li \image sceneenvironment_ao_distance_1.jpg
458 {Scene with ambient occlusion distance of 1}
459 \endtable
460
461 \note Getting visually good-looking screen space ambient occlusion is
462 dependent on carefully tuning a number of related parameters, such as \l
463 aoStrength, \l aoSoftness, \l aoDistance, \l aoDither, \l aoBias, and \l
464 aoSampleRate.
465
466 \sa aoStrength, aoSoftness
467*/
468float QQuick3DSceneEnvironment::aoDistance() const
469{
470 return m_aoDistance;
471}
472
473/*!
474 \qmlproperty real QtQuick3D::SceneEnvironment::aoSoftness
475
476 This property defines how smooth the edges of the ambient occlusion shading
477 are.
478
479 The value must be between 0.0 and 50.0. The default value is 50.0.
480
481 Pictured here with the default aoDistance and the maximum aoStrength:
482
483 \table
484 \header
485 \li aoSoftness of 50
486 \li aoSoftness of 25
487 \row
488 \li \image sceneenvironment_ao_softness_default.jpg
489 {Scene with ambient occlusion softness of 50}
490 \li \image sceneenvironment_ao_softness_half.jpg
491 {Scene with ambient occlusion softness of 25}
492 \endtable
493
494 \note Getting visually good-looking screen space ambient occlusion is
495 dependent on carefully tuning a number of related parameters, such as \l
496 aoStrength, \l aoSoftness, \l aoDistance, \l aoDither, \l aoBias, and \l
497 aoSampleRate.
498
499 \sa aoStrength, aoDistance
500*/
501float QQuick3DSceneEnvironment::aoSoftness() const
502{
503 return m_aoSoftness;
504}
505
506/*!
507 \qmlproperty bool QtQuick3D::SceneEnvironment::aoDither
508
509 When this property is enabled it scatters the edges of the ambient
510 occlusion shadow bands to improve smoothness (at the risk of sometimes
511 producing obvious patterned artifacts).
512
513 \note Very large distances between the clipping planes of your camera may
514 cause problems with ambient occlusion. If you are seeing odd banding in
515 your ambient occlusion, try adjusting the \l {PerspectiveCamera::}{clipFar}
516 property of your camera to be closer to your content.
517
518 The default value is \c false.
519
520 \sa {QtQuick3D::PerspectiveCamera::clipFar}{PerspectiveCamera.clipFar},
521 {QtQuick3D::OrthographicCamera::clipFar}{OrthographicCamera.clipFar}
522*/
523bool QQuick3DSceneEnvironment::aoDither() const
524{
525 return m_aoDither;
526}
527
528/*!
529 \qmlproperty int QtQuick3D::SceneEnvironment::aoSampleRate
530
531 This property defines ambient occlusion quality (more shades of gray) at
532 the expense of performance.
533
534 The value must be 2, 3, or 4. The default value is 2.
535*/
536int QQuick3DSceneEnvironment::aoSampleRate() const
537{
538 return m_aoSampleRate;
539}
540
541/*!
542 \qmlproperty real QtQuick3D::SceneEnvironment::aoBias
543
544 This property defines a cutoff distance preventing objects from exhibiting
545 ambient occlusion at close distances. Higher values increase the distance
546 required between objects before ambient occlusion is seen.
547
548 \note If you see ambient occlusion shadowing on objects where there should
549 be no shadowing, increase the value slightly to clip away close results.
550
551 The default value is 0.0.
552*/
553float QQuick3DSceneEnvironment::aoBias() const
554{
555 return m_aoBias;
556}
557
558/*!
559 \qmlproperty QtQuick3D::Texture QtQuick3D::SceneEnvironment::lightProbe
560
561 This property defines an image used to light the scene, either instead of,
562 or in addition to standard lights.
563
564 The image is preferably a high-dynamic range image or a \l{Pre-generating
565 IBL cubemap}{pre-generated cubemap}. Pre-baking provides significant
566 performance improvements at run time, because no time is spent on filtering
567 and mipmap generation. If the source is a .hdr or other image, the GPU-based
568 pre-processing happens at run time after loading the image file, and that
569 can be potentially time consuming, in particular on embedded and mobile
570 hardware. Therefore, it is strongly recommended that applications
571 pre-process .hdr images at latest at build time, as described
572 \l{Pre-generating IBL cubemap}{here}.
573
574 \note Using a Texture with \l{Texture::sourceItem}{sourceItem} is not
575 supported in combination with this property. Pre-filtering of all mip
576 levels for dynamic Qt Quick content is typically not reasonable in practice
577 due to performance implications.
578
579 For more information on image-based lighting, see \l{Using Image-Based Lighting}.
580
581 \note The light probe texture, when the property is set to a valid Texture,
582 is used for lighting regardless of the \l backgroundMode. However, when \l
583 backgroundMode is set to \c{SceneEnvironment.SkyBox}, the texture is also
584 used to render the scene background as a skybox.
585
586 The examples below were generated with varying the \l backgroundMode in the
587 environment of the following scene. The scene has no DirectionLight,
588 PointLight, or SpotLight. All lighting is based on the panoramic HDRI
589 image.
590
591 \qml
592 import QtQuick
593 import QtQuick3D
594 import QtQuick3D.Helpers
595
596 Item {
597 width: 1280
598 height: 720
599
600 View3D {
601 id: v3d
602 anchors.fill: parent
603
604 environment: ExtendedSceneEnvironment {
605 backgroundMode: SceneEnvironment.SkyBox
606 lightProbe: Texture { source: "00455_OpenfootageNET_field_low.hdr" }
607
608 tonemapMode: SceneEnvironment.TonemapModeFilmic
609 sharpnessAmount: 0.4
610
611 glowEnabled: true
612 glowStrength: 1.25
613 glowBloom: 0.25
614 glowBlendMode: ExtendedSceneEnvironment.GlowBlendMode.Additive
615 }
616
617 Node {
618 scale: Qt.vector3d(100, 100, 100)
619
620 Sponza {
621 }
622
623 Suzanne {
624 y: 1
625 scale: Qt.vector3d(0.5, 0.5, 0.5)
626 eulerRotation.y: -90
627 }
628 }
629
630 PerspectiveCamera {
631 id: camera
632 y: 100
633 }
634
635 WasdController {
636 controlledObject: camera
637 }
638 }
639 }
640 \endqml
641
642 Results with the above environment:
643
644 \image sceneenvironment_lightprobe.jpg
645 {Scene with light probe}
646 \image sceneenvironment_lightprobe_2.jpg
647 {Scene with light probe from different perspective}
648
649 Switching the backgroundMode to \c{SceneEnvironment.Transparent} would give us:
650
651 \image sceneenvironment_lightprobe_transparent.jpg
652 {Scene with backgroundMode set to transparent}
653 \image sceneenvironment_lightprobe_transparent_2.jpg
654 {Scene with backgroundMode set to transparent from different
655 perspective}
656
657 Here the lighting of the 3D scene is the same as before, meaning the
658 materials use the light probe in the lighting calculations the same way as
659 before, but there is no skybox rendered. The background is white since that
660 is the default clear color of the QQuickWindow hosting the 2D and 3D scene.
661
662 It is valid to set the lightProbe property value back to the default null.
663 This unassigns the previously associated texture. For example, let's use
664 the Delete key to dynamically toggle between image-based lighting with a
665 skybox, and no image-based lighting with a fixed clear color for the
666 background:
667
668 \qml
669 environment: ExtendedSceneEnvironment {
670 id: env
671
672 backgroundMode: SceneEnvironment.SkyBox
673 lightProbe: iblTex
674
675 tonemapMode: SceneEnvironment.TonemapModeFilmic
676 sharpnessAmount: 0.4
677
678 glowEnabled: true
679 glowStrength: 1.25
680 glowBloom: 0.25
681 glowBlendMode: ExtendedSceneEnvironment.GlowBlendMode.Additive
682 }
683
684 Texture {
685 id: iblTex
686 source: "00455_OpenfootageNET_field_low.hdr"
687 }
688
689 focus: true
690 Keys.onDeletePressed: {
691 if (env.backgroundMode == SceneEnvironment.SkyBox) {
692 env.backgroundMode = SceneEnvironment.Color;
693 env.clearColor = "green";
694 env.lightProbe = null;
695 } else {
696 env.backgroundMode = SceneEnvironment.SkyBox;
697 env.lightProbe = iblTex;
698 }
699 }
700 \endqml
701
702 Pressing Delete gives the following result. Remember that the scene used
703 here has no lights so all 3D models appear completely black.
704
705 \image sceneenvironment_lightprobe_null.jpg
706 {3D objects without light probe on green background}
707 \image sceneenvironment_lightprobe_null_2.jpg
708 {Ground plane without light probe on green background}
709
710 While lightProbe is commonly used in combination with Texture instances
711 that source their data from an image file (typically .hdr or .ktx), it can
712 also makes sense to associate with a Texture that uses in-memory,
713 \l{Texture::textureData}{procedurally generated image data}. A prime
714 example of this is a Texture where the image data is generated by \l
715 ProceduralSkyTextureData from the QtQuick3D.Helpers module:
716
717 \qml
718 backgroundMode: SceneEnvironment.SkyBox
719 lightProbe: Texture {
720 textureData: ProceduralSkyTextureData {
721 }
722 }
723 \endqml
724
725 This gives us a procedurally generated HDR skybox texture that is now used
726 both as the skybox and for image-based lighting:
727
728 \image sceneenvironment_lightprobe_proceduralsky.jpg {Architectural scene lit by procedural sky visible in background}
729
730 \sa backgroundMode, {Using Image-Based Lighting}, {Pre-generating IBL
731 cubemap}, probeExposure, probeHorizon, probeOrientation, ProceduralSkyTextureData
732*/
733QQuick3DTexture *QQuick3DSceneEnvironment::lightProbe() const
734{
735 return m_lightProbe;
736}
737
738/*!
739 \qmlproperty QtQuick3D::SkyMaterial QtQuick3D::SceneEnvironment::skyMaterial
740
741 This property defines a procedural, GPU-driven sky model that is used for
742 IBL and as background to the scene.
743
744 \since 6.12
745 \sa backgroundMode, lightProbe
746*/
747QQuick3DSkyMaterial *QQuick3DSceneEnvironment::skyMaterial() const
748{
749 return m_skyMaterial;
750}
751
752/*!
753 \qmlproperty real QtQuick3D::SceneEnvironment::probeExposure
754
755 This property modifies the amount of light emitted by the light probe. Part
756 of the tonemapping is exposure mapping, and this property adjusts how
757 the light values in the light probes get tonemaped.
758
759 By default exposure is set to is 1.0
760
761 \note This property does not have an effect when \l tonemapMode is set to
762 \c SceneEnvironment.TonemapModeNone.
763
764 \sa lightProbe, probeHorizon, probeOrientation
765*/
766float QQuick3DSceneEnvironment::probeExposure() const
767{
768 return m_probeExposure;
769}
770
771/*!
772 \qmlproperty real QtQuick3D::SceneEnvironment::probeHorizon
773
774 This property when defined with increasing values adds darkness (black)
775 to the bottom half of the environment, forcing the lighting to come
776 predominantly from the top of the image (and removing specific reflections
777 from the lower half). This property is useful for accounting for a ground
778 plane that would have the effect of obscuring the reflection of the light
779 probe from the ground. This is necessary because light probe contributions
780 come directily from the image without consideration for the content of the
781 scene.
782
783 The expected value range for the probeHorizon property is between 0.0
784 and 1.0. Any value outside of this range will be clamped to the
785 expected range.
786
787 By default probeHorizon is set to 0.0 which means the whole light probe
788 is used without adjustment.
789
790 \note The probeHorizon property only affects materials lighting, and has
791 no effect on the rendering of the sky box.
792
793 \sa lightProbe, probeExposure, probeOrientation
794*/
795float QQuick3DSceneEnvironment::probeHorizon() const
796{
797 return m_probeHorizon;
798}
799
800/*!
801 \qmlproperty vector3d QtQuick3D::SceneEnvironment::probeOrientation
802
803 This property when defines the orientation of the light probe. Orientation
804 is defined in terms of euler angles in degrees over the x, y, and z axes.
805
806 \note This value augments how the lightProbe Texture is sampled in combination
807 with any texture rotations and offsets set on the lightProbe texture.
808
809 \sa lightProbe, probeHorizon, probeExposure
810*/
811QVector3D QQuick3DSceneEnvironment::probeOrientation() const
812{
813 return m_probeOrientation;
814}
815
816/*!
817 \qmlproperty bool QtQuick3D::SceneEnvironment::temporalAAEnabled
818
819 When this property is enabled temporal antialiasing will be used.
820
821 The camera is jiggled very slightly between frames, and the result of each
822 new frame is blended with the previous frame.
823
824 \note Temporal antialiasing doesn't have an effect when antialiasingMode is MSAA.
825 \note When using ProgressiveAA, temporal AA is applied during scene animation.
826 Once the scene becomes static, ProgressiveAA takes over — but only when
827 temporalAAMode is SceneEnvironment.TAADefault.
828 In other words: ProgressiveAA has no effect when temporalAAMode is set to
829 SceneEnvironment.TAAMotionVector.
830
831 \b Pros: Due to the jiggling camera it finds real details that were otherwise
832 lost; low impact on performance.
833
834 \b Cons: Fast-moving objects cause one-frame ghosting.
835
836 \default false
837
838 \note Temporal antialiasing is not currently supported with multiview
839 rendering, and should not be used in VR/AR applications.
840*/
841bool QQuick3DSceneEnvironment::temporalAAEnabled() const
842{
843 return m_temporalAAEnabled;
844}
845
846/*!
847 \qmlproperty real QtQuick3D::SceneEnvironment::temporalAAStrength
848 \since 5.15
849
850 This property modifies the amount of temporal movement (antialiasing).
851 This has an effect only when temporalAAEnabled property is true.
852
853 \default 0.3
854
855 \sa temporalAAEnabled
856*/
857float QQuick3DSceneEnvironment::temporalAAStrength() const
858{
859 return m_temporalAAStrength;
860}
861
862/*!
863 \qmlproperty enumeration QtQuick3D::SceneEnvironment::temporalAAMode
864 \since 6.11
865
866 Controls the temporal anti-aliasing mode. Temporal AA reduces flickering and
867 aliasing by blending information across multiple frames.
868
869 \value SceneEnvironment.TAADefault
870 Blends current and previous frames for basic temporal filtering.
871
872 \value SceneEnvironment.TAAMotionVector
873 Uses motion vectors to track pixel movement between frames, providing
874 superior quality for animated scenes.
875
876 The default is \c SceneEnvironment.TAADefault.
877
878 \note Temporal AA may cause ghosting artifacts with fast-moving objects or
879 rapid camera movements.
880
881 \note Works best with constant frame rates. Frame rate variations reduce
882 effectiveness.
883*/
884QQuick3DSceneEnvironment::QQuick3DEnvironmentTemporalAAMode QQuick3DSceneEnvironment::temporalAAMode() const
885{
886 return m_temporalAAMode;
887}
888
889/*!
890 \qmlproperty bool QtQuick3D::SceneEnvironment::specularAAEnabled
891 \since 6.4
892
893 When this property is enabled, specular aliasing will be mitigated.
894 Specular aliasing is often visible in form of bright dots, possibly
895 flickering when moving the camera around.
896
897 The default value is false.
898
899 \table
900 \header
901 \li Specular AA disabled
902 \li Specular AA enabled
903 \row
904 \li \image specular_aa_off.jpg {Architectural scene showing
905 specular highlights without antialiasing}
906 \li \image specular_aa_on.jpg {Architectural scene showing
907 smoothed specular highlights with antialiasing}
908 \endtable
909*/
910bool QQuick3DSceneEnvironment::specularAAEnabled() const
911{
912 return m_specularAAEnabled;
913}
914
915/*!
916 \qmlproperty bool QtQuick3D::SceneEnvironment::depthTestEnabled
917
918 The default value is \c true. By default the renderer classifies the objects
919 in the scene either as \c opaque or as \c semi-transparent. The objects
920 (sub-meshes with the associated material) in the \c opaque list are rendered
921 first, with depth testing and depth write enabled, providing optimal
922 Z-culling for typical 3D objects that have no semi-transparent regions. The
923 objects in the \c semi-transparent list are rendered with depth write
924 disabled, although still with depth testing enabled (to test against the
925 opaque objects), in back to front order (sorted based on their center point's
926 distance from the camera). This allows correct blending ("see through") for
927 3D objects that involve semi-transparent regions on their surface, either
928 due to the \l{Node::opacity}{node opacity} or due to some color or texture
929 map in the material.
930
931 When this property is set to \c {false}, the Z-buffer is not written and
932 tested against, the depth test is skipped, and all objects, including fully
933 opaque ones, are rendered in one go, sorted back to front.
934
935 Setting this property to \c false should be rarely needed. It can be useful
936 in scenes where it is known that there is little benefit in the two-round
937 approach because either there are very few opaque objects, or they are
938 transformed in a way that a single back to front sorted pass performs
939 better.
940
941 \note Setting this property to \c false may cause rendering errors in
942 certain scenes. In addition, some features, such as shadows, ambient
943 occlusion, \c SCREEN_TEXTURE and \c DEPTH_TEXTURE in custom materials and
944 effects, will not behave correctly without enabling depth buffer usage.
945
946 \note This flag has no control over the presence of a depth or
947 depth-stencil buffer. Such buffers may still be allocated even when this is
948 set to \c false.
949*/
950bool QQuick3DSceneEnvironment::depthTestEnabled() const
951{
952 return m_depthTestEnabled;
953}
954/*!
955 \qmlproperty bool QtQuick3D::SceneEnvironment::depthPrePassEnabled
956
957 When enabled, the renderer performs a Z-prepass for opaque objects, meaning
958 it renders them with a simple shader and color write disabled in order to
959 get the depth buffer pre-filled before issuing draw calls for the main
960 rendering passes.
961
962 This can improve performance depending on the scene contents. It is
963 typically scenes with lots of overlapping objects and expensive fragment
964 shading that benefit from this. At the same time, it is worth noting that
965 the renderer performs front to back sorting for opaque objects, which in
966 itself helps reducing unnecessary fragment shading, and therefore the
967 Z-prepass does not always bring significant improvements.
968
969 On GPUs that use a tiled rendering architecture, which is common in mobile
970 and embedded systems, it is recommended to set this to \c false.
971
972 The default value is \c false.
973
974 \note This property has no effect when depth testing is disabled.
975*/
976bool QQuick3DSceneEnvironment::depthPrePassEnabled() const
977{
978 return m_depthPrePassEnabled;
979}
980
981/*!
982 \qmlproperty List<QtQuick3D::Effect> QtQuick3D::SceneEnvironment::effects
983 \since 5.15
984
985 This property contains a list of post-processing effects that will be
986 applied to the entire viewport. The result of each effect is fed to the
987 next so the order is significant.
988
989 \note For technical reasons, adding the same \l{QtQuick3D::Effect}{Effect}
990 node several times to the list is unsupported and will give unexpected results.
991*/
992QQmlListProperty<QQuick3DEffect> QQuick3DSceneEnvironment::effects()
993{
994 return QQmlListProperty<QQuick3DEffect>(this,
995 nullptr,
996 QQuick3DSceneEnvironment::qmlAppendEffect,
997 QQuick3DSceneEnvironment::qmlEffectsCount,
998 QQuick3DSceneEnvironment::qmlEffectAt,
999 QQuick3DSceneEnvironment::qmlClearEffects);
1000}
1001
1002/*!
1003 \qmlproperty enumeration QtQuick3D::SceneEnvironment::tonemapMode
1004 \since 6.0
1005
1006 This property defines how colors are tonemapped before rendering. All
1007 rendering in Qt Quick 3D is performed in linear color space and can in
1008 many cases lead to generating color values that are not displayable. The
1009 tonemapMode determines the technique that is used to remap colors into a
1010 displayable range.
1011
1012 The default value is \c SceneEnvironment.TonemapModeLinear
1013
1014 \value SceneEnvironment.TonemapModeNone
1015 All Tonemapping is bypassed. This mode is useful when performing post
1016 processing effects.
1017 \value SceneEnvironment.TonemapModeLinear
1018 Linear tonemapping is applied. Colors are gamma corrected and returned
1019 in sRGB color space.
1020 \value SceneEnvironment.TonemapModeAces
1021 Academy Color Encoding System tonemapping is applied.
1022 \value SceneEnvironment.TonemapModeHejlDawson
1023 Hejl-Dawson tonemapping is applied.
1024 \value SceneEnvironment.TonemapModeFilmic
1025 Filmic tonemapping is applied.
1026
1027 See \l{ExtendedSceneEnvironment::tonemapMode}{ExtendedSceneEnvironment} for
1028 an example of these different modes.
1029
1030 \note When using post-processing effects, most effects expect untonemapped
1031 linear color data. With application-provided, custom effects implemented
1032 via the \l Effect type, it is important to know that starting with Qt 6.5
1033 effects can safely assume that they work with linear color data, and
1034 tonemapping is performed automatically on the output of the last effect in
1035 the chain. If there is a need to customize tonemapping completely, consider
1036 setting the \c SceneEnvironment.TonemapModeNone value to disable the
1037 built-in tonemapper, and perform the appropriate adjustments on the color
1038 value in the last effect in the chain instead. This does not apply to the
1039 built-in effects of \l ExtendedSceneEnvironment, because those
1040 automatically take care of proper tonemapping regardless of what
1041 combination of built-in effects are enabled in the environment.
1042*/
1043QQuick3DSceneEnvironment::QQuick3DEnvironmentTonemapModes QQuick3DSceneEnvironment::tonemapMode() const
1044{
1045 return m_tonemapMode;
1046}
1047
1048/*!
1049 \qmlproperty real QtQuick3D::SceneEnvironment::skyboxBlurAmount
1050 \since 6.4
1051
1052 This property determines how much much the skybox should be blurred when
1053 using \c SceneEnvironment.SkyBox for the \l backgroundMode property. The
1054 default value is \c 0.0 which means there is no blurring.
1055
1056 Acceptable values range between 0.0 and 1.0, all other values will be clamped
1057 to this range.
1058
1059*/
1060
1061float QQuick3DSceneEnvironment::skyboxBlurAmount() const
1062{
1063 return m_skyboxBlurAmount;
1064}
1065
1066/*!
1067 \qmlproperty QtQuick3D::DebugSettings QtQuick3D::SceneEnvironment::debugSettings
1068 \since 6.5
1069
1070 This property specifies a \c DebugSettings object which is used to
1071 configure the debugging tools of the renderer. During construction
1072 the SceneEnvironment automatically creates a DebugSettings object
1073 associated with itself, and therefore setting a custom DebugSettings
1074 is usually not required.
1075
1076 An example of rendering the scene with wireframe mode enabled:
1077 \image debugsettings_wireframe.jpg {Sponza scene in wireframe mode}
1078
1079 Visualizing the normal vectors of the meshes:
1080 \image debugsettings_normals.jpg {Sponza scene showing surface normals}
1081
1082 Visualizing the specular lighting contribution:
1083 \image debugsettings_specular.jpg {Sponza scene showing specular highlights}
1084
1085 \sa DebugSettings
1086*/
1087
1088QQuick3DDebugSettings *QQuick3DSceneEnvironment::debugSettings() const
1089{
1090 return m_debugSettings;
1091}
1092
1093/*!
1094 \qmlproperty rect QtQuick3D::SceneEnvironment::scissorRect
1095 \since 6.5
1096
1097 This property defines a scissor rectangle in view coordinates, with the
1098 top-left corner at [0, 0]
1099*/
1100
1101QRect QQuick3DSceneEnvironment::scissorRect() const
1102{
1103 return m_scissorRect;
1104}
1105
1106void QQuick3DSceneEnvironment::setAntialiasingMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentAAModeValues antialiasingMode)
1107{
1108 if (m_antialiasingMode == antialiasingMode)
1109 return;
1110
1111 m_antialiasingMode = antialiasingMode;
1112 emit antialiasingModeChanged();
1113 update();
1114}
1115
1116void QQuick3DSceneEnvironment::setAntialiasingQuality(QQuick3DSceneEnvironment::QQuick3DEnvironmentAAQualityValues antialiasingQuality)
1117{
1118 if (m_antialiasingQuality == antialiasingQuality)
1119 return;
1120
1121 m_antialiasingQuality = antialiasingQuality;
1122 emit antialiasingQualityChanged();
1123 update();
1124}
1125
1126void QQuick3DSceneEnvironment::setBackgroundMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes backgroundMode)
1127{
1128 if (m_backgroundMode == backgroundMode)
1129 return;
1130
1131 m_backgroundMode = backgroundMode;
1132 emit backgroundModeChanged();
1133 update();
1134}
1135
1136void QQuick3DSceneEnvironment::setClearColor(const QColor &clearColor)
1137{
1138 if (m_clearColor == clearColor)
1139 return;
1140
1141 m_clearColor = clearColor;
1142 emit clearColorChanged();
1143 update();
1144}
1145
1146void QQuick3DSceneEnvironment::setAoStrength(float aoStrength)
1147{
1148 if (qFuzzyCompare(m_aoStrength, aoStrength))
1149 return;
1150
1151 m_aoStrength = aoStrength;
1152
1153 const bool aoEnabled = !(qFuzzyIsNull(m_aoStrength) || qFuzzyIsNull(m_aoDistance));
1154 setAoEnabled(aoEnabled);
1155
1156 emit aoStrengthChanged();
1157 update();
1158}
1159
1160void QQuick3DSceneEnvironment::setAoDistance(float aoDistance)
1161{
1162 if (qFuzzyCompare(m_aoDistance, aoDistance))
1163 return;
1164
1165 m_aoDistance = aoDistance;
1166
1167 const bool aoEnabled = !(qFuzzyIsNull(m_aoStrength) || qFuzzyIsNull(m_aoDistance));
1168 setAoEnabled(aoEnabled);
1169
1170 emit aoDistanceChanged();
1171 update();
1172}
1173
1174void QQuick3DSceneEnvironment::setAoSoftness(float aoSoftness)
1175{
1176 if (qFuzzyCompare(m_aoSoftness, aoSoftness))
1177 return;
1178
1179 m_aoSoftness = aoSoftness;
1180 emit aoSoftnessChanged();
1181 update();
1182}
1183
1184void QQuick3DSceneEnvironment::setAoDither(bool aoDither)
1185{
1186 if (m_aoDither == aoDither)
1187 return;
1188
1189 m_aoDither = aoDither;
1190 emit aoDitherChanged();
1191 update();
1192}
1193
1194void QQuick3DSceneEnvironment::setAoSampleRate(int aoSampleRate)
1195{
1196 if (m_aoSampleRate == aoSampleRate)
1197 return;
1198
1199 m_aoSampleRate = aoSampleRate;
1200 emit aoSampleRateChanged();
1201 update();
1202}
1203
1204void QQuick3DSceneEnvironment::setAoBias(float aoBias)
1205{
1206 if (qFuzzyCompare(m_aoBias, aoBias))
1207 return;
1208
1209 m_aoBias = aoBias;
1210 emit aoBiasChanged();
1211 update();
1212}
1213
1214void QQuick3DSceneEnvironment::setLightProbe(QQuick3DTexture *lightProbe)
1215{
1216 if (m_lightProbe == lightProbe)
1217 return;
1218
1219 QQuick3DObjectPrivate::attachWatcher(this, &QQuick3DSceneEnvironment::setLightProbe, lightProbe, m_lightProbe);
1220
1221 m_lightProbe = lightProbe;
1222 emit lightProbeChanged();
1223 update();
1224}
1225
1226void QQuick3DSceneEnvironment::setSkyMaterial(QQuick3DSkyMaterial *skyMaterial)
1227{
1228 if (m_skyMaterial == skyMaterial)
1229 return;
1230
1231 QQuick3DObjectPrivate::attachWatcher(this, &QQuick3DSceneEnvironment::setSkyMaterial, skyMaterial, m_skyMaterial);
1232
1233 m_skyMaterial = skyMaterial;
1234 emit skyMaterialChanged();
1235 update();
1236}
1237
1238void QQuick3DSceneEnvironment::setProbeExposure(float probeExposure)
1239{
1240 if (qFuzzyCompare(m_probeExposure, probeExposure))
1241 return;
1242
1243 m_probeExposure = probeExposure;
1244 emit probeExposureChanged();
1245 update();
1246}
1247
1248void QQuick3DSceneEnvironment::setProbeHorizon(float probeHorizon)
1249{
1250 // clamp value to expected range
1251 probeHorizon = qBound(0.0f, probeHorizon, 1.0f);
1252
1253 if (qFuzzyCompare(m_probeHorizon, probeHorizon))
1254 return;
1255
1256 m_probeHorizon = probeHorizon;
1257 emit probeHorizonChanged();
1258 update();
1259}
1260
1261void QQuick3DSceneEnvironment::setProbeOrientation(const QVector3D &orientation)
1262{
1263 if (qFuzzyCompare(m_probeOrientation, orientation))
1264 return;
1265
1266 m_probeOrientation = orientation;
1267 emit probeOrientationChanged();
1268 update();
1269}
1270
1271void QQuick3DSceneEnvironment::setDepthTestEnabled(bool depthTestEnabled)
1272{
1273 if (m_depthTestEnabled == depthTestEnabled)
1274 return;
1275
1276 m_depthTestEnabled = depthTestEnabled;
1277 emit depthTestEnabledChanged();
1278 update();
1279}
1280
1281void QQuick3DSceneEnvironment::setDepthPrePassEnabled(bool depthPrePassEnabled)
1282{
1283 if (m_depthPrePassEnabled == depthPrePassEnabled)
1284 return;
1285
1286 m_depthPrePassEnabled = depthPrePassEnabled;
1287 emit depthPrePassEnabledChanged();
1288 update();
1289}
1290
1291void QQuick3DSceneEnvironment::setTonemapMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentTonemapModes tonemapMode)
1292{
1293 if (m_tonemapMode == tonemapMode)
1294 return;
1295
1296 m_tonemapMode = tonemapMode;
1297 emit tonemapModeChanged();
1298 update();
1299}
1300
1301bool QQuick3DSceneEnvironment::useBuiltinTonemapper() const
1302{
1303 return true;
1304}
1305
1306QSSGRenderGraphObject *QQuick3DSceneEnvironment::updateSpatialNode(QSSGRenderGraphObject *node)
1307{
1308 // Don't do anything, these properties get set by the scene renderer
1309 return node;
1310}
1311
1312void QQuick3DSceneEnvironment::itemChange(QQuick3DObject::ItemChange change, const QQuick3DObject::ItemChangeData &value)
1313{
1314 if (change == QQuick3DObject::ItemSceneChange)
1315 updateSceneManager(value.sceneManager);
1316}
1317
1318const QVector<QQuick3DEffect *> &QQuick3DSceneEnvironment::effectList() const
1319{
1320 return m_effects;
1321}
1322
1323void QQuick3DSceneEnvironment::updateSceneManager(QQuick3DSceneManager *manager)
1324{
1325 if (manager) {
1326 QQuick3DObjectPrivate::refSceneManager(m_lightProbe, *manager);
1327 QQuick3DObjectPrivate::refSceneManager(m_skyMaterial, *manager);
1328 QQuick3DObjectPrivate::refSceneManager(m_skyBoxCubeMap, *manager);
1329 } else {
1330 QQuick3DObjectPrivate::derefSceneManager(m_lightProbe);
1331 QQuick3DObjectPrivate::derefSceneManager(m_skyMaterial);
1332 QQuick3DObjectPrivate::derefSceneManager(m_skyBoxCubeMap);
1333 }
1334}
1335
1336void QQuick3DSceneEnvironment::setTemporalAAMode(const QQuick3DEnvironmentTemporalAAMode &newTemporalAAMode)
1337{
1338 if (m_temporalAAMode == newTemporalAAMode)
1339 return;
1340 m_temporalAAMode = newTemporalAAMode;
1341 emit temporalAAModeChanged();
1342 update();
1343}
1344
1345void QQuick3DSceneEnvironment::setTemporalAAEnabled(bool temporalAAEnabled)
1346{
1347 if (m_temporalAAEnabled == temporalAAEnabled)
1348 return;
1349
1350 m_temporalAAEnabled = temporalAAEnabled;
1351 emit temporalAAEnabledChanged();
1352 update();
1353}
1354
1355void QQuick3DSceneEnvironment::setTemporalAAStrength(float strength)
1356{
1357 if (qFuzzyCompare(m_temporalAAStrength, strength))
1358 return;
1359
1360 m_temporalAAStrength = strength;
1361 emit temporalAAStrengthChanged();
1362 update();
1363}
1364
1365void QQuick3DSceneEnvironment::setSpecularAAEnabled(bool enabled)
1366{
1367 if (m_specularAAEnabled == enabled)
1368 return;
1369
1370 m_specularAAEnabled = enabled;
1371 emit specularAAEnabledChanged();
1372 update();
1373}
1374
1375void QQuick3DSceneEnvironment::qmlAppendEffect(QQmlListProperty<QQuick3DEffect> *list, QQuick3DEffect *effect)
1376{
1377 if (effect == nullptr)
1378 return;
1379 QQuick3DSceneEnvironment *self = static_cast<QQuick3DSceneEnvironment *>(list->object);
1380 self->m_effects.push_back(effect);
1381
1382 if (effect->parentItem() == nullptr)
1383 effect->setParentItem(self);
1384
1385 for (QQuick3DEffect *e : std::as_const(self->m_effects))
1386 e->effectChainDirty();
1387
1388 self->update();
1389}
1390
1391QQuick3DEffect *QQuick3DSceneEnvironment::qmlEffectAt(QQmlListProperty<QQuick3DEffect> *list, qsizetype index)
1392{
1393 QQuick3DSceneEnvironment *self = static_cast<QQuick3DSceneEnvironment *>(list->object);
1394 return self->m_effects.at(index);
1395}
1396
1397qsizetype QQuick3DSceneEnvironment::qmlEffectsCount(QQmlListProperty<QQuick3DEffect> *list)
1398{
1399 QQuick3DSceneEnvironment *self = static_cast<QQuick3DSceneEnvironment *>(list->object);
1400 return self->m_effects.size();
1401}
1402
1403void QQuick3DSceneEnvironment::qmlClearEffects(QQmlListProperty<QQuick3DEffect> *list)
1404{
1405 QQuick3DSceneEnvironment *self = static_cast<QQuick3DSceneEnvironment *>(list->object);
1406 self->m_effects.clear();
1407 self->update();
1408}
1409
1410void QQuick3DSceneEnvironment::setSkyboxBlurAmount(float newSkyboxBlurAmount)
1411{
1412 newSkyboxBlurAmount = qBound(0.0f, newSkyboxBlurAmount, 1.0f);
1413
1414 if (qFuzzyCompare(m_skyboxBlurAmount, newSkyboxBlurAmount))
1415 return;
1416
1417 m_skyboxBlurAmount = newSkyboxBlurAmount;
1418 emit skyboxBlurAmountChanged();
1419 update();
1420}
1421
1422/*!
1423 \qmlproperty Lightmapper QtQuick3D::SceneEnvironment::lightmapper
1424
1425 When this property is set to a valid Lightmapper object, the settings
1426 specified by the object will be taken into account when baking lightmaps.
1427
1428 The default value is null, which means using default values for all the
1429 baking-related settings.
1430
1431 For more information on how to bake lightmaps, see the \l Lightmapper
1432 documentation.
1433
1434 When lightmaps are not relevant to an application and baked lighting is
1435 never generated, the property and the associated object serve no purpose in
1436 practice.
1437
1438 \sa Model::usedInBakedLighting, Model::bakedLightmap, Light::bakeMode, Lightmapper
1439 */
1440
1441QQuick3DLightmapper *QQuick3DSceneEnvironment::lightmapper() const
1442{
1443 return m_lightmapper;
1444}
1445
1446void QQuick3DSceneEnvironment::setLightmapper(QQuick3DLightmapper *lightmapper)
1447{
1448 if (m_lightmapper == lightmapper)
1449 return;
1450
1451 if (m_lightmapper)
1452 m_lightmapper->disconnect(m_lightmapperSignalConnection);
1453
1454 m_lightmapper = lightmapper;
1455
1456 m_dirtyFlags |= InternalDirtyFlag::LightmapperDirty;
1457
1458 m_lightmapperSignalConnection = QObject::connect(m_lightmapper, &QQuick3DLightmapper::changed, this, [this] {
1459 m_dirtyFlags |= InternalDirtyFlag::LightmapperDirty;
1460 update();
1461 });
1462
1463 QObject::connect(m_lightmapper, &QObject::destroyed, this,
1464 [this](QObject *obj)
1465 {
1466 if (m_lightmapper == obj) {
1467 m_dirtyFlags |= InternalDirtyFlag::LightmapperDirty;
1468 m_lightmapper = nullptr;
1469 update();
1470 }
1471 });
1472
1473 emit lightmapperChanged();
1474 update();
1475}
1476
1477/*!
1478 \qmlproperty QtQuick3D::CubeMapTexture QtQuick3D::SceneEnvironment::skyBoxCubeMap
1479
1480 This property defines a cubemap to be used as a skybox when the background mode is \c SkyBoxCubeMap.
1481
1482 \since 6.4
1483*/
1484QQuick3DCubeMapTexture *QQuick3DSceneEnvironment::skyBoxCubeMap() const
1485{
1486 return m_skyBoxCubeMap;
1487}
1488
1489void QQuick3DSceneEnvironment::setSkyBoxCubeMap(QQuick3DCubeMapTexture *newSkyBoxCubeMap)
1490{
1491 if (m_skyBoxCubeMap == newSkyBoxCubeMap)
1492 return;
1493
1494 QQuick3DObjectPrivate::attachWatcher(this, &QQuick3DSceneEnvironment::setSkyBoxCubeMap, newSkyBoxCubeMap, m_skyBoxCubeMap);
1495
1496 m_skyBoxCubeMap = newSkyBoxCubeMap;
1497 emit skyBoxCubeMapChanged();
1498}
1499
1500void QQuick3DSceneEnvironment::setDebugSettings(QQuick3DDebugSettings *newDebugSettings)
1501{
1502 if (m_debugSettings == newDebugSettings)
1503 return;
1504
1505 if (m_debugSettings)
1506 m_debugSettings->disconnect(m_debugSettingsSignalConnection);
1507
1508 m_debugSettings = newDebugSettings;
1509
1510 m_debugSettingsSignalConnection = QObject::connect(m_debugSettings, &QQuick3DDebugSettings::changed, this,
1511 [this] { update(); });
1512 QObject::connect(m_debugSettings, &QObject::destroyed, this,
1513 [this](QObject *obj) {
1514 if (m_debugSettings == obj) {
1515 m_debugSettings = nullptr;
1516 update();
1517 }
1518 });
1519
1520 emit debugSettingsChanged();
1521 update();
1522}
1523
1524void QQuick3DSceneEnvironment::setScissorRect(QRect rect)
1525{
1526 if (m_scissorRect == rect)
1527 return;
1528
1529 m_scissorRect = rect;
1530 emit scissorRectChanged();
1531 update();
1532}
1533
1534bool QQuick3DSceneEnvironment::gridEnabled() const
1535{
1536 return m_gridEnabled;
1537}
1538
1539void QQuick3DSceneEnvironment::setGridEnabled(bool newGridEnabled)
1540{
1541 if (m_gridEnabled == newGridEnabled)
1542 return;
1543 m_gridEnabled = newGridEnabled;
1544 update();
1545}
1546
1547float QQuick3DSceneEnvironment::gridScale() const
1548{
1549 return m_gridScale;
1550}
1551
1552void QQuick3DSceneEnvironment::setGridScale(float newGridScale)
1553{
1554 if (qFuzzyCompare(m_gridScale, newGridScale))
1555 return;
1556 m_gridScale = newGridScale;
1557 update();
1558}
1559
1560uint QQuick3DSceneEnvironment::gridFlags() const
1561{
1562 return m_gridFlags;
1563}
1564
1565void QQuick3DSceneEnvironment::setGridFlags(uint newGridFlags)
1566{
1567 if (m_gridFlags == newGridFlags)
1568 return;
1569 m_gridFlags = newGridFlags;
1570 update();
1571}
1572
1573/*!
1574 \qmlproperty bool SceneEnvironment::aoEnabled
1575 \since 6.5
1576
1577 Enable or disable ambient occlusion.
1578
1579 The default value is \c false, which means ambient occlusion is disabled.
1580
1581 \note If \l aoStrength or \ aoDistance is 0, then setting this property to
1582 \c true will also set those values appropriately to make the ambient
1583 occlusion effective.
1584
1585 \note Getting visually good-looking screen space ambient occlusion is
1586 dependent on carefully tuning a number of related parameters, such as \l
1587 aoStrength, \l aoSoftness, \l aoDistance, \l aoDither, \l aoBias, and \l
1588 aoSampleRate.
1589
1590 \sa aoStrength, aoDistance
1591*/
1592
1593bool QQuick3DSceneEnvironment::aoEnabled() const
1594{
1595 return m_aoEnabled;
1596}
1597
1598void QQuick3DSceneEnvironment::setAoEnabled(bool newAoEnabled)
1599{
1600 if (m_aoEnabled == newAoEnabled)
1601 return;
1602
1603 m_aoEnabled = newAoEnabled;
1604
1605 if (m_aoEnabled) {
1606 if (qFuzzyIsNull(m_aoStrength))
1607 setAoStrength(100.0f);
1608 if (qFuzzyIsNull(m_aoDistance))
1609 setAoDistance(defaultAoDistance());
1610 }
1611
1612 emit aoEnabledChanged();
1613 update();
1614}
1615
1616/*!
1617 \qmlproperty QtQuick3D::Fog QtQuick3D::SceneEnvironment::fog
1618 \since 6.5
1619
1620 When this property is set to a valid \l {QtQuick3D::Fog}{Fog} object, it is
1621 used to configure the renderer's built-in fog support.
1622
1623 The default value is null, which means no fog. This is equivalent to
1624 setting a Fog object with \l{Fog::enabled}{enabled} set to false.
1625
1626 \image fog.jpg {Scene with fog effect}
1627
1628 \sa {QtQuick3D::Fog}{Fog}
1629 */
1630
1631QQuick3DFog *QQuick3DSceneEnvironment::fog() const
1632{
1633 return m_fog;
1634}
1635
1636void QQuick3DSceneEnvironment::setFog(QQuick3DFog *fog)
1637{
1638 if (m_fog == fog)
1639 return;
1640
1641 if (m_fog)
1642 m_fog->disconnect(m_fogSignalConnection);
1643
1644 m_fog = fog;
1645
1646 m_fogSignalConnection = QObject::connect(m_fog, &QQuick3DFog::changed, this, [this] { update(); });
1647
1648 QObject::connect(m_fog, &QObject::destroyed, this,
1649 [this](QObject *obj)
1650 {
1651 if (m_fog == obj) {
1652 m_fog = nullptr;
1653 update();
1654 }
1655 });
1656
1657 emit fogChanged();
1658 update();
1659}
1660
1661/*!
1662 \qmlproperty enumeration QtQuick3D::SceneEnvironment::oitMethod
1663 \since 6.9
1664
1665 This property holds the Order Independent Transparency method. Setting this
1666 property to a valid OIT method causes the renderer to render transparent pixels
1667 in the correct depth order.
1668
1669 Possible values are:
1670 \value SceneEnvironment.OITNone OIT is turned off.
1671 \value SceneEnvironment.OITWeightedBlended Approximates order independent transparency.
1672 \value SceneEnvironment.OITLinkedList Accurate order independent transparency.
1673
1674 The default is \c None and order independent transparency is turned off.
1675
1676 \b Weighted Blended
1677
1678 This is an approximation of order independent transparency. The transparent fragments are
1679 rendered to an offscreen buffer while weighting is applied to each fragment based on its
1680 distance to the camera. This buffer is then blended to the backbuffer after de-weighting
1681 each pixel. This method doesn't follow the source-over composition rule for all fragments
1682 and the result is different from the correct result, however this method works also on
1683 older hardware and is faster than the other more rigorous methods.
1684
1685 \b Linked List
1686
1687 This is an accurate order independent transparency. The transparent fragments are
1688 rendered to a linked list in the render pass and sorted by their depth and blended
1689 in the composition pass.
1690 \since 6.11
1691
1692 \note OIT might not work with MSAA on devices with GLES 3.1 or lower. It is recommended
1693 not to use MSAA if oit is wanted on such devices.
1694
1695 \note Order independent transparenty is only applicaple to source-over blend mode.
1696 If scene contains objects with other blending modes, OIT is disabled.
1697*/
1698
1699QQuick3DSceneEnvironment::QQuick3DEnvironmentOITMethod QQuick3DSceneEnvironment::oitMethod() const
1700{
1701 return m_oitMethod;
1702}
1703
1704void QQuick3DSceneEnvironment::setOitMethod(QQuick3DSceneEnvironment::QQuick3DEnvironmentOITMethod method)
1705{
1706 if (m_oitMethod == method)
1707 return;
1708 m_oitMethod = method;
1709 emit oitMethodChanged();
1710 update();
1711}
1712
1713QT_END_NAMESPACE
Combined button and popup list for selecting options.