Debian Codegraph @

Docs/README.effects

raw
1 Effects
2 -------
3
4 Effects describe the graphical appearance of 3d objects and scenery in
5 FlightGear. The main motivation for effects is to support OpenGL
6 shaders and to provide different implementations for graphics hardware
7 of varying capabilities. Effects are similar to DirectX effects files
8 and Ogre3D material scripts.
9
10 An effect is a property list. The property list syntax is extended
11 with new "vec3d" and "vec4d" types to support common computer graphics
12 values. Effects are read from files with a ".eff" extension or can be
13 created on-the-fly by FlightGear at runtime. An effect consists of a
14 "parameters" section followed by "technique" descriptions. The
15 "parameters" section is a tree of values that describe, abstractly,
16 the graphical characteristics of objects that use the effect. Techniques
17 refer to these parameters and use them to set OpenGL state or to set
18 parameters for shader programs. The names of properties in the
19 parameter section can be whatever the effects author chooses, although
20 some standard parameters are set by FlightGear itself. On the other
21 hand, the properties in the techniques section are all defined by the
22 FlightGear.
23
24 Techniques
25 ----------
26
27 A technique can contain a predicate that describes the OpenGL
28 functionality required to support the technique. The first
29 technique with a valid predicate in the list of techniques is used
30 to set up the graphics state of the effect. A technique with no
31 predicate is always assumed to be valid. The predicate is written in a
32 little expression language that supports the following primitives:
33
34 and, or, equal, less, less-equal
35 glversion - returns the version number of OpenGL
36 extension-supported - returns true if an OpenGL extension is supported
37 property - returns the boolean value of a property
38 float-property - returns the float value of a property, useful inside equal, less
39 or less-equal nodes
40 shader-language - returns the version of GLSL supported, or 0 if there is none.
41
42 The proper way to test whether to enable a shader-based technique is:
43 <predicate>
44 <and>
45 <property>/sim/rendering/shader-effects</property>
46 <less-equal>
47 <value type="float">1.0</value>
48 <shader-language/>
49 </less-equal>
50 </and>
51 </predicate>
52
53 There is also a property set by the user to indicate what is the level
54 of quality desired. This level of quality can be checked in the predicate
55 like this :
56 <predicate>
57 <and>
58 <property>/sim/rendering/shader-effects</property>
59 <less-equal>
60 <value type="float">2.0</value>
61 <float-property>/sim/rendering/quality-level</float-property>
62 </less-equal>
63 <!-- other predicate conditions -->
64 </and>
65 </predicate>
66
67 The range of /sim/rendering/quality-level is [0..5]
68 * 2.0 is the threshold for relief mapping effects,
69 * 4.0 is the threshold for geometry shader usage.
70
71 A technique can consist of several passes. A pass is basically an Open
72 Scene Graph StateSet. Ultimately all OpenGL and OSG modes and state
73 attributes will be accessable in techniques. State attributes -- that
74 is, technique properties that have children and are not just boolean
75 modes -- have an <active> parameter which enables or disables the
76 attribute. In this way a technique can declare parameters it needs,
77 but not enable the attribute at all if it is not needed; the decision
78 can be based on a parameter in the parameters section of the
79 effect. For example, effects that support transparent and opaque
80 geometry could have as part of a technique:
81
82 <blend>
83 <active><use>blend/active</use></active>
84 <source>src-alpha</source>
85 <destination>one-minus-src-alpha</destination>
86 </blend>
87
88 So if the blend/active parameter is true blending will be activated
89 using the usual blending equation; otherwise blending is disabled.
90
91 Values of Technique Attributes
92 ------------------------------
93
94 Values are assigned to technique properties in several ways:
95
96 * They can appear directly in the techniques section as a
97 constant. For example:
98 <uniform>
99 <name>ColorsTex</name>
100 <type>sampler-1d</type>
101 <value type="int">2</value>
102 </uniform>
103 * The name of a property in the parameters section can be
104 referenced using a "use" clause. For example, in the technique
105 section:
106 <material>
107 <ambient><use>material/ambient</use></ambient>
108 </material>
109 Then, in the parameters section of the effect:
110 <parameters>
111 <material>
112 <ambient type="vec4d">0.2 0.2 0.2 1.0</ambient>
113 </material>
114 </parameters>
115
116 It's worth pointing out that the "material" property in a
117 technique specifies part of OpenGL's state, whereas "material"
118 in the parameters section is just a name, part of a
119 hierarchical namespace.
120
121 * A property in the parameters section doesn't need to contain
122 a constant value; it can also contain a "use" property. Here
123 the value of the use clause is the name of a node in an
124 external property tree which will be used as the source of a
125 value. If the name begins with '/', the node is in
126 FlightGear's global property tree; otherwise, it is in a local
127 property tree, usually belonging to a model [NOT IMPLEMENTED
128 YET]. For example:
129 <parameters>
130 <chrome-light><use>/rendering/scene/chrome-light</use></chrome-light>
131 </parameters>
132 The type is determined by what is expected by the technique
133 attribute that will ultimately receive the value. [There is
134 no way to get vector values out of the main property system
135 yet; this will be fixed shortly.] Values that are declared
136 this way are dynamically updated if the property node
137 changes.
138
139 OpenGL Attributes
140 -----------------
141
142 The following attributes are currently implemented in techiques:
143 alpha-test - children: active, comparison, reference
144 Valid values for comparision:
145 never, less, equal, lequal, greater, notequal, gequal,
146 always
147
148 alpha-to-coverage - true, false
149
150 blend - children: active, source, destination, source-rgb,
151 source-alpha, destination-rgb, destination-alpha
152 Each operand can have the following values:
153 dst-alpha, dst-color, one, one-minus-dst-alpha,
154 one-minus-dst-color, one-minus-src-alpha,
155 one-minus-src-color, src-alpha, src-alpha-saturate,
156 src-color, constant-color, one-minus-constant-color,
157 constant-alpha, one-minus-constant-alpha, zero
158
159 cull-face - front, back, front-back
160
161 lighting - true, false
162
163 material - children: active, ambient, ambient-front, ambient-back, diffuse,
164 diffuse-front, diffuse-back, specular, specular-front,
165 specular-back, emissive, emissive-front, emissive-back, shininess,
166 shininess-front, shininess-back, color-mode
167
168 polygon-mode - children: front, back
169 Valid values:
170 fill, line, point
171
172 program
173 vertex-shader
174 geometry-shader
175 fragment-shader
176 attribute
177 geometry-vertices-out - integer, max number of vertices emitted by geometry
178 shader
179 geometry-input-type - points, lines, lines-adjacency, triangles,
180 triangles-adjacency
181 geometry-output-type - points, line-strip, triangle-strip
182
183 render-bin - (OSG) children: bin-number, bin-name
184
185 rendering-hint - (OSG) opaque, transparent
186
187 shade-model - flat, smooth
188
189 texture-unit - has several child properties:
190 unit - The number of an OpenGL texture unit
191 point-sprite - true, false - Whether this should rendered as a point-sprite
192 type - This is either an OpenGL texture type or the name of a
193 builtin texture. Currently supported OpenGL types are 1d, 2d,
194 3d which have the following common parameters:
195 image (file name)
196 filter - nearest, linear, [nearest|linear]-mipmap-[nearest|linear]
197 mag-filter - nearest, linear, [nearest|linear]-mipmap-[nearest|linear]
198 wrap-s - clamp, clamp-to-border, clamp-to-edge, mirror, repeat
199 wrap-t - clamp, clamp-to-border, clamp-to-edge, mirror, repeat
200 wrap-r - clamp, clamp-to-border, clamp-to-edge, mirror, repeat
201 mipmap-control - control the mipmap on a per-channel basis. Children:
202 function-r - auto, average, sum, product, min, max
203 function-g - auto, average, sum, product, min, max
204 function-b - auto, average, sum, product, min, max
205 function-a - auto, average, sum, product, min, max
206
207 The following built-in types are supported:
208 white - 1 pixel white texture
209 noise - a 3d noise texture. (size parameter defines size of texture)
210 light-sprite - a procedurally generated sprite suitable for point lights
211 cubemap - build a cube-map. Children:
212 images - build from 6 images. Children: [positive|negative]-[x|y|z]
213 image - build from a single cross-image
214
215 environment
216 mode - add, blend, decal, modulate, replace
217 color
218
219 texenv-combine
220 combine-[rgb|alpha] - replace, modulate, add, add-signed, interpolate, subtract, dot3-rgb, dot3-rgba
221 source[0|1|2]-[rgb|alpha] - constant, primary_color, previous, texture, texture[0-7]
222 operand[0|1|2]-[rgb|alpha] -src-color, one-minus-src-color, src-alpha, one-minus-src-alpha
223 scale-[rgb|alpha]
224 constant-color
225
226 texgen
227 mode - object-linear, eye-linear, sphere-map, normal-map, reflection-map
228 planes - s, t, r, q
229
230 uniform
231 name
232 type - float, float-vec3, float-vec4, sampler-1d, sampler-2d,
233 sampler-3d
234
235 vertex-program-two-side - true, false
236
237 vertex-program-point-size - true, false
238
239 Inheritance
240 -----------
241
242 One feature not fully illustrated in the sample below is that
243 effects can inherit from each other. The parent effect is listed in
244 the "inherits-from" form. The child effect's property tree is
245 overlaid over that of the parent. Nodes that have the same name and
246 property index -- set by the "n=" attribute in the property tag --
247 are recursively merged. Leaf property nodes from the child have
248 precedence. This means that effects that inherit from the example
249 effect below could be very short, listing just new
250 parameters and adding nothing to the techniques section;
251 alternatively, a technique could be altered or customized in a
252 child, listing (for example) a different shader program. An example
253 showing inheritance Effects/crop.eff, which inherits some if its
254 values from Effects/terrain-default.eff.
255
256 FlightGear directly uses effects inheritance to assign effects to 3D
257 models and terrain. As described below, at runtime small effects are
258 created that contain material and texture values in a "parameters"
259 section. These effects inherit from another effect which references
260 those parameters in its "techniques" section. The derived effect
261 overrides any default values that might be in the base effect's
262 parameters section.
263
264 Generate
265 --------
266
267 Often shader effects need tangent vectors to work properly. These
268 tangent vectors, usually called tangent and binormal, are computed
269 on the CPU and given to the shader as vertex attributes. These
270 vectors are computed on demand on the geometry using the effect if
271 the 'generate' clause is present in the effect file. Example :
272
273 <generate>
274 <tangent type="int">6</tangent>
275 <binormal type="int">7</binormal>
276 <normal type="int">8</normal>
277 </generate>
278
279 Valid subnodes of 'generate' are 'tangent', 'binormal' or 'normal'.
280 The integer value of these subnodes is the index of the attribute
281 that will hold the value of the vec3 vector. If 'normal' generation
282 is requested, the generated normals will replace those supplied by
283 the model or terrain, which is usually undesirable.
284
285 The generate clause is located under PropertyList in the xml file.
286
287 In order to be available for the vertex shader, these data should
288 be bound to an attribute in the program clause, like this :
289
290 <program>
291 <vertex-shader>my_vertex_shader</vertex-shader>
292 <attribute>
293 <name>my_tangent_attribute</name>
294 <index>6</index>
295 </attribute>
296 <attribute>
297 <name>my_binormal_attribute</name>
298 <index>7</index>
299 </attribute>
300 </program>
301
302 attribute names are whatever the shader uses. The index is the one
303 declared in the 'generate' clause. So because generate/tangent has
304 value 6 and my_tangent_attribute has index 6, my_tangent_attribute
305 holds the tangent value for the vertex.
306
307 Default Effects in Terrain Materials and Models
308 -----------------------------------------------
309
310 Effects for terrain work in this way: for each material type in
311 materials.xml an effect is created that inherits from a single default
312 terrain effect, Effects/terrain-default.eff. The parameters section of
313 the effect is filled in using the ambient, diffuse, specular,
314 emissive, shininess, and transparent fields of the material. The
315 parameters image, filter, wrap-s, and wrap-t are also initialized from
316 the material xml. Seperate effects are created for each texture
317 variant of a material.
318
319 Model effects are created by walking the OpenSceneGraph scene graph
320 for a model and replacing nodes (osg::Geode) that have state sets with
321 node that uses an effect instead. Again, a small effect is created
322 with parameters extracted from OSG objects; this effect inherits, by
323 default, from Effects/model-default.eff. A larger set of parameters is
324 created for model effects than for terrain because there is more
325 variation possible from the OSG model loaders than from the terrain
326 system. The parameters created are:
327
328 * material active, ambient, diffuse, specular, emissive,
329 shininess, color mode
330 * blend active, source, destination
331 * shade-model
332 * cull-face
333 * rendering-hint
334 * texture type, image, filter, wrap-s, wrap-t
335
336 Specifying Custom Effects
337 -------------------------
338
339 You can specify the effects that will be used by FlightGear as the
340 base effect when it creates terrain and model effects.
341
342 In the terrain materials.xml, an "effect" property specifies the name
343 of the model to use.
344
345 In model .xml files, A richer syntax is supported. [TO BE DETERMINED]
346
347 Material animations will be implemented by creating a new effect
348 that inherits from one in a model, overriding the parameters that
349 will be animated.
350
351 Examples
352 --------
353
354 The Effects directory contains the effects definitions; look there for
355 examples. Effects/crop.eff is a good example of a complex effect.
356
357 Application
358 -----------
359
360 To apply an effect to a model or part of a model use:
361
362 <effect>
363 <inherits-from>Effects/light-cone</inherits-from>
364 <object-name>Cone</object-name>
365 </effect>
366
367 where <inherits-from> </inherits-from> contains the path to the effect you want to
368 apply. The effect does not need the file extension.
369
370 NOTE:
371
372 Chrome, although now implemented as an effect, still retains the old method of
373 application:
374
375 <animation>
376 <type>shader</type>
377 <shader>chrome</shader>
378 <texture>glass_shader.png</texture>
379 <object-name>windscreen</object-name>
380 </animation>
381
382 in order to maintain backward compatibility.
383
384 Model Hierarchy
385 ---------------
386
387 There are a large number of techniques used by the models, with complex
388 inheritance. Here is a handy list of the techniques, what they are for, and
389 where the base technique is defined
390
391 Model
392
393 # Where Defined Summary
394 4 model-combined.xml ALS, quality>0, model>0
395 5 model-default.xml ALS, basic
396 7 model-combined.xml quality>0, model>0
397 11 model-default.xml generic>0, quality>0
398 13 model-default.xml Fallback - no predicate
399
400
401 Scenery
402
403 # Where defined Summary
404 3 terrain-default.xml ALS, landmass=6, transition=6
405 4 terrain-default.xml ALS, landmass>3, transition>2
406 5 terrain-default.xml ALS, basic
407 11 terrain-default.xml Photoscenery, quality>0, generic>0
408 12 terrain-default.xml Fallback - no predicate