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
|
/****************************************************************************
**
** Copyright (C) 1993-2009 NVIDIA Corporation.
** Copyright (C) 2017 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 The .shader Format
\page file-formats-shader.html
\ingroup qt3dstudio-file-formats
Qt 3D Studio supports custom
materials used to render elements. Materials are arbitrary single-pass
GLSL shaders, wrapped in a file format providing an artist-friendly
interface for tweaking material parameters in Studio.
\section1 Overview
The general structure of a \c{.shader} file is shown below. Note
that some of the attributes and elements shown here are optional (and
this example does not include all possible attributes):
\badcode
<Material formalName="..." version="1.0">
<MetaData author="...">
<Property name="..." />
<Property name="..." />
</MetaData>
<Shaders type="GLSL">
<Shader>
<VertexShader>
<Source>...</Source>
</VertexShader>
<FragmentShader>
<Source>...</Source>
</FragmentShader>
</Shader>
</Shaders>
</Material>
\endcode
The actual code for the shader is placed within the
\c{<Source>} elements.
\section1 Schemata
Legal \c{.shader} files are described by the following formal
schemata. The RelaxNG Compact schema is the reference from which the XML
Schema Definition schema was derived.
\section2 RelaxNG Compact (\c{.rnc)}
\badcode
grammar \{
start = MaterialElement # Everything is wrapped in a <Material> element
MaterialElement = element Material \{
attribute version \{"1.0"\, }# This file describes version 1.0 only
attribute formalName \{text\?, }# The formalName attribute is optional; default: filename (minus extension)
attribute description \{text\?, }# Optional long description of the material
MetaDataElement?, # <MetaData> is optional,
ShadersElement # but <Shaders> is required
\}
MetaDataElement = element MetaData\{
attribute author \{text\?, }# Various descriptive attributes (optional)
attribute created \{text\?,}
attribute modified \{text\?,}
PropertyElement* # Zero or more <Property> elements
\}
PropertyElement = element Property \{ # All <Property> attributes are optional except for name
attribute name \{xsd:ID\, }# The internal, script name of the property (must be a unique identifier)
attribute description \{text\?, }# Tooltip to display in Inspector palette
attribute formalName \{text\?, }# The name to display in Inspector palette; default: the property `name`
attribute type \{PropertyType\?, }# The type of the property (defined below); default: Float
attribute min \{xsd:float\?, }# UI min value for numeric types; default: none
attribute max \{xsd:float\?, }# UI max value for numeric types; default: none
attribute default \{text\?, }# Default value for the property; default: 0/""
attribute usage \{UsageType\?, }# Only for textures; default: diffuse
attribute filter \{FilterType\?, }# Only for textures; default: linear
attribute clamp \{ClampType\? }# Only for textures; default: wrap
\}
ShadersElement = element Shaders \{
attribute type \{"GLSL" | "HLSL"\?, }# Optional shader type; only GLSL supported. default: GLSL
attribute version \{text\?, }# Code version
element Shared \{text\?, }# Arbitrary definition code to run for all shaders (optional)
ShaderElement+ # There must be at least one <Shader> in the .shader file
\}
ShaderElement = element Shader \{
attribute name \{xsd:NCName\?, }# An identifier-like name
((VSEl | FSEl) | (VSEl & FSEl)) # Either or both of <VertexShader> and <FragmentShader>, in either order
\}
VSEl = element VertexShader \{ShaderContent\}
FSEl = element FragmentShader \{ShaderContent\}
ShaderContent = element Source \{ text \ }# Shaders currently require a single <Source> element
UsageType = "diffuse" | "specular" | "bump" | "environment"
FilterType = "nearest" | "linear"
ClampType = "clamp" | "wrap"
PropertyType = "Boolean" | "Color" | "Float" | "Float2" | "Font"
| "FontSize" | "Image" | "Import" | "Long" | "Mesh"
| "MultiLineString" | "Rotation" | "String" | "Vector"
| "Texture" | "Texture3D" | "TextureCube"
\}
\endcode
\section2 XML Schema Definition (\c{.xsd)}
\badcode
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Material">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="MetaData"/>
<xs:element ref="Shaders"/>
</xs:sequence>
<xs:attribute name="version" use="required">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="1.0"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="formalName"/>
<xs:attribute name="description"/>
</xs:complexType>
</xs:element>
<xs:element name="MetaData">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="Property"/>
</xs:sequence>
<xs:attribute name="author"/>
<xs:attribute name="created"/>
<xs:attribute name="modified"/>
</xs:complexType>
</xs:element>
<xs:element name="Property">
<xs:complexType>
<xs:attribute name="name" use="required" type="xs:ID"/>
<xs:attribute name="description"/>
<xs:attribute name="formalName"/>
<xs:attribute name="type" type="PropertyType"/>
<xs:attribute name="min" type="xs:float"/>
<xs:attribute name="max" type="xs:float"/>
<xs:attribute name="default"/>
<xs:attribute name="usage" type="UsageType"/>
<xs:attribute name="filter" type="FilterType"/>
<xs:attribute name="clamp" type="ClampType"/>
</xs:complexType>
</xs:element>
<xs:element name="Shaders">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="Shared"/>
<xs:element maxOccurs="unbounded" ref="Shader"/>
</xs:sequence>
<xs:attribute name="type">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="GLSL"/>
<xs:enumeration value="HLSL"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="version"/>
</xs:complexType>
</xs:element>
<xs:element name="Shared" type="xs:string"/>
<xs:element name="Shader">
<xs:complexType>
<xs:choice>
<xs:choice>
<xs:element ref="VertexShader"/>
<xs:element ref="FragmentShader"/>
</xs:choice>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="VertexShader"/>
<xs:element ref="FragmentShader"/>
</xs:choice>
</xs:choice>
<xs:attribute name="name" type="xs:NCName"/>
</xs:complexType>
</xs:element>
<xs:element name="VertexShader" type="ShaderContent"/>
<xs:element name="FragmentShader" type="ShaderContent"/>
<xs:complexType name="ShaderContent">
<xs:sequence>
<xs:element ref="Source"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Source" type="xs:string"/>
<xs:simpleType name="UsageType">
<xs:restriction base="xs:token">
<xs:enumeration value="diffuse"/>
<xs:enumeration value="specular"/>
<xs:enumeration value="bump"/>
<xs:enumeration value="environment"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="FilterType">
<xs:restriction base="xs:token">
<xs:enumeration value="nearest"/>
<xs:enumeration value="linear"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ClampType">
<xs:restriction base="xs:token">
<xs:enumeration value="clamp"/>
<xs:enumeration value="wrap"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="PropertyType">
<xs:restriction base="xs:token">
<xs:enumeration value="Boolean"/>
<xs:enumeration value="Color"/>
<xs:enumeration value="Float"/>
<xs:enumeration value="Float2"/>
<xs:enumeration value="Font"/>
<xs:enumeration value="FontSize"/>
<xs:enumeration value="Image"/>
<xs:enumeration value="Import"/>
<xs:enumeration value="Long"/>
<xs:enumeration value="Mesh"/>
<xs:enumeration value="MultiLineString"/>
<xs:enumeration value="Rotation"/>
<xs:enumeration value="String"/>
<xs:enumeration value="Vector"/>
<xs:enumeration value="Texture"/>
<xs:enumeration value="Texture3D"/>
<xs:enumeration value="TextureCube"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
\endcode
*/
|