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