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-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
11Level of Detail (LoD) refers to the technique of using alternative versions of a 3D
12model at different distances from the camera. The goal of doing this is to optimize
13resource usage by using simpler versions of the model when it is far away or a small
14share of the screen, while using more detailed versions when it is closer or larger
15portion of screen space. This approach allows for efficient use of GPU resources
16while maintaining visual fidelity.
17
18Qt Quick 3D provides both an automatic as well as an explicit level of detail system.
19The automatic system is based on using a single mesh with multiple levels of detail
20stored in the mesh file. The explicit system is based on using a LodManager component
21to specify the different levels of detail as child models.
22
23\section1 Automatic Level of Detail
24
25The primary way to use the the automatic level of detail support is by importing
26content with the \l {Balsam Asset Import Tool}. By using the flag
27\c {--generateMeshLevelsOfDetail} when importing assets, the tool will generate
28levels of detail for each mesh when possible. This is done by trying to simplify the
29geometry of the original mesh, while still maintaining the overall features. What
30results is additional geometry as well as new index values for each additional
31level of detail, as well as a distance factor used to determine which
32mesh to use for a given render size. This distance factor is related to the distance
33of the object being rendered to the camera, but the most important thing is having a
34good ratio of geometry per pixel. This data is written to the .mesh file and will
35be used automatically when used by a Model.
36
37\image lod_balsamui.png
38 {Balsam UI settings with LOD generation option highlighted}
39
40A tradeoff to the automatic system, and the reason why it is not enabled by default
41is that it is possible that when the geometry is reduced, visual artifacts can also
42be introduced. The geometry simplification algorithm used attempts to preserve
43the features of the model, but in some cases it may be necessary to recalculate
44the normals of the mesh to maintain the intended visual appearance. This can be
45done by using the \c {--recalculateLodNormals} flag when importing the asset.
46The normal recalculation process can be further tuned by passing euler angle
47values to the arguments \c {--recalculateLodNormalsMergeAngle} and
48\c {--recalculateLodNormalsSplitAngle} to control the angle at which normals
49are merged or split respectively.
50
51The main advantage of the automatic system is that it is easy to use once the
52asset has been imported with the appropriate settings. No additional code is
53required to use the automatic system and any Models that reference the generated
54mesh files containing levels of detail geometry will automatically choose the
55appropriate geometry based on how many pixels the model takes up on the screen.
56
57It is possible to tweak automatic level of detail selection behavior
58either at the \l {Camera::levelOfDetailBias}{global level} or at the
59\l {Model::levelOfDetailBias}{per-model level} by using the \c levelOfDetailBias
60property of either \l Camera or \l Model. The default level of 1.0 of each
61of these bias properties means to trust the value calculated by the automatic
62system. This value is a bias to the ideal value such that a value smaller
63than 1.0 will require an even smaller rendered size before switching to a
64lesser level of detail. Values above 1.0 will lead to lower levels of detail
65being used sooner. A value of 0.0 will disable the usage of levels of detail
66completely and always use the original mesh geometry.
67
68The automatic system is not as flexible as the explicit system. For example
69the automatic system always uses the same material for all levels of detail,
70which may not always be desirable. Another potential downside is that there
71is not transition between the different levels of detail which ideally
72should not be necessary with automatic level of detail, but may be desireable
73for certain use cases.
74
75\section1 Explicit Level of Detail
76
77The Explicit level of detail system is more flexible than the automatic
78system, but requires more work to use. The explicit system is based on using
79a LodManager component to specify the different levels of detail as child
80\l Model components. Any children of the LodManager that are instances of Model
81will be considered a level of detail. This is quite powerful because each level of
82detail can be a completely custom model, with it's own geometries and materials.
83
84The LodManager component also has a \l {LodManager::distances}{distances} property which is used to
85determine which child \l Model to use. The LodManager node will transition to the
86next child \l Model as the camera distance approach each distance boundary.
87The \l {LodManager::fadeDistance}{fadeDistance} property can be used to set at which
88distance the cross fade transition begins and ends around the distances boundaries.
89
90This is an \l {Qt Quick 3D - Level of Detail Helper Example}{example} of how to use
91the explicit level of detail system:
92
93\image lodhelper-example.jpg
94 {Bust sculpture with instanced objects at varying detail levels}
95
96In the referenced example the \l LodManager is used to explicitly specify different mesh
97files for each level of detail of the marble bust.
98
99\snippet lodhelper/main.qml example
100
101For this code this is a diagram of what is being defined which points out how the distances
102list is used to define where the boundaries between the different levels of detail as well
103as the fadeDistance property which is used to define the cross fade transition.
104
105\image lodmanager_diagram.png {LOD system architecture diagram}
106
107*/