→A Practical Application in Flightgear: +syntax highlighting and formatting
Any combination of Preferences, [[Nasal|Nasal]] or [[Xml|XML]] manipulates data in the [[Property Tree]].
In this case the switch to turn on the landing or spot light and a couple other needed data containers are defined in $FG_ROOT/preferences.xml with the following lines.
They show up in the Property Tree under sim/rendering/als-secondary-lights and can be activated or manipulated by normal [[Nasal|Nasal]] calls or [[Xml|XML]].
Parameter entries defined in the Effect file correspond to a property tree data container (static or variable). They will contain the data needed by the shader program to perform its magic. The type of information contained in the property tree might be program control data or variable/static data that the shader program can manipulate prior to sending on to render.
In the case of ALS Lights, below is some of the data passed to, and used by, the shader program.
Note the "use-searchlight" entry, it is pointing to the use-searchlight entry in the property tree under "sim/rendering/als-secondary-lights" that was defined in preferences.xml.
Next comes the entry to define what shader program the parameters data is going to be passed to.
This is where you specify what shader program is to be used by the technique. ALS has the lowest techniques, with higher quality preceding lower quality.
In the case of ALS Lights, so far we only have to deal with the fragment shader.
==== Uniforms ====
The uniforms section is the mechanism that feeds the parameter data to the shader program.
Note the name, "use_searchlight", which was originally defined in preferences.xml and then became an entry in parameters is now being passed to the program shader by the uniform. Below in the "Shader Program" section, we will show you how the shader receives the uniform's data.
==== Functions ====
float light_distance_fading(in float dist)
else return vec3 (0.0,0.0,0.0);
[[File:Model on Water and Trees on Land.jpg|803px|Model on Water and Trees on Land ALS Lights Effect]]
==== Functions ====
Function calls to the function defined in secondary_lights.frag are
vec3 landing_light(in float offset);
You don't have to use any path information or includes in the code because the GLSL compiler program takes care of linking all the shader programs as long as they are defined correctly in the "programs" section of the effect file.
Variable data can be passed to and returned from GLSL functions just like any other language.
==== Main Program ====
The "main" function is the heart of the shader program. This is where the shader program manipulates all the data made available to it.
vec4 fragColor = vec4 (gl_Color.rgb +secondary_light * light_distance_fading(dist),1.0) * texel;
Note how "use_searchlight" is used in the main function to determine if the property defined in preferences.xml and manipulated in the property tree is set to true or 1.
Some of the variable data contained in the shader program is used for other purposes and is introduced into the shader program from other property, parameter and uniform definitions not pertaining to ALS Lights.