<?xml version="1.0" encoding="UTF-8" ?>

<PropertyList>
	<path>LECO_Terminal.ac</path>

<effect>
	<inherits-from>Effects/model-combined-deferred</inherits-from>
	<parameters>
		<!-- lightmap -->
		<lightmap-enabled type="int">1</lightmap-enabled>
		<lightmap-multi type="int">1</lightmap-multi>
		<!-- use only the red channel -->
		<lightmap-factor type="float" n="0"><use>/scenery/LECO/lightsFactor</use></lightmap-factor>
		<lightmap-factor type="float" n="1">0</lightmap-factor>
		<lightmap-factor type="float" n="2">0</lightmap-factor>
		<lightmap-factor type="float" n="3">0</lightmap-factor>
		<texture n="3"> <!-- lightmap -->
			<image>LECO_Terminal_2.png</image>
			<filter>linear-mipmap-linear</filter>
			<wrap-s>repeat</wrap-s>
			<wrap-t>repeat</wrap-t>
			<internal-format>normalized</internal-format>
		</texture>
		<!-- reflection -->
		<reflection-enabled type="int">0</reflection-enabled>
	  </parameters>
	  <object-name>Main</object-name>
</effect>

<!-- NOTE: apparently, there is no easy way to have reflections AND lightmaps!
     This is why we select an object with reflections during the day, and an object
     with a lightmap at night. Apart from the shader, the rest of the object is the same! -->
<animation>
	<object-name>WindowsNight</object-name>
	<type>select</type>
	<condition>
		<greater-than>
			<property>/scenery/LECO/lightsSwitch</property>
			<value>0.5</value>
		</greater-than>
	</condition>
</animation>
<animation>
	<object-name>Windows</object-name>
	<type>select</type>
	<condition>
		<less-than>
			<property>/scenery/LECO/lightsSwitch</property>
			<value>0.5</value>
		</less-than>
	</condition>
</animation>

<effect>
	<inherits-from>Effects/model-combined-deferred</inherits-from>
	<parameters>
		<!-- lightmap -->
		<lightmap-enabled type="int">0</lightmap-enabled>
		<!-- reflection -->
		<reflection-enabled type="int">1</reflection-enabled>
		<reflection-correction type="float">0.2</reflection-correction>
		<reflection-fresnel type="float">0.2</reflection-fresnel>
		<texture n= "5" > <!-- reflection cubemap -->
			<type>cubemap</type>
			<images>
			<positive-x>Aircraft/Generic/Effects/CubeMaps/blue-sky/blue-sky-faces_c00.png</positive-x>
			<negative-x>Aircraft/Generic/Effects/CubeMaps/blue-sky/blue-sky-faces_c01.png</negative-x>
			<positive-y>Aircraft/Generic/Effects/CubeMaps/blue-sky/blue-sky-faces_c02.png</positive-y>
			<negative-y>Aircraft/Generic/Effects/CubeMaps/blue-sky/blue-sky-faces_c03.png</negative-y>
			<positive-z>Aircraft/Generic/Effects/CubeMaps/blue-sky/blue-sky-faces_c04.png</positive-z>
			<negative-z>Aircraft/Generic/Effects/CubeMaps/blue-sky/blue-sky-faces_c05.png</negative-z>
			</images>
		</texture>
	  </parameters>
	  <object-name>Windows</object-name>
</effect>
<effect>
	<inherits-from>Effects/model-combined-deferred</inherits-from>
	<parameters>
		<!-- lightmap -->
		<lightmap-enabled type="int">1</lightmap-enabled>
		<lightmap-multi type="int">1</lightmap-multi>
		<!-- use only the red channel -->
		<lightmap-factor type="float" n="0"><use>/scenery/LECO/lightsFactor</use></lightmap-factor>
		<lightmap-factor type="float" n="1">0</lightmap-factor>
		<lightmap-factor type="float" n="2">0</lightmap-factor>
		<lightmap-factor type="float" n="3">0</lightmap-factor>
		<texture n="3"> <!-- lightmap -->
			<image>LECO_Terminal_2.png</image>
			<filter>linear-mipmap-linear</filter>
			<wrap-s>repeat</wrap-s>
			<wrap-t>repeat</wrap-t>
			<internal-format>normalized</internal-format>
		</texture>
		<!-- reflection -->
		<reflection-enabled type="int">0</reflection-enabled>
	  </parameters>
	  <object-name>WindowsNight</object-name>
</effect>

  <!--
      THE FOLLOWING CODE IS USED BY OTHER MODELS IN THE SCENERY!!!!
      the following properties are used in all the light related effects
      at LECO, as a better alternative to using sun-angle-rad directly.
      Credits for the original idea go to LOWI scenery developers.
      See their LOWI_garage_main.xml 

      Can be extended with loop freq throttling and weather data:
      http://forum.flightgear.org/viewtopic.php?p=208233#p208233
  -->
  <nasal>
    <load><![CDATA[
if (!contains(globals, "scenery")) globals["scenery"] = {};
if (!contains(scenery, "LECO")) scenery["LECO"] = {};
if (!contains(scenery.LECO, "lightsFactor")) scenery.LECO.lightmapFactor = nil;
if (!contains(scenery.LECO, "lightsSwitch")) scenery.LECO.lightSwitch = nil;

var loopIntervalInSeconds = 1.0;
var isActive = 0;
var lowerBound = 1.45;
var upperBound = 1.60;
var updateLightmapFactors = func() {
  isActive or return;
  
  var sunAngle = getprop("/sim/time/sun-angle-rad") or 0.0;
  
  if(sunAngle < lowerBound) {
    # DAY
    setprop("/scenery/LECO/lightsFactor", 0.0);
    setprop("/scenery/LECO/lightsSwitch", 0);
    
  } else if((lowerBound <= sunAngle) and (sunAngle <= upperBound)) {
    # DAWN/SUNRISE
    var lmFactor = (sunAngle - lowerBound) / (upperBound - lowerBound);
    var lmSwitch = 1; #(lmFactor > 0.5 ? 1 : 0);
    setprop("/scenery/LECO/lightsFactor", lmFactor);
    setprop("/scenery/LECO/lightsSwitch", lmSwitch);
#    print("sunAngle = ", sunAngle);
#    print("MIDDLE lightsFactor = ", lmFactor);
    
  } else {
    # NIGHT
    setprop("/scenery/LECO/lightsFactor", 1.0);
    setprop("/scenery/LECO/lightsSwitch", 1);
  }

  settimer(updateLightmapFactors, loopIntervalInSeconds);
}
isActive = 1;
updateLightmapFactors();
]]>
    </load>
    <unload>isActive = 0</unload>

  </nasal>

</PropertyList>
