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.
834
835 \default 0.3
836
837 \sa temporalAAEnabled
838*/
839float QQuick3DSceneEnvironment::temporalAAStrength() const
840{
841 return m_temporalAAStrength;
842}
843
844/*!
845 \qmlproperty enumeration QtQuick3D::SceneEnvironment::temporalAAMode
846 \since 6.11
847
848 Controls the temporal anti-aliasing mode. Temporal AA reduces flickering and
849 aliasing by blending information across multiple frames.
850
851 \value SceneEnvironment.TAADefault
852 Blends current and previous frames for basic temporal filtering.
853
854 \value SceneEnvironment.TAAMotionVector
855 Uses motion vectors to track pixel movement between frames, providing
856 superior quality for animated scenes.
857
858 The default is \c SceneEnvironment.TAADefault.
859
860 \note Temporal AA may cause ghosting artifacts with fast-moving objects or
861 rapid camera movements.
862
863 \note Works best with constant frame rates. Frame rate variations reduce
864 effectiveness.
865*/
866QQuick3DSceneEnvironment::QQuick3DEnvironmentTemporalAAMode QQuick3DSceneEnvironment::temporalAAMode() const
867{
868 return m_temporalAAMode;
869}
870
871/*!
872 \qmlproperty bool QtQuick3D::SceneEnvironment::specularAAEnabled
873 \since 6.4
874
875 When this property is enabled, specular aliasing will be mitigated.
876 Specular aliasing is often visible in form of bright dots, possibly
877 flickering when moving the camera around.
878
879 The default value is false.
880
881 \table
882 \header
883 \li Specular AA disabled
884 \li Specular AA enabled
885 \row
886 \li \image specular_aa_off.jpg {Architectural scene showing
887 specular highlights without antialiasing}
888 \li \image specular_aa_on.jpg {Architectural scene showing
889 smoothed specular highlights with antialiasing}
890 \endtable
891*/
892bool QQuick3DSceneEnvironment::specularAAEnabled() const
893{
894 return m_specularAAEnabled;
895}
896
897/*!
898 \qmlproperty bool QtQuick3D::SceneEnvironment::depthTestEnabled
899
900 The default value is \c true. By default the renderer classifies the objects
901 in the scene either as \c opaque or as \c semi-transparent. The objects
902 (sub-meshes with the associated material) in the \c opaque list are rendered
903 first, with depth testing and depth write enabled, providing optimal
904 Z-culling for typical 3D objects that have no semi-transparent regions. The
905 objects in the \c semi-transparent list are rendered with depth write
906 disabled, although still with depth testing enabled (to test against the
907 opaque objects), in back to front order (sorted based on their center point's
908 distance from the camera). This allows correct blending ("see through") for
909 3D objects that involve semi-transparent regions on their surface, either
910 due to the \l{Node::opacity}{node opacity} or due to some color or texture
911 map in the material.
912
913 When this property is set to \c {false}, the Z-buffer is not written and
914 tested against, the depth test is skipped, and all objects, including fully
915 opaque ones, are rendered in one go, sorted back to front.
916
917 Setting this property to \c false should be rarely needed. It can be useful
918 in scenes where it is known that there is little benefit in the two-round
919 approach because either there are very few opaque objects, or they are
920 transformed in a way that a single back to front sorted pass performs
921 better.
922
923 \note Setting this property to \c false may cause rendering errors in
924 certain scenes. In addition, some features, such as shadows, ambient
925 occlusion, \c SCREEN_TEXTURE and \c DEPTH_TEXTURE in custom materials and
926 effects, will not behave correctly without enabling depth buffer usage.
927
928 \note This flag has no control over the presence of a depth or
929 depth-stencil buffer. Such buffers may still be allocated even when this is
930 set to \c false.
931*/
932bool QQuick3DSceneEnvironment::depthTestEnabled() const
933{
934 return m_depthTestEnabled;
935}
936/*!
937 \qmlproperty bool QtQuick3D::SceneEnvironment::depthPrePassEnabled
938
939 When enabled, the renderer performs a Z-prepass for opaque objects, meaning
940 it renders them with a simple shader and color write disabled in order to
941 get the depth buffer pre-filled before issuing draw calls for the main
942 rendering passes.
943
944 This can improve performance depending on the scene contents. It is
945 typically scenes with lots of overlapping objects and expensive fragment
946 shading that benefit from this. At the same time, it is worth noting that
947 the renderer performs front to back sorting for opaque objects, which in
948 itself helps reducing unnecessary fragment shading, and therefore the
949 Z-prepass does not always bring significant improvements.
950
951 On GPUs that use a tiled rendering architecture, which is common in mobile
952 and embedded systems, it is recommended to set this to \c false.
953
954 The default value is \c false.
955
956 \note This property has no effect when depth testing is disabled.
957*/
958bool QQuick3DSceneEnvironment::depthPrePassEnabled() const
959{
960 return m_depthPrePassEnabled;
961}
962
963/*!
964 \qmlproperty List<QtQuick3D::Effect> QtQuick3D::SceneEnvironment::effects
965 \since 5.15
966
967 This property contains a list of post-processing effects that will be
968 applied to the entire viewport. The result of each effect is fed to the
969 next so the order is significant.
970
971 \note For technical reasons, adding the same \l{QtQuick3D::Effect}{Effect}
972 node several times to the list is unsupported and will give unexpected results.
973*/
974QQmlListProperty<QQuick3DEffect> QQuick3DSceneEnvironment::effects()
975{
976 return QQmlListProperty<QQuick3DEffect>(this,
977 nullptr,
978 QQuick3DSceneEnvironment::qmlAppendEffect,
979 QQuick3DSceneEnvironment::qmlEffectsCount,
980 QQuick3DSceneEnvironment::qmlEffectAt,
981 QQuick3DSceneEnvironment::qmlClearEffects);
982}
983
984/*!
985 \qmlproperty enumeration QtQuick3D::SceneEnvironment::tonemapMode
986 \since 6.0
987
988 This property defines how colors are tonemapped before rendering. All
989 rendering in Qt Quick 3D is performed in linear color space and can in
990 many cases lead to generating color values that are not displayable. The
991 tonemapMode determines the technique that is used to remap colors into a
992 displayable range.
993
994 The default value is \c SceneEnvironment.TonemapModeLinear
995
996 \value SceneEnvironment.TonemapModeNone
997 All Tonemapping is bypassed. This mode is useful when performing post
998 processing effects.
999 \value SceneEnvironment.TonemapModeLinear
1000 Linear tonemapping is applied. Colors are gamma corrected and returned
1001 in sRGB color space.
1002 \value SceneEnvironment.TonemapModeAces
1003 Academy Color Encoding System tonemapping is applied.
1004 \value SceneEnvironment.TonemapModeHejlDawson
1005 Hejl-Dawson tonemapping is applied.
1006 \value SceneEnvironment.TonemapModeFilmic
1007 Filmic tonemapping is applied.
1008
1009 See \l{ExtendedSceneEnvironment::tonemapMode}{ExtendedSceneEnvironment} for
1010 an example of these different modes.
1011
1012 \note When using post-processing effects, most effects expect untonemapped
1013 linear color data. With application-provided, custom effects implemented
1014 via the \l Effect type, it is important to know that starting with Qt 6.5
1015 effects can safely assume that they work with linear color data, and
1016 tonemapping is performed automatically on the output of the last effect in
1017 the chain. If there is a need to customize tonemapping completely, consider
1018 setting the \c SceneEnvironment.TonemapModeNone value to disable the
1019 built-in tonemapper, and perform the appropriate adjustments on the color
1020 value in the last effect in the chain instead. This does not apply to the
1021 built-in effects of \l ExtendedSceneEnvironment, because those
1022 automatically take care of proper tonemapping regardless of what
1023 combination of built-in effects are enabled in the environment.
1024*/
1025QQuick3DSceneEnvironment::QQuick3DEnvironmentTonemapModes QQuick3DSceneEnvironment::tonemapMode() const
1026{
1027 return m_tonemapMode;
1028}
1029
1030/*!
1031 \qmlproperty real QtQuick3D::SceneEnvironment::skyboxBlurAmount
1032 \since 6.4
1033
1034 This property determines how much much the skybox should be blurred when
1035 using \c SceneEnvironment.SkyBox for the \l backgroundMode property. The
1036 default value is \c 0.0 which means there is no blurring.
1037
1038 Acceptable values range between 0.0 and 1.0, all other values will be clamped
1039 to this range.
1040
1041*/
1042
1043float QQuick3DSceneEnvironment::skyboxBlurAmount() const
1044{
1045 return m_skyboxBlurAmount;
1046}
1047
1048/*!
1049 \qmlproperty QtQuick3D::DebugSettings QtQuick3D::SceneEnvironment::debugSettings
1050 \since 6.5
1051
1052 This property specifies a \c DebugSettings object which is used to
1053 configure the debugging tools of the renderer. During construction
1054 the SceneEnvironment automatically creates a DebugSettings object
1055 associated with itself, and therefore setting a custom DebugSettings
1056 is usually not required.
1057
1058 An example of rendering the scene with wireframe mode enabled:
1059 \image debugsettings_wireframe.jpg {Sponza scene in wireframe mode}
1060
1061 Visualizing the normal vectors of the meshes:
1062 \image debugsettings_normals.jpg {Sponza scene showing surface normals}
1063
1064 Visualizing the specular lighting contribution:
1065 \image debugsettings_specular.jpg {Sponza scene showing specular highlights}
1066
1067 \sa DebugSettings
1068*/
1069
1070QQuick3DDebugSettings *QQuick3DSceneEnvironment::debugSettings() const
1071{
1072 return m_debugSettings;
1073}
1074
1075/*!
1076 \qmlproperty rect QtQuick3D::SceneEnvironment::scissorRect
1077 \since 6.5
1078
1079 This property defines a scissor rectangle in view coordinates, with the
1080 top-left corner at [0, 0]
1081*/
1082
1083QRect QQuick3DSceneEnvironment::scissorRect() const
1084{
1085 return m_scissorRect;
1086}
1087
1088void QQuick3DSceneEnvironment::setAntialiasingMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentAAModeValues antialiasingMode)
1089{
1090 if (m_antialiasingMode == antialiasingMode)
1091 return;
1092
1093 m_antialiasingMode = antialiasingMode;
1094 emit antialiasingModeChanged();
1095 update();
1096}
1097
1098void QQuick3DSceneEnvironment::setAntialiasingQuality(QQuick3DSceneEnvironment::QQuick3DEnvironmentAAQualityValues antialiasingQuality)
1099{
1100 if (m_antialiasingQuality == antialiasingQuality)
1101 return;
1102
1103 m_antialiasingQuality = antialiasingQuality;
1104 emit antialiasingQualityChanged();
1105 update();
1106}
1107
1108void QQuick3DSceneEnvironment::setBackgroundMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes backgroundMode)
1109{
1110 if (m_backgroundMode == backgroundMode)
1111 return;
1112
1113 m_backgroundMode = backgroundMode;
1114 emit backgroundModeChanged();
1115 update();
1116}
1117
1118void QQuick3DSceneEnvironment::setClearColor(const QColor &clearColor)
1119{
1120 if (m_clearColor == clearColor)
1121 return;
1122
1123 m_clearColor = clearColor;
1124 emit clearColorChanged();
1125 update();
1126}
1127
1128void QQuick3DSceneEnvironment::setAoStrength(float aoStrength)
1129{
1130 if (qFuzzyCompare(m_aoStrength, aoStrength))
1131 return;
1132
1133 m_aoStrength = aoStrength;
1134
1135 const bool aoEnabled = !(qFuzzyIsNull(m_aoStrength) || qFuzzyIsNull(m_aoDistance));
1136 setAoEnabled(aoEnabled);
1137
1138 emit aoStrengthChanged();
1139 update();
1140}
1141
1142void QQuick3DSceneEnvironment::setAoDistance(float aoDistance)
1143{
1144 if (qFuzzyCompare(m_aoDistance, aoDistance))
1145 return;
1146
1147 m_aoDistance = aoDistance;
1148
1149 const bool aoEnabled = !(qFuzzyIsNull(m_aoStrength) || qFuzzyIsNull(m_aoDistance));
1150 setAoEnabled(aoEnabled);
1151
1152 emit aoDistanceChanged();
1153 update();
1154}
1155
1156void QQuick3DSceneEnvironment::setAoSoftness(float aoSoftness)
1157{
1158 if (qFuzzyCompare(m_aoSoftness, aoSoftness))
1159 return;
1160
1161 m_aoSoftness = aoSoftness;
1162 emit aoSoftnessChanged();
1163 update();
1164}
1165
1166void QQuick3DSceneEnvironment::setAoDither(bool aoDither)
1167{
1168 if (m_aoDither == aoDither)
1169 return;
1170
1171 m_aoDither = aoDither;
1172 emit aoDitherChanged();
1173 update();
1174}
1175
1176void QQuick3DSceneEnvironment::setAoSampleRate(int aoSampleRate)
1177{
1178 if (m_aoSampleRate == aoSampleRate)
1179 return;
1180
1181 m_aoSampleRate = aoSampleRate;
1182 emit aoSampleRateChanged();
1183 update();
1184}
1185
1186void QQuick3DSceneEnvironment::setAoBias(float aoBias)
1187{
1188 if (qFuzzyCompare(m_aoBias, aoBias))
1189 return;
1190
1191 m_aoBias = aoBias;
1192 emit aoBiasChanged();
1193 update();
1194}
1195
1196void QQuick3DSceneEnvironment::setLightProbe(QQuick3DTexture *lightProbe)
1197{
1198 if (m_lightProbe == lightProbe)
1199 return;
1200
1201 QQuick3DObjectPrivate::attachWatcher(this, &QQuick3DSceneEnvironment::setLightProbe, lightProbe, m_lightProbe);
1202
1203 m_lightProbe = lightProbe;
1204 emit lightProbeChanged();
1205 update();
1206}
1207
1208void QQuick3DSceneEnvironment::setProbeExposure(float probeExposure)
1209{
1210 if (qFuzzyCompare(m_probeExposure, probeExposure))
1211 return;
1212
1213 m_probeExposure = probeExposure;
1214 emit probeExposureChanged();
1215 update();
1216}
1217
1218void QQuick3DSceneEnvironment::setProbeHorizon(float probeHorizon)
1219{
1220 // clamp value to expected range
1221 probeHorizon = qBound(0.0f, probeHorizon, 1.0f);
1222
1223 if (qFuzzyCompare(m_probeHorizon, probeHorizon))
1224 return;
1225
1226 m_probeHorizon = probeHorizon;
1227 emit probeHorizonChanged();
1228 update();
1229}
1230
1231void QQuick3DSceneEnvironment::setProbeOrientation(const QVector3D &orientation)
1232{
1233 if (qFuzzyCompare(m_probeOrientation, orientation))
1234 return;
1235
1236 m_probeOrientation = orientation;
1237 emit probeOrientationChanged();
1238 update();
1239}
1240
1241void QQuick3DSceneEnvironment::setDepthTestEnabled(bool depthTestEnabled)
1242{
1243 if (m_depthTestEnabled == depthTestEnabled)
1244 return;
1245
1246 m_depthTestEnabled = depthTestEnabled;
1247 emit depthTestEnabledChanged();
1248 update();
1249}
1250
1251void QQuick3DSceneEnvironment::setDepthPrePassEnabled(bool depthPrePassEnabled)
1252{
1253 if (m_depthPrePassEnabled == depthPrePassEnabled)
1254 return;
1255
1256 m_depthPrePassEnabled = depthPrePassEnabled;
1257 emit depthPrePassEnabledChanged();
1258 update();
1259}
1260
1261void QQuick3DSceneEnvironment::setTonemapMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentTonemapModes tonemapMode)
1262{
1263 if (m_tonemapMode == tonemapMode)
1264 return;
1265
1266 m_tonemapMode = tonemapMode;
1267 emit tonemapModeChanged();
1268 update();
1269}
1270
1271bool QQuick3DSceneEnvironment::useBuiltinTonemapper() const
1272{
1273 return true;
1274}
1275
1276QSSGRenderGraphObject *QQuick3DSceneEnvironment::updateSpatialNode(QSSGRenderGraphObject *node)
1277{
1278 // Don't do anything, these properties get set by the scene renderer
1279 return node;
1280}
1281
1282void QQuick3DSceneEnvironment::itemChange(QQuick3DObject::ItemChange change, const QQuick3DObject::ItemChangeData &value)
1283{
1284 if (change == QQuick3DObject::ItemSceneChange)
1285 updateSceneManager(value.sceneManager);
1286}
1287
1288const QVector<QQuick3DEffect *> &QQuick3DSceneEnvironment::effectList() const
1289{
1290 return m_effects;
1291}
1292
1293void QQuick3DSceneEnvironment::updateSceneManager(QQuick3DSceneManager *manager)
1294{
1295 if (manager) {
1296 QQuick3DObjectPrivate::refSceneManager(m_lightProbe, *manager);
1297 QQuick3DObjectPrivate::refSceneManager(m_skyBoxCubeMap, *manager);
1298 } else {
1299 QQuick3DObjectPrivate::derefSceneManager(m_lightProbe);
1300 QQuick3DObjectPrivate::derefSceneManager(m_skyBoxCubeMap);
1301 }
1302}
1303
1304void QQuick3DSceneEnvironment::setTemporalAAMode(const QQuick3DEnvironmentTemporalAAMode &newTemporalAAMode)
1305{
1306 if (m_temporalAAMode == newTemporalAAMode)
1307 return;
1308 m_temporalAAMode = newTemporalAAMode;
1309 emit temporalAAModeChanged();
1310 update();
1311}
1312
1313void QQuick3DSceneEnvironment::setTemporalAAEnabled(bool temporalAAEnabled)
1314{
1315 if (m_temporalAAEnabled == temporalAAEnabled)
1316 return;
1317
1318 m_temporalAAEnabled = temporalAAEnabled;
1319 emit temporalAAEnabledChanged();
1320 update();
1321}
1322
1323void QQuick3DSceneEnvironment::setTemporalAAStrength(float strength)
1324{
1325 if (qFuzzyCompare(m_temporalAAStrength, strength))
1326 return;
1327
1328 m_temporalAAStrength = strength;
1329 emit temporalAAStrengthChanged();
1330 update();
1331}
1332
1333void QQuick3DSceneEnvironment::setSpecularAAEnabled(bool enabled)
1334{
1335 if (m_specularAAEnabled == enabled)
1336 return;
1337
1338 m_specularAAEnabled = enabled;
1339 emit specularAAEnabledChanged();
1340 update();
1341}
1342
1343void QQuick3DSceneEnvironment::qmlAppendEffect(QQmlListProperty<QQuick3DEffect> *list, QQuick3DEffect *effect)
1344{
1345 if (effect == nullptr)
1346 return;
1347 QQuick3DSceneEnvironment *self = static_cast<QQuick3DSceneEnvironment *>(list->object);
1348 self->m_effects.push_back(effect);
1349
1350 if (effect->parentItem() == nullptr)
1351 effect->setParentItem(self);
1352
1353 for (QQuick3DEffect *e : self->m_effects)
1354 e->effectChainDirty();
1355
1356 self->update();
1357}
1358
1359QQuick3DEffect *QQuick3DSceneEnvironment::qmlEffectAt(QQmlListProperty<QQuick3DEffect> *list, qsizetype index)
1360{
1361 QQuick3DSceneEnvironment *self = static_cast<QQuick3DSceneEnvironment *>(list->object);
1362 return self->m_effects.at(index);
1363}
1364
1365qsizetype QQuick3DSceneEnvironment::qmlEffectsCount(QQmlListProperty<QQuick3DEffect> *list)
1366{
1367 QQuick3DSceneEnvironment *self = static_cast<QQuick3DSceneEnvironment *>(list->object);
1368 return self->m_effects.size();
1369}
1370
1371void QQuick3DSceneEnvironment::qmlClearEffects(QQmlListProperty<QQuick3DEffect> *list)
1372{
1373 QQuick3DSceneEnvironment *self = static_cast<QQuick3DSceneEnvironment *>(list->object);
1374 self->m_effects.clear();
1375 self->update();
1376}
1377
1378void QQuick3DSceneEnvironment::setSkyboxBlurAmount(float newSkyboxBlurAmount)
1379{
1380 newSkyboxBlurAmount = qBound(0.0f, newSkyboxBlurAmount, 1.0f);
1381
1382 if (qFuzzyCompare(m_skyboxBlurAmount, newSkyboxBlurAmount))
1383 return;
1384
1385 m_skyboxBlurAmount = newSkyboxBlurAmount;
1386 emit skyboxBlurAmountChanged();
1387 update();
1388}
1389
1390/*!
1391 \qmlproperty Lightmapper QtQuick3D::SceneEnvironment::lightmapper
1392
1393 When this property is set to a valid Lightmapper object, the settings
1394 specified by the object will be taken into account when baking lightmaps.
1395
1396 The default value is null, which means using default values for all the
1397 baking-related settings.
1398
1399 For more information on how to bake lightmaps, see the \l Lightmapper
1400 documentation.
1401
1402 When lightmaps are not relevant to an application and baked lighting is
1403 never generated, the property and the associated object serve no purpose in
1404 practice.
1405
1406 \sa Model::usedInBakedLighting, Model::bakedLightmap, Light::bakeMode, Lightmapper
1407 */
1408
1409QQuick3DLightmapper *QQuick3DSceneEnvironment::lightmapper() const
1410{
1411 return m_lightmapper;
1412}
1413
1414void QQuick3DSceneEnvironment::setLightmapper(QQuick3DLightmapper *lightmapper)
1415{
1416 if (m_lightmapper == lightmapper)
1417 return;
1418
1419 if (m_lightmapper)
1420 m_lightmapper->disconnect(m_lightmapperSignalConnection);
1421
1422 m_lightmapper = lightmapper;
1423
1424 m_lightmapperSignalConnection = QObject::connect(m_lightmapper, &QQuick3DLightmapper::changed, this,
1425 [this] { update(); });
1426
1427 QObject::connect(m_lightmapper, &QObject::destroyed, this,
1428 [this](QObject *obj)
1429 {
1430 if (m_lightmapper == obj) {
1431 m_lightmapper = nullptr;
1432 update();
1433 }
1434 });
1435
1436 emit lightmapperChanged();
1437 update();
1438}
1439
1440/*!
1441 \qmlproperty QtQuick3D::CubeMapTexture QtQuick3D::SceneEnvironment::skyBoxCubeMap
1442
1443 This property defines a cubemap to be used as a skybox when the background mode is \c SkyBoxCubeMap.
1444
1445 \since 6.4
1446*/
1447QQuick3DCubeMapTexture *QQuick3DSceneEnvironment::skyBoxCubeMap() const
1448{
1449 return m_skyBoxCubeMap;
1450}
1451
1452void QQuick3DSceneEnvironment::setSkyBoxCubeMap(QQuick3DCubeMapTexture *newSkyBoxCubeMap)
1453{
1454 if (m_skyBoxCubeMap == newSkyBoxCubeMap)
1455 return;
1456
1457 QQuick3DObjectPrivate::attachWatcher(this, &QQuick3DSceneEnvironment::setSkyBoxCubeMap, newSkyBoxCubeMap, m_skyBoxCubeMap);
1458
1459 m_skyBoxCubeMap = newSkyBoxCubeMap;
1460 emit skyBoxCubeMapChanged();
1461}
1462
1463void QQuick3DSceneEnvironment::setDebugSettings(QQuick3DDebugSettings *newDebugSettings)
1464{
1465 if (m_debugSettings == newDebugSettings)
1466 return;
1467
1468 if (m_debugSettings)
1469 m_debugSettings->disconnect(m_debugSettingsSignalConnection);
1470
1471 m_debugSettings = newDebugSettings;
1472
1473 m_debugSettingsSignalConnection = QObject::connect(m_debugSettings, &QQuick3DDebugSettings::changed, this,
1474 [this] { update(); });
1475 QObject::connect(m_debugSettings, &QObject::destroyed, this,
1476 [this](QObject *obj) {
1477 if (m_debugSettings == obj) {
1478 m_debugSettings = nullptr;
1479 update();
1480 }
1481 });
1482
1483 emit debugSettingsChanged();
1484 update();
1485}
1486
1487void QQuick3DSceneEnvironment::setScissorRect(QRect rect)
1488{
1489 if (m_scissorRect == rect)
1490 return;
1491
1492 m_scissorRect = rect;
1493 emit scissorRectChanged();
1494 update();
1495}
1496
1497bool QQuick3DSceneEnvironment::gridEnabled() const
1498{
1499 return m_gridEnabled;
1500}
1501
1502void QQuick3DSceneEnvironment::setGridEnabled(bool newGridEnabled)
1503{
1504 if (m_gridEnabled == newGridEnabled)
1505 return;
1506 m_gridEnabled = newGridEnabled;
1507 update();
1508}
1509
1510float QQuick3DSceneEnvironment::gridScale() const
1511{
1512 return m_gridScale;
1513}
1514
1515void QQuick3DSceneEnvironment::setGridScale(float newGridScale)
1516{
1517 if (qFuzzyCompare(m_gridScale, newGridScale))
1518 return;
1519 m_gridScale = newGridScale;
1520 update();
1521}
1522
1523uint QQuick3DSceneEnvironment::gridFlags() const
1524{
1525 return m_gridFlags;
1526}
1527
1528void QQuick3DSceneEnvironment::setGridFlags(uint newGridFlags)
1529{
1530 if (m_gridFlags == newGridFlags)
1531 return;
1532 m_gridFlags = newGridFlags;
1533 update();
1534}
1535
1536/*!
1537 \qmlproperty bool SceneEnvironment::aoEnabled
1538 \since 6.5
1539
1540 Enable or disable ambient occlusion.
1541
1542 The default value is \c false, which means ambient occlusion is disabled.
1543
1544 \note If \l aoStrength or \ aoDistance is 0, then setting this property to
1545 \c true will also set those values appropriately to make the ambient
1546 occlusion effective.
1547
1548 \note Getting visually good-looking screen space ambient occlusion is
1549 dependent on carefully tuning a number of related parameters, such as \l
1550 aoStrength, \l aoSoftness, \l aoDistance, \l aoDither, \l aoBias, and \l
1551 aoSampleRate.
1552
1553 \sa aoStrength, aoDistance
1554*/
1555
1556bool QQuick3DSceneEnvironment::aoEnabled() const
1557{
1558 return m_aoEnabled;
1559}
1560
1561void QQuick3DSceneEnvironment::setAoEnabled(bool newAoEnabled)
1562{
1563 if (m_aoEnabled == newAoEnabled)
1564 return;
1565
1566 m_aoEnabled = newAoEnabled;
1567
1568 if (m_aoEnabled) {
1569 if (qFuzzyIsNull(m_aoStrength))
1570 setAoStrength(100.0f);
1571 if (qFuzzyIsNull(m_aoDistance))
1572 setAoDistance(defaultAoDistance());
1573 }
1574
1575 emit aoEnabledChanged();
1576 update();
1577}
1578
1579/*!
1580 \qmlproperty QtQuick3D::Fog QtQuick3D::SceneEnvironment::fog
1581 \since 6.5
1582
1583 When this property is set to a valid \l {QtQuick3D::Fog}{Fog} object, it is
1584 used to configure the renderer's built-in fog support.
1585
1586 The default value is null, which means no fog. This is equivalent to
1587 setting a Fog object with \l{Fog::enabled}{enabled} set to false.
1588
1589 \image fog.jpg {Scene with fog effect}
1590
1591 \sa {QtQuick3D::Fog}{Fog}
1592 */
1593
1594QQuick3DFog *QQuick3DSceneEnvironment::fog() const
1595{
1596 return m_fog;
1597}
1598
1599void QQuick3DSceneEnvironment::setFog(QQuick3DFog *fog)
1600{
1601 if (m_fog == fog)
1602 return;
1603
1604 if (m_fog)
1605 m_fog->disconnect(m_fogSignalConnection);
1606
1607 m_fog = fog;
1608
1609 m_fogSignalConnection = QObject::connect(m_fog, &QQuick3DFog::changed, this, [this] { update(); });
1610
1611 QObject::connect(m_fog, &QObject::destroyed, this,
1612 [this](QObject *obj)
1613 {
1614 if (m_fog == obj) {
1615 m_fog = nullptr;
1616 update();
1617 }
1618 });
1619
1620 emit fogChanged();
1621 update();
1622}
1623
1624/*!
1625 \qmlproperty enumeration QtQuick3D::SceneEnvironment::oitMethod
1626 \since 6.9
1627
1628 This property holds the Order Independent Transparency method. Setting this
1629 property to a valid OIT method causes the renderer to render transparent pixels
1630 in the correct depth order.
1631
1632 Possible values are:
1633 \value SceneEnvironment.OITNone OIT is turned off.
1634 \value SceneEnvironment.OITWeightedBlended Approximates order independent transparency.
1635 \value SceneEnvironment.OITLinkedList Accurate order independent transparency.
1636
1637 The default is \c None and order independent transparency is turned off.
1638
1639 \b Weighted Blended
1640
1641 This is an approximation of order independent transparency. The transparent fragments are
1642 rendered to an offscreen buffer while weighting is applied to each fragment based on its
1643 distance to the camera. This buffer is then blended to the backbuffer after de-weighting
1644 each pixel. This method doesn't follow the source-over composition rule for all fragments
1645 and the result is different from the correct result, however this method works also on
1646 older hardware and is faster than the other more rigorous methods.
1647
1648 \b Linked List
1649
1650 This is an accurate order independent transparency. The transparent fragments are
1651 rendered to a linked list in the render pass and sorted by their depth and blended
1652 in the composition pass.
1653 \since 6.11
1654
1655 \note OIT might not work with MSAA on devices with GLES 3.1 or lower. It is recommended
1656 not to use MSAA if oit is wanted on such devices.
1657
1658 \note Order independent transparenty is only applicaple to source-over blend mode.
1659 If scene contains objects with other blending modes, OIT is disabled.
1660*/
1661
1662QQuick3DSceneEnvironment::QQuick3DEnvironmentOITMethod QQuick3DSceneEnvironment::oitMethod() const
1663{
1664 return m_oitMethod;
1665}
1666
1667void QQuick3DSceneEnvironment::setOitMethod(QQuick3DSceneEnvironment::QQuick3DEnvironmentOITMethod method)
1668{
1669 if (m_oitMethod == method)
1670 return;
1671 m_oitMethod = method;
1672 emit oitMethodChanged();
1673 update();
1674}
1675
1676QT_END_NAMESPACE
Combined button and popup list for selecting options.