Howto:Add aircraft lights

From FlightGear wiki
Jump to navigation Jump to search
This article is incomplete. Please help improve the article, or discuss the issue on the talk page.

In order to add (the right) lights to your aircraft, you need to know what kind of lights planes are equipped with. Therefore it is suggested to read aircraft lighting first.

Anti-Collision Beacon lights

Nasal

var beacon_switch = props.globals.getNode("controls/switches/beacon", 2);
var beacon = aircraft.light.new( "/sim/model/lights/beacon", [0, 3], "/controls/lighting/beacon" );

Model

 <animation>
 <type>select</type>
 <object-name>Light</object-name>
 <condition>
 <property>/sim/model/lights/beacon/state</property>
 </condition>
 </animation>

Strobe lights

Nasal

var strobe_switch = props.globals.getNode("controls/switches/strobe", 2);
var strobe = aircraft.light.new( "/sim/model/lights/strobe", [0, 3], "/controls/lighting/strobe" );

Model

 <animation>
  <type>select</type>
  <object-name>Light</object-name>
  <condition>
   <property>/sim/model/lights/strobe/state</property>
  </condition>
 </animation>

Landing lights

Model

 <animation>
  <type>select</type>
  <object-name>Light</object-name>
  <condition>
   <property>controls/lighting/landing-light</property>
  </condition>
 </animation>

If the lights are located on the nosegear, use the one below instead. It will only show the lights when the landinggear is out. Change the value to make the light switch on when gear is out (vary from plane to plane, you can use the property browser to find the right value).

 <animation>
  <type>select</type>
   <object-name>Light</object-name>
   <condition>
    <and>
     <property>controls/lighting/landing-light</property>
     <greater-than>
      <property>gear/gear/position-norm</property>
      <value>0.05</value>
     </greater-than>
    </and>
   </condition>
 </animation>

Combined ALS procedural lights and Compositor lights

Flightgear comes with three light effects which historically had to be configured separately. The original sprite lights, the ALS procedural light which simulates the effect when looking at the light source, and the Compositor lights which illuminate the surrounding.

As of January 30th 2022 it is possible to configure all light effects simultaneously by using the XML overlay system and referencing spotlight.xml or pointlight.xml in the Aircraft/Generic directory.

<model>
 <name>RedLight</name>
 <path>Aircraft/Generic/spotlight.xml</path>
 <offsets>
  <x-m>-0.42</x-m>
  <y-m>-5.28</y-m>
  <z-m> 0.67</z-m>
 </offsets>
 <overlay>
  <params>
   <name>RedLight</name>
   <power-source>/controls/lighting/nav-lights</power-source>
   <direction>
    <x>0.5</x>
    <y>0.5</y>
    <z>0</z>
   </direction>
   <ambient>
    <r>0.5</r>
    <g>0</g>
    <b>0</b>
   </ambient>
   <specular>
    <r>1.0</r>
    <g>0.7</g>
    <b>0.5</b>
   </specular>
  </params>
 </overlay>
</model>

Be aware that the direction follows the convention from ALS pointing_x, pointing_y and pointing_z and not the x, y and z tags as used by the Compositor. The Compositors directional vector is directly opposite to the one used here and by ALS.

The power-source property replaces the select animation mentioned above.

The power-source, direction and color components of the overlay section are shared between ALS and the Compositor. Other parameters are set to a sane default for normal navigation lights but can be adjusted individually.

For example for a landing light you could add the following parameters to the overlay section

   <!-- ALS settings -->
   <dist-scale>10</dist-scale>
   <inner_angle>0.1</inner_angle>
   <outer_angle>0.4</outer_angle>
   <zero_angle>0.5</zero_angle>
   <outer_gain>0.0</outer_gain>

   <!-- Compositor settings -->
   <attenuation>
    <c>0.375</c>
    <l>0.01</l>
    <q>0.0001</q>
   </attenuation>
   <spot-cutoff>60</spot-cutoff>
   <spot-exponent>45</spot-exponent>
   <range-m>1500</range-m>

To tune the numbers of compositor lights, you may want to have a look at the Illuminator add-on, which allows to modify existing lights at runtime. You need to add the light XML first to your aircraft with some guestimate numbers.

PC-9M with ALS NAV lights
PC-9M with pre-ALS sprite NAV lights