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-tool-shadergen.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2020 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qtquick3d-tool-shadergen.html
6
\title Shadergen Tool
7
\brief Command line tool for generating Qt Quick 3D material shaders at build-time.
8
\deprecated
9
10
The shadergen tool is a command line application that is part of Qt Quick 3D's
11
asset conditioning pipeline. It can be enable per project or run manually from the command line.
12
Pre-generating the material shaders can have a significant impact on the start-up time and/or avoid
13
unwanted stalls at run-time, as the processes of creating a material shader at run-time can be costly.
14
15
\note This tool was experimental and has now been deprecated. Pre-existing functionality will remain
16
as-is, but no new features or fixes will be added.
17
18
One of the biggest obstacles for the offline shader generator is the amount of different materials
19
that can be generated, not only based on the material properties themeself but also how the rest of
20
the scene is set-up; for example, light count, light type, shadows, etc. all affect the generated
21
shader(s). When we also take \l{Dynamic properties} {dynamic properties} into account, the share amount
22
of material shader permutations can very quickly make it unfeasible to generate them all at build-time.
23
To limit the amount of shaders the tool needs to generate, the tool tries to only generate the shaders
24
it think the application needs. The heuristics used in the tool might not always be able to detect
25
which materials should be generate, this is espcecially true for properties that change at run-time.
26
To verify that the material shaders were successfully, and correctly, generated, the tool should have
27
generated a \l{Generated content}{.qsbc} file which can be inspected to verify that the content
28
matches the material used by the application. It's also possible to verify that the material
29
was loaded from the pre-built cache by setting the environment variable \b QT_RHI_SHADER_DEBUG=1
30
and looking at the debug output for mentions of the engine loading the \b pregenerated
31
shader successfully.
32
33
Known limitations are:
34
\list
35
\li Scenes with more then one \l{View3D}.
36
\li Dynamically adding or removing lights are not supported when using generating materials.
37
\li The generated shaders are strictly tied to the Qt version used due to its dependency on
38
the internals of the renderer. Compatibility of the generated shaders can therefore
39
not be guaranteed between versions.
40
\endlist
41
42
\section1 Usage
43
44
To enable offline generation of material shaders in your project, add the following to your
45
project file:
46
47
CMake:
48
\code
49
qt6_add_materials(offlineshaders "shaders"
50
PREFIX
51
"/"
52
FILES
53
${qml_resource_files}
54
)
55
\endcode
56
57
Alternatively the shadergen tool can be invoked manually from the command line, like this:
58
59
\code
60
shadergen main.qml Material.qml
61
\endcode
62
63
Normally the shadergen tool should be run from your application's project folder, but it's also
64
possible to instruct the tool to change its current working directory through the \c -C argument.
65
66
If no output path is provided then the tool will write the generated files to the current
67
directory. The output path can be changed with the \c -o option.
68
69
Note that for the tool to generate the expected materials it will need to know about the whole
70
scene and not just the material(s), for example the number of lights in the scene does also
71
affect how the materials get generated, so all relevant qml files should be added to the list of
72
files the tool needs to process.
73
74
\section2 Command line arguments
75
76
\table
77
\header
78
\li
79
Short
80
\li
81
Full
82
\li
83
Description
84
\row
85
\li
86
-C <PATH>
87
\li
88
--directory <PATH>
89
\li
90
Changes the current directory to \c <PATH>. This argument is optional.
91
\row
92
\li
93
-o <PATH>
94
\li
95
--output-dir <PATH>
96
\li
97
Sets the output path to <PATH>. This is the location where the files generated by the tool
98
will be placed under. If no path is given the path is current directory.
99
\row
100
\li
101
-r <NAME>
102
\li
103
--resource-file <NAME>
104
\li
105
Changes the name of the generated resource file to \c <NAME>. This argument is optional.
106
\row
107
\li
108
-l <FILE>
109
\li
110
--list-qsbc <FILE>
111
\li
112
List the content of the qsbc file.
113
\endtable
114
115
\section1 Generated content
116
117
The shadergen tools main output file is a .qsbc file. The .qsbc file contains a collection of
118
\l {Qt Shader Tools} {.qsb} files plus some meta-data about the various material shaders,
119
such as the unique property string for each material. To inspect the content of the .qsbc file
120
you can use the \c -l argument with the shadergen tool, like this:
121
122
\code
123
shadergen -l qtappshaders.qsbc
124
\endcode
125
126
\sa {Qt Shader Tools} {QtShaderTools}
127
128
\section1 Dynamic properties
129
130
Since the tool is run at build-time it has limited ability to reason about which properties
131
might change at run-time. Properties where a value is only changing within the properties range, for
132
example the roughness value, will not have any affect on the generated material shader, but properties
133
that are either \b on or \b off, e.g., setting an image map at run-time, would require a different type of
134
material to be generated. It is therefore recommended that all variants of a material, which enables
135
or disables features in the material, or the scene, are declared as individual components, this will
136
help the tool to generated the correct material shaders.
137
138
The following example shows a contrived example of a material where we want to add a base color
139
map to a material at run-time. Note that the component \c MaterialRedExtended is never used in the example,
140
it's purely defined to help the shadergen tool generate the shaders needed to dynamically set the \c baseColorMap at run-time.
141
142
MaterialRed.qml
143
144
\snippet offlineshaders/MaterialRed.qml baseMaterial
145
146
MaterialRedExtended.qml
147
148
\snippet offlineshaders/MaterialRedExtended.qml extendedMaterial
149
150
main.qml
151
152
\snippet offlineshaders/main.qml redMaterial
153
154
\snippet offlineshaders/main.qml setMap
155
156
*/
qtquick3d
src
quick3d
doc
src
qtquick3d-tool-shadergen.qdoc
Generated on
for Qt by
1.16.1