Howto:Shader programming in FlightGear: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 348: Line 348:


== ALS Landing Lights - Spotlight ==
== ALS Landing Lights - Spotlight ==
[[File:als secondary light.png|640px|thumbnail|Proof of Concept]]
[[File:ALS Secondary Light Proof of Concept.png|320px|ALS Secondary Light Proof of Concept]]The ALS Landing Lights-Spotlight (we'll call it ALS Lights from now on) is a good example for showing how to incorporate a shader effect into [[Flightgear]] as it touches many parts of the visuals we see and many parts of the coding pipeline.
The ALS Landing Lights-Spotlight (we'll call it ALS Lights from now on) is a good example for showing how to incorporate a shader effect into [[Flightgear]] as it touches many parts of the visuals we see and many parts of the coding pipeline.


In the case of ALS Lights, you have to add the effect to every visual item rendered on the screen that you want to see a light shining on. If you want it to be capable of shining on everything, you have to account for each separate item and how that item is rendered.  That is a lot of code to touch.
In the case of ALS Lights, you have to add the effect to every visual item rendered on the screen that you want to see a light shining on. If you want it to be capable of shining on everything, you have to account for each separate item and how that item is rendered.  That is a lot of code to touch.
Line 389: Line 388:
They show up in the Property Tree under sim/rendering/als-secondary-lights and can be activated or manipulated by normal Nasal calls or XML.
They show up in the Property Tree under sim/rendering/als-secondary-lights and can be activated or manipulated by normal Nasal calls or XML.


[[File:als_secondary_lights_fog.jpg|1024px|thumbnail|ALS Landing Lights combined with Fog Effect]]
=== Effects File ===
=== Effects File ===
{{Note|need link to Effects Doc here to explain the details of the effects file}}
{{Note|need link to Effects Doc here to explain the details of the effects file}}
Line 484: Line 482:
  </uniform></small>
  </uniform></small>
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.
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.
[[File:Als Secondary Lights combined with Fog Effect.jpg|1024px|Weather settings to produce fog and ALS Landing Lights on a runway.]]


=== Shader Programs ===
=== Shader Programs ===
Line 552: Line 552:
   else return vec3 (0.0,0.0,0.0);
   else return vec3 (0.0,0.0,0.0);
  }
  }
[[File:Model on Water and Trees on Land.jpg|thumb|Model on Water and Trees on Land ALS Lights Effect]]


=== tree-ALS.frag ===
=== tree-ALS.frag ===
Line 608: Line 610:
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.
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.
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.
[[File:Model on Water.jpg|thumb|ALS Lights Effect over model and water.]]


==== File List ====
==== File List ====
Line 662: Line 666:
*** fragment water-ALS-high.frag & secondary_lights.frag
*** fragment water-ALS-high.frag & secondary_lights.frag
** adds uniforms (technique 2)
** adds uniforms (technique 2)
[[File:ALS Lights over Model and Terrain.jpg|640px|ALS Lights over Model and Terrain]]


== General Comments from Forum Discussion ==
== General Comments from Forum Discussion ==
330

edits