1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qquick3dlightmapper_p.h"
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \qmltype Lightmapper
10 \inherits Object
11 \inqmlmodule QtQuick3D
12 \brief Specifies lightmap baking settings for a scene.
13 \since 6.4
14
15 Used when baking direct and indirect lighting. These settings are not
16 relevant at other times, such as when using already generated lightmaps to
17 render a scene.
18
19 \note As of Qt 6.4, lightmap baking is in an early technical preview state.
20 Changes to features, quality, and API are likely to happen in future releases.
21
22 The Lightmapper object works in combination with:
23
24 \list
25 \li \l Model::bakedLightmap and the associated \l BakedLightmap,
26 \li \l Model::usedInBakedLighting and \l Model::lightmapBaseResolution,
27 \li \l Light::bakeMode,
28 \li the engine's built-in lightmap baker.
29 \endlist
30
31 \sa {Lightmaps and Global Illumination}, {Qt Quick 3D - Baked Lightmap Example}
32 */
33
34/*!
35 \qmlproperty float Lightmapper::opacityThreshold
36
37 The opacity (alpha) threshold below which an object is ignored in ray -
38 mesh intersections when calculating lighting via raytracing. When the
39 opacity falls below the threshold, the model (submesh) will not occlude
40 lights and thus will not generate shadows either.
41
42 The default value is 0.5.
43
44 \note The lightmapper takes the \l{PrincipledMaterial::opacity}{material's
45 opacity} and the \l{PrincipledMaterial::baseColor}{baseColor alpha}
46 combined with the \l{PrincipledMaterial::baseColorMap}{base color map's
47 alpha} into account. Other sources of semi-transparency, such as the
48 opacity map or alpha cut-off settings are ignored during the lightmap
49 baking process.
50 */
51
52/*!
53 \qmlproperty float Lightmapper::bias
54
55 Raycasting bias used during baking. Adapt the value in case artifacts
56 occur, for example in order to reduce undesired shadowing patterns. In many
57 cases the default value is sufficient.
58
59 The default value is 0.005.
60 */
61
62/*!
63 \qmlproperty bool Lightmapper::adaptiveBiasEnabled
64
65 Enables applying an additional, dynamic bias based on the surface normal.
66
67 The default value is true.
68 */
69
70/*!
71 \qmlproperty bool Lightmapper::indirectLightEnabled
72
73 Normally there is no need to change this value. The default value is true.
74 Setting this property to false disables indirect light computation during
75 lightmap baking. Thus the resulting texture maps will only contain direct
76 light information. At run time, the engine will continue to use the maps
77 normally, assuming they contain both direct and indirect lighting.
78 */
79
80/*!
81 \qmlproperty int Lightmapper::samples
82
83 The number of samples per lightmap texel.
84
85 The default value is 256.
86
87 The value heavily affects both the performance and quality of the resulting
88 lightmaps during lightmap baking.
89 */
90
91/*!
92 \qmlproperty int Lightmapper::indirectLightWorkgroupSize
93
94 The size of the sample workgroups. These workgroups are attempted to be
95 executed in parallel. (the exact behavior depends on the number of CPU
96 cores and the QThreadPool configuration)
97
98 The default value is 32. With the default sample count of 256 this means
99 attempting to run 8 groups in parallel per model.
100 */
101
102/*!
103 \qmlproperty int Lightmapper::bounces
104
105 The maximum number of indirect light bounces per sample. The value should
106 at least be 1, no point in indirect light calculation otherwise.
107
108 The default value is 3.
109
110 The value heavily affects both the performance and quality of the resulting
111 lightmaps during lightmap baking.
112*/
113
114/*!
115 \qmlproperty float Lightmapper::indirectLightFactor
116
117 Multiplier for the indirect light amount. While it is the value of 1 (i.e.,
118 not affecting the indirect light amount calculation) that provides the
119 strictly correct rendering results, a slightly higher value can often give
120 better looking results when using the lightmap, even with a lower number of
121 bounces.
122
123 The default value is 1.
124 */
125
126float QQuick3DLightmapper::opacityThreshold() const
127{
128 return m_opacityThreshold;
129}
130
131float QQuick3DLightmapper::bias() const
132{
133 return m_bias;
134}
135
136bool QQuick3DLightmapper::isAdaptiveBiasEnabled() const
137{
138 return m_adaptiveBias;
139}
140
141bool QQuick3DLightmapper::isIndirectLightEnabled() const
142{
143 return m_indirectLight;
144}
145
146int QQuick3DLightmapper::samples() const
147{
148 return m_samples;
149}
150
151int QQuick3DLightmapper::indirectLightWorkgroupSize() const
152{
153 return m_workgroupSize;
154}
155
156int QQuick3DLightmapper::bounces() const
157{
158 return m_bounces;
159}
160
161float QQuick3DLightmapper::indirectLightFactor() const
162{
163 return m_indirectFactor;
164}
165
166void QQuick3DLightmapper::setOpacityThreshold(float opacity)
167{
168 if (m_opacityThreshold == opacity)
169 return;
170
171 m_opacityThreshold = opacity;
172 emit opacityThresholdChanged();
173 emit changed();
174}
175
176void QQuick3DLightmapper::setBias(float bias)
177{
178 if (m_bias == bias)
179 return;
180
181 m_bias = bias;
182 emit biasChanged();
183 emit changed();
184}
185
186void QQuick3DLightmapper::setAdaptiveBiasEnabled(bool enabled)
187{
188 if (m_adaptiveBias == enabled)
189 return;
190
191 m_adaptiveBias = enabled;
192 emit adaptiveBiasEnabledChanged();
193 emit changed();
194}
195
196void QQuick3DLightmapper::setIndirectLightEnabled(bool enabled)
197{
198 if (m_indirectLight == enabled)
199 return;
200
201 m_indirectLight = enabled;
202 emit indirectLightEnabledChanged();
203 emit changed();
204}
205
206void QQuick3DLightmapper::setSamples(int count)
207{
208 if (m_samples == count)
209 return;
210
211 m_samples = count;
212 emit samplesChanged();
213 emit changed();
214}
215
216void QQuick3DLightmapper::setIndirectLightWorkgroupSize(int size)
217{
218 if (m_workgroupSize == size)
219 return;
220
221 m_workgroupSize = size;
222 emit indirectLightWorkgroupSizeChanged();
223 emit changed();
224}
225
226void QQuick3DLightmapper::setBounces(int count)
227{
228 if (m_bounces == count)
229 return;
230
231 m_bounces = count;
232 emit bouncesChanged();
233 emit changed();
234}
235
236void QQuick3DLightmapper::setIndirectLightFactor(float factor)
237{
238 if (m_indirectFactor == factor)
239 return;
240
241 m_indirectFactor = factor;
242 emit indirectLightFactorChanged();
243 emit changed();
244}
245
246QT_END_NAMESPACE
247

source code of qtquick3d/src/quick3d/qquick3dlightmapper.cpp