Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qtquick3d-lod.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qtquick3d-lod.html
6
\title Qt Quick 3D Level of Detail
7
\brief An overview of the usages of Level of Detail in Qt Quick 3D.
8
9
\section1 Level of Detail (LoD)
10
11
Level of Detail (LoD) refers to the technique of using alternative versions of a 3D
12
model at different distances from the camera. The goal of doing this is to optimize
13
resource usage by using simpler versions of the model when it is far away or a small
14
share of the screen, while using more detailed versions when it is closer or larger
15
portion of screen space. This approach allows for efficient use of GPU resources
16
while maintaining visual fidelity.
17
18
Qt Quick 3D provides both an automatic as well as an explicit level of detail system.
19
The automatic system is based on using a single mesh with multiple levels of detail
20
stored in the mesh file. The explicit system is based on using a LodManager component
21
to specify the different levels of detail as child models.
22
23
\section1 Automatic Level of Detail
24
25
The primary way to use the the automatic level of detail support is by importing
26
content with the \l {Balsam Asset Import Tool}. By using the flag
27
\c {--generateMeshLevelsOfDetail} when importing assets, the tool will generate
28
levels of detail for each mesh when possible. This is done by trying to simplify the
29
geometry of the original mesh, while still maintaining the overall features. What
30
results is additional geometry as well as new index values for each additional
31
level of detail, as well as a distance factor used to determine which
32
mesh to use for a given render size. This distance factor is related to the distance
33
of the object being rendered to the camera, but the most important thing is having a
34
good ratio of geometry per pixel. This data is written to the .mesh file and will
35
be used automatically when used by a Model.
36
37
\image lod_balsamui.png
38
{Balsam UI settings with LOD generation option highlighted}
39
40
A tradeoff to the automatic system, and the reason why it is not enabled by default
41
is that it is possible that when the geometry is reduced, visual artifacts can also
42
be introduced. The geometry simplification algorithm used attempts to preserve
43
the features of the model, but in some cases it may be necessary to recalculate
44
the normals of the mesh to maintain the intended visual appearance. This can be
45
done by using the \c {--recalculateLodNormals} flag when importing the asset.
46
The normal recalculation process can be further tuned by passing euler angle
47
values to the arguments \c {--recalculateLodNormalsMergeAngle} and
48
\c {--recalculateLodNormalsSplitAngle} to control the angle at which normals
49
are merged or split respectively.
50
51
The main advantage of the automatic system is that it is easy to use once the
52
asset has been imported with the appropriate settings. No additional code is
53
required to use the automatic system and any Models that reference the generated
54
mesh files containing levels of detail geometry will automatically choose the
55
appropriate geometry based on how many pixels the model takes up on the screen.
56
57
It is possible to tweak automatic level of detail selection behavior
58
either at the \l {Camera::levelOfDetailBias}{global level} or at the
59
\l {Model::levelOfDetailBias}{per-model level} by using the \c levelOfDetailBias
60
property of either \l Camera or \l Model. The default level of 1.0 of each
61
of these bias properties means to trust the value calculated by the automatic
62
system. This value is a bias to the ideal value such that a value smaller
63
than 1.0 will require an even smaller rendered size before switching to a
64
lesser level of detail. Values above 1.0 will lead to lower levels of detail
65
being used sooner. A value of 0.0 will disable the usage of levels of detail
66
completely and always use the original mesh geometry.
67
68
The automatic system is not as flexible as the explicit system. For example
69
the automatic system always uses the same material for all levels of detail,
70
which may not always be desirable. Another potential downside is that there
71
is not transition between the different levels of detail which ideally
72
should not be necessary with automatic level of detail, but may be desireable
73
for certain use cases.
74
75
\target instanced-lod
76
\section2 Instanced models
77
78
A \l Model drawn with \l {Instancing}{instancing} does not get one level of
79
detail for the whole model: the instances can be spread over a large area, and
80
one distance would not fit them all. Instead, each instance gets its own level,
81
selected the same way as for a model without instancing: with the same ratios
82
and the same \c levelOfDetailBias, by the depth along the view direction to the
83
nearest point of the bounds, which for an instance is a sphere around it. The
84
scale of an instance counts like the scale of a model: an instance that is drawn
85
twice as large switches level at twice the distance. With an
86
\l OrthographicCamera the distance does not change the size on screen, so the
87
level of each instance follows its scale and the magnification of the camera.
88
89
At most 12 levels are used for the instances: the original geometry and the
90
first 11 levels of detail of the mesh. Instances that would get a coarser level
91
get the last of these. \l {Model::instancingLodFactor}{instancingLodFactor} can
92
still select any level of the mesh.
93
94
Each level is drawn with a draw call of its own, with its instances in the
95
order of the instance table. \c INSTANCE_INDEX in a \l CustomMaterial is still
96
the row of each instance in the instance table.
97
98
The levels are selected on the CPU, going through all the instances, so this
99
increases the frame preparation time with large instance counts, as
100
\l {Instancing::depthSortingEnabled}{depth sorting} does. This is done again
101
when the model, the instance table or the camera changes, and not while they
102
all stand still. A model with \l {Model::instancingLodMin}{instancingLodMin}
103
or \l {Model::instancingLodMax}{instancingLodMax} that is drawn in several
104
views with cameras in different places is the exception: its range, and so its
105
levels, are selected again for each view in every frame.
106
107
When the camera has \l {Camera::frustumCullingEnabled}{frustumCullingEnabled}
108
set, this also leaves out the instances that are entirely outside the view of
109
the camera, which otherwise would be processed by the GPU only to be clipped.
110
This is not done when the view renders several views at once, as for XR, where
111
the instances are drawn once for all of them.
112
113
The level is selected for each instance when the mesh has levels of detail
114
with an index buffer and level of detail is enabled on both the model and the
115
camera (see \l {Model::levelOfDetailBias}{Model.levelOfDetailBias} and
116
\l {Camera::levelOfDetailBias}{Camera.levelOfDetailBias}). In the following
117
cases, all the instances get one level instead:
118
119
\list
120
\li The model sets \l {Model::instancingLodFactor}{instancingLodFactor}, which
121
picks one level for all the instances by hand, from \c 0.0 for the original
122
geometry to \c 1.0 for the coarsest level.
123
\li The instance table is \l {Instancing::depthSortingEnabled}{depth sorted}.
124
It is drawn in one draw call, in the sorted order. Drawn level by level, the
125
instances would only be back to front within each level, as a larger
126
instance switches level farther away than a smaller one, and
127
semi-transparent instances could blend in the wrong order.
128
\endlist
129
130
The level is then the one given by \c instancingLodFactor, which is the
131
original geometry when it is not set.
132
133
To draw semi-transparent instances with a level for each instance, leave the
134
instance table unsorted and set
135
\l {SceneEnvironment::oitMethod}{SceneEnvironment.oitMethod} instead. Order
136
independent transparency blends the instances in the right order whatever
137
order they are drawn in.
138
139
\l {Model::instancingLodMin}{instancingLodMin} and
140
\l {Model::instancingLodMax}{instancingLodMax} limit the instances a model
141
draws to a range of distances from the camera, in every pass. The level is
142
then selected among the instances in the range, so a model can leave out the
143
instances beyond some distance and still get the automatic level for the
144
rest. Several models can also share one instance table and draw different
145
ranges of it, each with its own material, and with the automatic level or
146
with a level chosen by \c instancingLodFactor.
147
148
When the level is selected for each instance, the shadow maps, reflection
149
probes and motion vectors are drawn with the original geometry instead. They
150
draw all the instances in the range of
151
\c instancingLodMin and \c instancingLodMax, also those outside the view of the
152
camera.
153
154
To see which level each model or instance is drawn with, set
155
\l {DebugSettings::drawLevelsOfDetail}{DebugSettings.drawLevelsOfDetail}.
156
157
\section1 Explicit Level of Detail
158
159
The Explicit level of detail system is more flexible than the automatic
160
system, but requires more work to use. The explicit system is based on using
161
a LodManager component to specify the different levels of detail as child
162
\l Model components. Any children of the LodManager that are instances of Model
163
will be considered a level of detail. This is quite powerful because each level of
164
detail can be a completely custom model, with it's own geometries and materials.
165
166
The LodManager component also has a \l {LodManager::distances}{distances} property which is used to
167
determine which child \l Model to use. The LodManager node will transition to the
168
next child \l Model as the camera distance approach each distance boundary.
169
The \l {LodManager::fadeDistance}{fadeDistance} property can be used to set at which
170
distance the cross fade transition begins and ends around the distances boundaries.
171
172
This is an \l {Qt Quick 3D - Level of Detail Helper Example}{example} of how to use
173
the explicit level of detail system:
174
175
\image lodhelper-example.jpg
176
{Bust sculpture with instanced objects at varying detail levels}
177
178
In the referenced example the \l LodManager is used to explicitly specify different mesh
179
files for each level of detail of the marble bust.
180
181
When a child of the LodManager is a model that uses
182
\l {Instancing}{instancing}, the LodManager sets its
183
\l {Model::instancingLodMin}{instancingLodMin} and
184
\l {Model::instancingLodMax}{instancingLodMax} from the distances instead of
185
its visibility, so that each instance is drawn by the child that matches its
186
own distance, and such children are not cross-faded. When the geometry of such a child
187
has levels of detail of its own, the level of each instance in its range is
188
also selected \l {instanced-lod}{automatically}. Set
189
\l {Model::instancingLodFactor}{instancingLodFactor} to \c 0.0 on the child to
190
draw its original geometry instead.
191
192
\snippet lodhelper/main.qml example
193
194
For this code this is a diagram of what is being defined which points out how the distances
195
list is used to define where the boundaries between the different levels of detail as well
196
as the fadeDistance property which is used to define the cross fade transition.
197
198
\image lodmanager_diagram.png {LOD system architecture diagram}
199
200
*/
qtquick3d
src
quick3d
doc
src
qtquick3d-lod.qdoc
Generated on
for Qt by
1.18.0