1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qquick3dlightmapper_p.h"
QT_BEGIN_NAMESPACE
/*!
\qmltype Lightmapper
\inherits QtObject
\inqmlmodule QtQuick3D
\brief Specifies lightmap baking settings for a scene.
\since 6.4
Used when baking direct and indirect lighting. Most of these settings are not
relevant at other times, such as when using already generated lightmaps to
render a scene. The exception is \l source, though this has a sensible default
for development.
On a successfull bake a single file will be generated at the value specified by
\l source. This binary file contains the results of the bake, including the
per-model lightmaps and the mesh files with lightmap-compatible UVs.
The individual model data is accessed via \l BakedLightmap::key.
The data contained in the resulting lightmap file is all tightly coupled
to each other and to the current scene state. This means that any modifications
to the original mesh files, Lightmapper settings or other scene changes will
require a new bake to be executed to see the updated result.
\note As of Qt 6.4, lightmap baking is in an early technical preview state.
Changes to features, quality, and API are likely to happen in future releases.
The Lightmapper object works in combination with:
\list
\li \l Model::bakedLightmap and the associated \l BakedLightmap,
\li \l Model::usedInBakedLighting and \l Model::texelsPerUnit,
\li \l Light::bakeMode,
\li the engine's built-in lightmap baker.
\endlist
\sa {Lightmaps and Global Illumination}, {Qt Quick 3D - Baked Lightmap Example}
*/
/*!
\qmlproperty real Lightmapper::opacityThreshold
The opacity (alpha) threshold below which an object is ignored in ray -
mesh intersections when calculating lighting via raytracing. When the
opacity falls below the threshold, the model (submesh) will not occlude
lights and thus will not generate shadows either.
The default value is 0.5.
\note The lightmapper takes the \l{PrincipledMaterial::opacity}{material's
opacity} and the \l{PrincipledMaterial::baseColor}{baseColor alpha}
combined with the \l{PrincipledMaterial::baseColorMap}{base color map's
alpha} into account. Other sources of semi-transparency, such as the
opacity map or alpha cut-off settings are ignored during the lightmap
baking process.
*/
/*!
\qmlproperty real Lightmapper::bias
Raycasting bias used during baking. Adapt the value in case artifacts
occur, for example in order to reduce undesired shadowing patterns. In many
cases the default value is sufficient.
The default value is 0.005.
*/
/*!
\qmlproperty bool Lightmapper::adaptiveBiasEnabled
Enables applying an additional, dynamic bias based on the surface normal.
The default value is true.
*/
/*!
\qmlproperty bool Lightmapper::indirectLightEnabled
Normally there is no need to change this value. The default value is true.
Setting this property to false disables indirect light computation during
lightmap baking. Thus the resulting texture maps will only contain direct
light information. At run time, the engine will continue to use the maps
normally, assuming they contain both direct and indirect lighting.
*/
/*!
\qmlproperty int Lightmapper::samples
The number of samples per lightmap texel.
The default value is 256.
The value heavily affects both the performance and quality of the resulting
lightmaps during lightmap baking.
*/
/*!
\qmlproperty int Lightmapper::indirectLightWorkgroupSize
The size of the sample workgroups. These workgroups are attempted to be
executed in parallel. (the exact behavior depends on the number of CPU
cores and the QThreadPool configuration)
The default value is 32. With the default sample count of 256 this means
attempting to run 8 groups in parallel per model.
*/
/*!
\qmlproperty int Lightmapper::bounces
The maximum number of indirect light bounces per sample. The value should
at least be 1, no point in indirect light calculation otherwise.
The default value is 3.
The value heavily affects both the performance and quality of the resulting
lightmaps during lightmap baking.
*/
/*!
\qmlproperty real Lightmapper::indirectLightFactor
Multiplier for the indirect light amount. While it is the value of 1 (i.e.,
not affecting the indirect light amount calculation) that provides the
strictly correct rendering results, a slightly higher value can often give
better looking results when using the lightmap, even with a lower number of
bounces.
The default value is 1.
*/
/*!
\qmlproperty string Lightmapper::source
\since 6.10
\default lightmaps.bin
The path to where to save the generated lightmap file on a successful bake
and where to load the file at runtime.
When baking, the path needs to be set up to be a regular file location which
is writable. By default the value is \c{lightmaps.bin}, meaning the current
working directory, in a file called exactly that. This location is also
readable, which makes the final result instantly appear on a successful bake.
When loading a bake it will try to look at an actual file location on disk,
falling back to looking at files embedded in the executable via the Qt
resource system if not found. To control the value more explicitly it can be
prefixed, with for example \c{qrc:/} and the Lightmapper will always look for
a file in resources.
The following example always tries to load the lightmap file embedded via
resources. First set the value to a writable location and bake. Then copy the
generated file into the source directoy. Then by listing the file in the
application's CMake project as a resource under the \c{/lightmaps} PREFIX,
lets the build process pick up the file and include it in the executable.
\qml
Lightmapper {
source: "qrc:/lightmaps/lightmaps.bin"
// will attempt to load from :/lightmaps/lightmaps.bin at runtime.
// this will result in a "Location not writable" when initiating a bake.
}
\endqml
Note that just omitting the prefix will still make the Lightmapper try to
load the lightmap file from resources at runtime if the file is not found
on disk. This is a convenience during development. If a bake is then
initiated and is successful, the same path is converted to absolute and the
generated file will be saved to that location. Now the results will insantly
appear. Then it's just a matter of copying this file to the source directory
and adding back the prefix to start explicitly loading from resources again.
\note It is not possible to write to the resource system, so an error is given
when a bake is initiated and the path is explicitly set up to point there.
*/
/*!
\qmlproperty real Lightmapper::denoiseSigma
\since 6.10
\default 8
This property defines the sigma value of the Non-local means based denoiser.
This means that the higher this value is the stronger the blurring will be.
Try to keep this value as low as possible to avoid losing visual features
while still removing the noise.
*/
/*!
\qmlproperty real Lightmapper::texelsPerUnit
\since 6.10
\default 1
This property defines the unit to texel scale, meaning a \c{1x1} quad with
texelsPerUnit of \c{32} will take up approximately \c{32x32} texels in the
lightmap.
\sa Model::texelsPerUnit
*/
float QQuick3DLightmapper::opacityThreshold() const
{
return m_opacityThreshold;
}
float QQuick3DLightmapper::bias() const
{
return m_bias;
}
bool QQuick3DLightmapper::isAdaptiveBiasEnabled() const
{
return m_adaptiveBias;
}
bool QQuick3DLightmapper::isIndirectLightEnabled() const
{
return m_indirectLight;
}
int QQuick3DLightmapper::samples() const
{
return m_samples;
}
int QQuick3DLightmapper::indirectLightWorkgroupSize() const
{
return m_workgroupSize;
}
int QQuick3DLightmapper::bounces() const
{
return m_bounces;
}
float QQuick3DLightmapper::indirectLightFactor() const
{
return m_indirectFactor;
}
QString QQuick3DLightmapper::source() const
{
return m_source;
}
void QQuick3DLightmapper::setOpacityThreshold(float opacity)
{
if (m_opacityThreshold == opacity)
return;
m_opacityThreshold = opacity;
emit opacityThresholdChanged();
emit changed();
}
void QQuick3DLightmapper::setBias(float bias)
{
if (m_bias == bias)
return;
m_bias = bias;
emit biasChanged();
emit changed();
}
void QQuick3DLightmapper::setAdaptiveBiasEnabled(bool enabled)
{
if (m_adaptiveBias == enabled)
return;
m_adaptiveBias = enabled;
emit adaptiveBiasEnabledChanged();
emit changed();
}
void QQuick3DLightmapper::setIndirectLightEnabled(bool enabled)
{
if (m_indirectLight == enabled)
return;
m_indirectLight = enabled;
emit indirectLightEnabledChanged();
emit changed();
}
void QQuick3DLightmapper::setSamples(int count)
{
if (m_samples == count)
return;
m_samples = count;
emit samplesChanged();
emit changed();
}
void QQuick3DLightmapper::setIndirectLightWorkgroupSize(int size)
{
if (m_workgroupSize == size)
return;
m_workgroupSize = size;
emit indirectLightWorkgroupSizeChanged();
emit changed();
}
void QQuick3DLightmapper::setBounces(int count)
{
if (m_bounces == count)
return;
m_bounces = count;
emit bouncesChanged();
emit changed();
}
void QQuick3DLightmapper::setIndirectLightFactor(float factor)
{
if (m_indirectFactor == factor)
return;
m_indirectFactor = factor;
emit indirectLightFactorChanged();
emit changed();
}
void QQuick3DLightmapper::setSource(const QString &source)
{
if (m_source == source)
return;
m_source = source;
emit sourceChanged();
emit changed();
}
float QQuick3DLightmapper::denoiseSigma() const
{
return m_denoiseSigma;
}
void QQuick3DLightmapper::setDenoiseSigma(float newDenoiseSigma)
{
if (qFuzzyCompare(m_denoiseSigma, newDenoiseSigma))
return;
m_denoiseSigma = newDenoiseSigma;
emit denoiseSigmaChanged();
emit changed();
}
float QQuick3DLightmapper::texelsPerUnit() const
{
return m_texelsPerUnit;
}
void QQuick3DLightmapper::setTexelsPerUnit(float newTexelsPerUnit)
{
if (qFuzzyCompare(m_texelsPerUnit, newTexelsPerUnit))
return;
m_texelsPerUnit = newTexelsPerUnit;
emit texelsPerUnitChanged();
emit changed();
}
QT_END_NAMESPACE
|