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
11
Qt Quick 3D supports IBL (Image-Based Lighting) to illuminate scenes or individual materials.
12
13
IBL is a lighting technique that allows scenes to be illuminated with images. This is especially
14
useful when you want to create realistic lighting and reflections in indoor and outdoor scenes.
15
16
You can use any image file for IBL, but it is recommended to use 360ยบ HDR (High Dynamic Range)
17
images. HDR images have a much higher dynamic range than for example JPEG or PNG images. A higher
18
dynamic range provides more realistic lighting through a great range of luminance levels from
19
very bright to very dark.
20
21
The following example demonstrates the lighting effect on an object using an HDR image vs a single
22
directional 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
55
To illuminate a \l {SceneEnvironment}{scene} using an image you'll add the image as a \l Texture to
56
the \l {SceneEnvironment::lightProbe}{lightProbe} property.
57
58
\qml
59
lightProbe: Texture {
60
source: "maps/OpenfootageNET_garage-1024.hdr"
61
}
62
\endqml
63
64
Once you have selected an image, IBL is set up for your scene. All models in the scene are
65
illuminated 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
68
object.
69
70
Now that you have IBL set up for your scene, let us have a look at the different properties for
71
the probe. In many cases the default values provide a satisfying result, but you can tweak the
72
following 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
120
To use image-based lighting only on one material instead of a whole scene, or use a separate light
121
probe for a model already illuminated by image-based lighting, set the image as the
122
\l {Material::lightProbe}{light probe} for the material.
123
124
Once you have followed the steps above, you have a separate light probe set for the material.
125
This light probe overrides the scene light probe if there is one specified.
126
127
\section1 Pre-generating IBL cubemap
128
129
When IBL is used, a cubemap for the IBL image needs to be generated by the
130
application. By default this happens during application startup and can be quite
131
slow, especially on embedded and mobile devices. It is therefore possible to
132
pre-generate this cubemap using \l {Balsam Asset Import Tool}{Balsam}. Simply
133
run \l {Balsam Asset Import Tool}{Balsam} with the .hdr file as input and it
134
will output a cubemap file with the same name as the input but with a ktx file
135
extension. One can then reference this file in the lightProbe property's
136
associated \l Texture, and Qt will then load the pregenerated cubemap without
137
any costly processing at run time.
138
139
\section2 Manual baking
140
141
As an example, let's assume the application uses a .hdr image for its light
142
probes 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
157
This is fully functional, assuming environment.hdr is available at run
158
time. However, loading the .hdr image involves expensive pre-processing. This
159
can be avoided by running:
160
161
\badcode
162
balsam environment.hdr
163
\endcode
164
165
The result is a new file \c{environment.ktx}. Shipping this instead of the .hdr file
166
and 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
176
Manually running balsam on assets is not always ideal. Therefore, applications
177
are recommended to rely on CMake to automatically perform the same task at
178
application build time.
179
180
This is done by using the qt6_add_lightprobe_images CMake function provided by
181
the 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
195
Replace \c application_target with the appropriate target. Here, there is no
196
need to run balsam manually on environment.hdr anymore, and the .hdr file does
197
not need to be shipped with the application. Rather, during the build balsam
198
will be invoked automatically, and an environment.ktx will be added to the
199
application resources at \c{:/ibl/environment.ktx}. The lightProbe's \l Texture
200
needs 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
209
matching the .qml file's location allows using a relative source path instead of
210
having to provide an absolute path with the qrc scheme.
211
212
In addition to PREFIX, the keyword BASE is also available. The behavior follows
213
that 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
227
Like in qt6_add_shaders, the OUTPUTS keyword is available to allow specifying a
228
completely custom name for the file in the resource system. For example, the
229
following 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
243
OUTPUTS.
244
245
*/
qtquick3d
src
quick3d
doc
src
qtquick3d-ibl.qdoc
Generated on
for Qt by
1.16.1