summaryrefslogtreecommitdiffstats
path: root/doc/src/07-file-formats/custom-materials-effects.qdoc
blob: 7a1521cc57b0a9f522f6e1680bd8d3ba7f5a39a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!

\title Custom Materials and Effects
\page custom-materials-effects.html
\ingroup qt3dstudio-file-formats

Qt 3D Studio supports custom \e{materials} and \e{layer effects}. These are arbitrary
GLSL shaders, wrapped in a file format providing an artist-friendly interface
for adjusting properties in Studio.

You can write your own materials and effects to use in Qt 3D Studio, this requires knowledge in
OpenGL Shading Language (GLSL).

This document explains the structure of the \c{.effect} and \c{.shader} files but does not go
through how to write shaders in GLSL.

\sa {Custom Material Reference}, {Effect Reference}

\section1 Overview

The general structure of an \c{.effect} and a \c{.shader} is almost the same.
The only different is the \c{<Effect>} and the \c{<Material>} elements.

\note Some of the attributes and elements shown here are optional (and this example does not
include all possible attributes).

The structure of an \c{.effect} file. As mentioned above the same structure applies to
\c{.shader} files as well with the only difference that you will need to use \c{<Material>} and
\c{</Material>} instead of \c{<Effect>} and \c{</Effect>}.

\badcode
<Effect>
    <MetaData>
        <Property name="..."/>
        <Property name="..."/>
    </MetaData>
    <Shaders>
        <Shared>
        </Shared>
        <Shader>
            <FragmentShader>
            </FragmentShader>
        </Shader>
        <Shader>
            <VertexShader>
            </VertexShader>
        </Shader>
    </Shaders>
    <Passes>
        <Buffer name="..."/>
        <Pass>
            <DepthInput/>
        </Pass>
        <Pass>
            <BufferInput/>
        </Pass>
    </Passes>
</Effect>
\endcode

\section1 Elements

\section2 \c{<Effect>}
The \c{<Effect>} element is the root element of the document. Everything in the document needs
to be wrapped in the \c{<Effect>} element.

\section2 \c{<MetaData>}
The \c{<MetaData>} element can contain zero or more \c{<Property>} elements. The \c{<MetaData>}
element is optional.

\section2 \c{<Property>}
The \c{<Property>} element must be wrapped in the \c{<MetaData>} element. This element describes a
property of the \e{effect} or \e{material}. Most properties are by default visible and adjustable
in Studio. Below you can see an example on how properties might look in Studio.

\image effect-properties.png

A \c{property} element can have the following attributes:

\table
\header
    \li Attribute
    \li Value
    \li Default value
    \li Description
\row
    \li name
    \li Text
    \li -
    \li The internal name of the property (must be a unique identifier).
\row
    \li formalName
    \li Text
    \li The \e{name} property.
    \li The name to display in the \e{inspector palette}.
\row
    \li description
    \li Text
    \li -
    \li Tooltip to display in the \e{inspector palette}.
\row
    \li type
    \li \l{PropertyType}
    \li Float
    \li The type of the property.
\row
    \li min
    \li Float
    \li -
    \li Min value for numeric types.
\row
    \li max
    \li Float
    \li -
    \li Max value for numeric types.
\row
    \li default
    \li Text
    \li 0 or "".
    \li Default value.
\row
    \li animatable
    \li Boolean
    \li True
    \li Sets possibility to animate the property. Note that all types are not animatable.
\row
    \li hidden
    \li Boolean
    \li False
    \li Sets visibility in the \e{inspector palette}.
\row
    \li clamp
    \li Text
    \li Clamp
    \li For \c{Texture} type only, sets texture to \e{clamp} or \e{repeat}.
\row
    \li filter
    \li Text
    \li
    \li For \c{Texture} type only, sets texture filter to \e{nearest} or \e{linear}.
\row
    \li \l{list}
    \li Text
    \li -
    \li Creates UI dropdown list.
\endtable

The only required attribute in the \c{<property>} element is \c{name}.

If a numeric \c{property} has both a \c{max} and a \c{min} attribute specified it will appear as
a slide bar in Studio. Otherwise it will appear as a text box.

\target PropertyType
\section3 \c{PropertyType}

The \c{PropertyType} sets the property type for the element. The following property
types are valid:

\table
\header
    \li PropertyType
    \li Value
    \li Description
    \li Example
\row
    \li Boolean
    \li True or false.
    \li Boolean value, will show as a check box in Studio.
    \li \c{<Property type="Boolean" default="True"...}
\row
    \li Color
    \li RGB normalized decimal value.
    \li RGB color, will show as a color picker tool in Studio.
    \li \c{<Property type="Color" default="0.5 0.5 0.5"...}
\row
    \li Float
    \li Float
    \li Numeric value, will show as a text field in Studio.
    \li \c{<Property type="Float" default="0.5"...}
\row
    \li Float2
    \li Two float values.
    \li Two numeric values, will show as two text fields in Studio.
    \li \c{<Property type="Float2" default="0.5 0.75"...}
\row
    \li Font
    \li Font
    \li Will show as font selector in Studio.
    \li \c{<Property type="Font" default="Arial"...}
\row
    \li FontSize
    \li Long
    \li Size of font, will show as drop down in Studio.
    \li \c{<Property type="FontSize" default="36"...}
\row
    \li Image2D
    \li Image path
    \li Image file, will show as file selector in Studio.
    \li \c{<Property type="Image2D" default=".\maps\bump-map.png"...}
\row
    \li Texture
    \li Image path
    \li Image file to use as texture, will show as file selector in Studio.
    \li \c{<Property type="Texture" default=".\maps\bump-map.png"...}
\endtable

\section3 \c{<showifequal>} and \c{<hideifequal>}

It is possible to toggle the UI visibility of properties based on the value of other
properties using the \c{<showifequal>} and \c{<hideifequal>} elements.

Two attributes are required for these elements:

\table
\header
    \li Attribute
    \li Description
\row
    \li property
    \li The \c{name} of the property which value should effect the visibility.
\row
    \li value
    \li The \c{value} of the property at which the visibility should change.
\endtable

In the example code below the color picker tool for \c{backgroundColor} property will be visible
only when the \c{opacity} property value is equal to 0.

\badcode
<property name="opacity" formalName="Opacity" type="Float" min="0" max="1" />
<property name="backgroundColor" formalName="Background color" type="color">
    <showifequal property="opacity" value="0" />
</property>
\endcode

It is possible to use multiple \c{<showifequal>} and \c{<hideifequal>} elements within the same
\c{<property>} element. In these cases the visibility will toggle once either of the conditions
are met. In the example code below the color picker tool for \c{backgroundColor} property will
be visible either when \c{opacity} property value is equal to 0 or when \c{showAll} property
value is equal to \c{True}.

\badcode
<property name="showAll" formalName="Show all" type="Boolean" />
<property name="opacity" formalName="Opacity" type="Float" min="0" max="1" />
<property name="backgroundColor" formalName="Background color" type="color">
    <showifequal property="opacity" value="0" />
    <showifequal property="showAll" value="True" />
</property>
\endcode

\target list
\section3 The \c{list} attribute
It is possible to create a property that is displayed as a drop down menu in Studio. In order to
do that you will need to specify the \c{name} and \c{list} attributes for the \c{<property>}
element. The value for the \c{list} attribute needs to be a comma (,) or colon(:) separated text string.

In Studio this will display as a drop down menu with the four options \e{Right}, \e{Left}, \e{Up}
and \e{Down}. You can specify the default value with the \c{default} attribute, if not specified
it will be empty.

\badcode
<property name="alignment" list="Right:Left:Up:Down" Default="Up"/>
\endcode

Note that you will not need to specify \c{type} for the property.

\section2 \c{<Shaders>}
The \c{<Shaders>} element must contain at least one \c{<Shader>} element.

\section2 \c{<Shader>}
The \c{<Shader>} element must contain either one \c{<FragmentShader>} element or one
\c{<VertexShader>}.
The \c{<Shader>} element has one attribute, \c{name}. It is optional and should contain an
identifier-like name.

\badcode
<Shader name="tonemap">
\endcode

*/