Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G


Jump to: navigation, search

Effect Framework

7,289 bytes added, 04:50, 1 September 2019
Created page WIP
The effect framework as per version 2019.1

=Default Effects in Terrain Materials and Models=
Effects for terrain work in this way: for each material type in
materials.xml an effect is created that inherits from a single default
terrain effect, Effects/terrain-default.eff. The parameters section of
the effect is filled in using the ambient, diffuse, specular,
emissive, shininess, and transparent fields of the material. The
parameters image, filter, wrap-s, and wrap-t are also initialized from
the material xml. Seperate effects are created for each texture
variant of a material.

Model effects are created by walking the OpenSceneGraph scene graph
for a model and replacing nodes (osg::Geode) that have state sets with
node that uses an effect instead. Again, a small effect is created
with parameters extracted from OSG objects; this effect inherits, by
default, from Effects/model-default.eff. A larger set of parameters is
created for model effects than for terrain because there is more
variation possible from the OSG model loaders than from the terrain
system. The parameters created are:

* material active, ambient, diffuse, specular, emissive,
shininess, color mode
* blend active, source, destination
* shade-model
* cull-face
* rendering-hint
* texture type, image, filter, wrap-s, wrap-t

=Specifying Custom Effects=
You can specify the effects that will be used by FlightGear as the
base effect when it creates terrain and model effects.

In the terrain materials.xml, an "effect" property specifies the name
of the model to use.

In model .xml files, A richer syntax is supported. [TO BE DETERMINED]

Material animations will be implemented by creating a new effect
that inherits from one in a model, overriding the parameters that
will be animated.

The Effects directory contains the effects definitions; look there for
examples. Effects/crop.eff is a good example of a complex effect.

To apply an effect to a model or part of a model use:


where <inherits-from> </inherits-from> contains the path to the effect you want to apply.
The effect does not need the file extension.


Chrome, although now implemented as an effect, still retains the old method of application:


in order to maintain backward compatibility.

=The xml tags of an effect=

The name of the effect

One feature not fully illustrated in the sample below is that
effects can inherit from each other. The parent effect is listed in
the "inherits-from" form. The child effect's property tree is
overlaid over that of the parent. Nodes that have the same name and
property index -- set by the "n=" attribute in the property tag --
are recursively merged. Leaf property nodes from the child have
precedence. This means that effects that inherit from the example
effect below could be very short, listing just new
parameters and adding nothing to the techniques section;
alternatively, a technique could be altered or customized in a
child, listing (for example) a different shader program. An example
showing inheritance Effects/crop.eff, which inherits some if its
values from Effects/terrain-default.eff.

FlightGear directly uses effects inheritance to assign effects to 3D
models and terrain. As described below, at runtime small effects are
created that contain material and texture values in a "parameters"
section. These effects inherit from another effect which references
those parameters in its "techniques" section. The derived effect
overrides any default values that might be in the base effect's
parameters section.

Custom parameters that controls the effect.

A certain way of rendering this effect. Different pipelines typically have their own techniques.

Condition for this technique to be used. If this fails it will try the next technique in the effect.

What is passed to the shaders/OSG.
(Not sure, but think multiple passes are possible.)

true or false

children: active, ambient, ambient-front, ambient-back, diffuse,
diffuse-front, diffuse-back, specular, specular-front,
specular-back, emissive, emissive-front, emissive-back, shininess,
shininess-front, shininess-back, color-mode

Children: active, source, destination, source-rgb, source-alpha, destination-rgb, destination-alpha

Children values: dst-alpha, dst-color, one, one-minus-dst-alpha, one-minus-dst-color, one-minus-src-alpha, one-minus-src-color, src-alpha, src-alpha-saturate, src-color, constant-color, one-minus-constant-color, constant-alpha, one-minus-constant-alpha, zero

flat or smooth

front, back, front-back, off

Sent to OSG.

default, opaque, transparent


true or false

true, false

Data accessible by shaders.

bool, int, float, float-vec3, float-vec4, sampler-1d, sampler-2d, sampler-3d, sampler-1d-shadow, sampler-2d-shadow, sampler-cube


true, false

never, less, equal, lequal, greater, notequal, gequal, always


Sent to OSG.

RenderBin, DepthSortedBin

geometry-vertices-out: integer, max number of vertices emitted by geometry shader
geometry-input-type - points, lines, lines-adjacency, triangles, triangles-adjacency
geometry-output-type - points, line-strip, triangle-strip


Often shader effects need tangent vectors to work properly. These
tangent vectors, usually called tangent and binormal, are computed
on the CPU and given to the shader as vertex attributes. These
vectors are computed on demand on the geometry using the effect if
the 'generate' clause is present in the effect file. Exemple :

<tangent type="int">6</tangent>
<binormal type="int">7</binormal>
<normal type="int">8</normal>

Valid subnodes of 'generate' are 'tangent', 'binormal' or 'normal'.
The integer value of these subnode is the index of the attribute
that will hold the value of the vec3 vector.

The generate clause is located under PropertyList in the xml file.

In order to be available for the vertex shader, these data should
be bound to an attribute in the program clause, like this :


attribute names are whatever the shader use. The index is the one
declared in the 'generate' clause. So because generate/tangent has
value 6 and my_tangent_attribute has index 6, my_tangent_attribute
holds the tangent value for the vertex.

Navigation menu