Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
39A tradeoff to the automatic system, and the reason why it is not enabled by default
40is that it is possible that when the geometry is reduced, visual artifacts can also
41be introduced. The geometry simplification algorithm used attempts to preserve
42the features of the model, but in some cases it may be necessary to recalculate
43the normals of the mesh to maintain the intended visual appearance. This can be
44done by using the \c {--recalculateLodNormals} flag when importing the asset.
45The normal recalculation process can be further tuned by passing euler angle
46values to the arguments \c {--recalculateLodNormalsMergeAngle} and
47\c {--recalculateLodNormalsSplitAngle} to control the angle at which normals
48are merged or split respectively.
49
50The main advantage of the automatic system is that it is easy to use once the
51asset has been imported with the appropriate settings. No additional code is
52required to use the automatic system and any Models that reference the generated
53mesh files containing levels of detail geometry will automatically choose the
54appropriate geometry based on how many pixels the model takes up on the screen.
55
56It is possible to tweak automatic level of detail selection behavior
57either at the \l {Camera::levelOfDetailBias}{global level} or at the
58\l {Model::levelOfDetailBias}{per-model level} by using the \c levelOfDetailBias
59property of either \l Camera or \l Model. The default level of 1.0 of each
60of these bias properties means to trust the value calculated by the automatic
61system. This value is a bias to the ideal value such that a value smaller
62than 1.0 will require an even smaller rendered size before switching to a
63lesser level of detail. Values above 1.0 will lead to lower levels of detail
64being used sooner. A value of 0.0 will disable the usage of levels of detail
65completely and always use the original mesh geometry.
66
67The automatic system is not as flexible as the explicit system. For example
68the automatic system always uses the same material for all levels of detail,
69which may not always be desirable. Another potential downside is that there
70is not transition between the different levels of detail which ideally
71should not be necessary with automatic level of detail, but may be desireable
72for certain use cases.
73
74\section1 Explicit Level of Detail
75
76The Explicit level of detail system is more flexible than the automatic
77system, but requires more work to use. The explicit system is based on using
78a LodManager component to specify the different levels of detail as child
79\l Model components. Any children of the LodManager that are instances of Model
80will be considered a level of detail. This is quite powerful because each level of
81detail can be a completely custom model, with it's own geometries and materials.
82
83The LodManager component also has a \l {LodManager::distances}{distances} property which is used to
84determine which child \l Model to use. The LodManager node will transition to the
85next child \l Model as the camera distance approach each distance boundary.
86The \l {LodManager::fadeDistance}{fadeDistance} property can be used to set at which
87distance the cross fade transition begins and ends around the distances boundaries.
88
89This is an \l {Qt Quick 3D - Level of Detail Helper Example}{example} of how to use
90the explicit level of detail system:
91
92\image lodhelper-example.jpg
93
94In the referenced example the \l LodManager is used to explicitly specify different mesh
95files for each level of detail of the marble bust.
96
97\snippet lodhelper/main.qml example
98
99For this code this is a diagram of what is being defined which points out how the distances
100list is used to define where the boundaries between the different levels of detail as well
101as the fadeDistance property which is used to define the cross fade transition.
102
103\image lodmanager_diagram.png
104
105*/
106
107