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
qtquick3d-ibl.qdoc
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5
6\title Using Image-Based Lighting
7\page quick3d-asset-conditioning-ibl
8
9\section1 Introduction
10
11Qt Quick 3D supports IBL (Image-Based Lighting) to illuminate scenes or individual materials.
12
13IBL is a lighting technique that allows scenes to be illuminated with images. This is especially
14useful when you want to create realistic lighting and reflections in indoor and outdoor scenes.
15
16You can use any image file for IBL, but it is recommended to use 360ยบ HDR (High Dynamic Range)
17images. HDR images have a much higher dynamic range than for example JPEG or PNG images. A higher
18dynamic range provides more realistic lighting through a great range of luminance levels from
19very bright to very dark.
20
21The following example demonstrates the lighting effect on an object using an HDR image vs a single
22directional light:
23
24\table
25\header
26 \li Light
27 \li Smooth Dielectric material
28 \li Rough Dielectric material
29 \li Smooth Metallic material
30 \li Rough Metallic material
31\row
32 \li \b{Single directional light}
33 \li \image IBL-sphere-smooth-directional-light.png
34 {Smooth sphere with single directional light}
35 \li \image IBL-sphere-rough-directional-light.png
36 {Rough sphere with single directional light}
37 \li \image IBL-sphere-metallic-smooth-directional-light.png
38 {Metallic smooth sphere with single directional light}
39 \li \image IBL-sphere-metallic-rough-directional-light.png
40 {Metallic rough sphere with single directional light}
41\row
42 \li \b{Image-based light}
43 \li \image IBL-sphere-smooth-environment-light.png
44 {Smooth sphere with image-based environment lighting}
45 \li \image IBL-sphere-rough-environment-light.png
46 {Rough sphere with image-based environment lighting}
47 \li \image IBL-sphere-metallic-smooth-environment-light.png
48 {Metallic smooth sphere with image-based environment lighting}
49 \li \image IBL-sphere-metallic-rough-environment-light.png
50 {Metallic rough sphere with image-based environment lighting}
51\endtable
52
53\section1 Scene Lighting
54
55To illuminate a \l {SceneEnvironment}{scene} using an image you'll add the image as a \l Texture to
56the \l {SceneEnvironment::lightProbe}{lightProbe} property.
57
58\qml
59lightProbe: Texture {
60 source: "maps/OpenfootageNET_garage-1024.hdr"
61}
62\endqml
63
64Once you have selected an image, IBL is set up for your scene. All models in the scene are
65illuminated by the light probe by default.
66
67\note You can also combine IBL with any other light source to compliment the lighting effect on an
68object.
69
70Now that you have IBL set up for your scene, let us have a look at the different properties for
71the probe. In many cases the default values provide a satisfying result, but you can tweak the
72following property values depending on the image and desired result:
73
74\list
75 \li \l {SceneEnvironment::probeExposure}{Exposure}
76 The amount of light emitted by the light probe.
77 \li \l {SceneEnvironment::probeHorizon}{Horizon Cut-Off}
78 Increasing the value adds darkness (black) to the bottom half of the environment,
79 forcing the lighting to come predominantly from the top of the image
80 (and removing specific reflections from the lower half).
81 \li \l {SceneEnvironment::probeOrientation}{Orientation}
82 This property when defines the orientation of the light probe.
83 Orientation is defined in terms of euler angles in degrees over the
84 x, y, and z axes.
85\endlist
86
87\table
88\header
89 \li Property
90 \li Metallic material
91 \li Dielectric material
92\row
93 \li \e{\b{Default settings}}
94 \li \image IBL-sphere-metallic-smooth-environment-light.png
95 {Metallic smooth sphere with image-based environment lighting}
96 \li \image IBL-sphere-smooth-environment-light.png
97 {Smooth sphere with image-based environment lighting}
98\row
99 \li \e{\b{Exposure}}
100 \li \image IBL-sphere-metallic-smooth-environment-light-exposure.png
101 {Metallic smooth sphere showing light probe exposure adjustment}
102 \li \image IBL-sphere-smooth-environment-light-exposure.png
103 {Smooth sphere showing light probe exposure adjustment}
104\row
105 \li \e{\b{Horizon Cut-off}}
106 \li \image IBL-sphere-metallic-smooth-environment-light-horizon.png
107 {Metallic smooth sphere showing light probe horizon adjustment}
108 \li \image IBL-sphere-smooth-environment-light-horizon.png
109 {Smooth sphere showing light probe horizon adjustment}
110\row
111 \li \e{\b{Orientation}}
112 \li \image IBL-sphere-metallic-smooth-environment-light-orientation.png
113 {Metallic smooth sphere showing light probe orientation}
114 \li \image IBL-sphere-smooth-environment-light-orientation.png
115 {Smooth sphere showing light probe orientation}
116\endtable
117
118\section1 Material Lighting
119
120To use image-based lighting only on one material instead of a whole scene, or use a separate light
121probe for a model already illuminated by image-based lighting, set the image as the
122\l {Material::lightProbe}{light probe} for the material.
123
124Once you have followed the steps above, you have a separate light probe set for the material.
125This light probe overrides the scene light probe if there is one specified.
126
127\section1 Pre-generating IBL cubemap
128
129When IBL is used, a cubemap for the IBL image needs to be generated by the
130application. By default this happens during application startup and can be quite
131slow, especially on embedded and mobile devices. It is therefore possible to
132pre-generate this cubemap using \l {Balsam Asset Import Tool}{Balsam}. Simply
133run \l {Balsam Asset Import Tool}{Balsam} with the .hdr file as input and it
134will output a cubemap file with the same name as the input but with a ktx file
135extension. One can then reference this file in the lightProbe property's
136associated \l Texture, and Qt will then load the pregenerated cubemap without
137any costly processing at run time.
138
139\section2 Manual baking
140
141As an example, let's assume the application uses a .hdr image for its light
142probes or the skybox:
143
144\badcode
145 View3D {
146 environment: SceneEnvironment {
147 backgroundMode: SceneEnvironment.SkyBox
148 lightProbe: Texture {
149 source: "environment.hdr"
150 }
151 probeOrientation: Qt.vector3d(0, -90, 0)
152 }
153 // ...
154 }
155\endcode
156
157This is fully functional, assuming environment.hdr is available at run
158time. However, loading the .hdr image involves expensive pre-processing. This
159can be avoided by running:
160
161\badcode
162 balsam environment.hdr
163\endcode
164
165The result is a new file \c{environment.ktx}. Shipping this instead of the .hdr file
166and changing the Texture source provides significantly faster loading times.
167
168\badcode
169 lightProbe: Texture {
170 source: "environment.ktx"
171 }
172\endcode
173
174\section2 Build time baking via CMake
175
176Manually running balsam on assets is not always ideal. Therefore, applications
177are recommended to rely on CMake to automatically perform the same task at
178application build time.
179
180This is done by using the qt6_add_lightprobe_images CMake function provided by
181the Quick3D component of the Qt6 package:
182
183\badcode
184 ...
185 find_package(Qt6 COMPONENTS Quick3D)
186 ...
187 qt6_add_lightprobe_images(application_target "ibl_assets"
188 PREFIX
189 "/ibl"
190 FILES
191 "environment.hdr"
192 )
193\endcode
194
195Replace \c application_target with the appropriate target. Here, there is no
196need to run balsam manually on environment.hdr anymore, and the .hdr file does
197not need to be shipped with the application. Rather, during the build balsam
198will be invoked automatically, and an environment.ktx will be added to the
199application resources at \c{:/ibl/environment.ktx}. The lightProbe's \l Texture
200needs to then reference this file.
201
202\badcode
203 lightProbe: Texture {
204 source: "qrc:/ibl/environment.ktx"
205 }
206\endcode
207
208\note Setting PREFIX so that the final name in the resource system has a path
209matching the .qml file's location allows using a relative source path instead of
210having to provide an absolute path with the qrc scheme.
211
212In addition to PREFIX, the keyword BASE is also available. The behavior follows
213that of qt6_add_resources. For example, the following leads to generating
214\c{:/ibl/maps/environment.ktx}:
215
216\badcode
217 qt6_add_lightprobe_images(application_target "ibl_assets"
218 PREFIX
219 "/ibl"
220 BASE
221 "../data/shared"
222 FILES
223 "../data/shared/maps/environment.hdr"
224 )
225\endcode
226
227Like in qt6_add_shaders, the OUTPUTS keyword is available to allow specifying a
228completely custom name for the file in the resource system. For example, the
229following also generates \c{:/ibl/maps/environment.ktx}:
230
231\badcode
232 qt6_add_lightprobe_images(application_target "ibl_assets"
233 PREFIX
234 "/ibl"
235 FILES
236 "../data/shared/maps/environment.hdr"
237 OUTPUTS
238 "maps/environment.ktx"
239 )
240\endcode
241
242\note For each entry in the FILES list, there must be a corresponding entry in
243OUTPUTS.
244
245*/