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