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