Board index FlightGear Development Effects and shaders

Using /sim/time/sun-angle-rad in </lightmap-factor>  Topic is solved

An exciting "new" option in FlightGear, that includes reflections, lightmaps, the particle system etc.. A lot is yet to be discovered/implemented!

Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby BecOzIcan » Sat Jul 09, 2016 2:04 pm

Hi Gents

I am giving a go at adding a lightmap to my latest AI model but I noticed the borders of my lighting areas show up during the day and clash with the overall scenery light (shown on picture below)

As a workaround I am trying to hide the lightmap during daytime using <lightmap-factor type="float" n="0"><use>/sim/time/sun-angle-rad</use></lightmap-factor>
as suggested in this post viewtopic.php?f=47&t=22940

That solution failed and the lightmap shows whatever the time of day. I am guessing the /sim/time/sun-angle-rad needs to be normalised so that it actually goes from 0 to 1 (OFF.ON) rather than 0 to 6.28 but I am not sure how to achieve that.

Any suggestion/guidance would be greatly appreciated

My effect triggering code :

Code: Select all
<PropertyList>
  <name>388-Lightmap</name>
  <inherits-from>Effects/model-combined-deferred</inherits-from>
  <parameters>
    <normalmap-enabled type="int">0</normalmap-enabled>
    <reflection-enabled type="int">0</reflection-enabled>
    <reflection-dynamic type="int">0</reflection-dynamic>
    <reflect_map-enabled type="int">0</reflect_map-enabled>
    <reflection-correction type="float">0</reflection-correction>
    <lightmap-enabled type="int">1</lightmap-enabled>
    <lightmap-multi type="int">1</lightmap-multi>
    <lightmap-factor type="float" n="0">1</lightmap-factor>
    <lightmap-color type="vec3d" n="0">1.0 1.0 1.0</lightmap-color>
    <lightmap-factor type="float" n="1">1</lightmap-factor>
    <lightmap-color type="vec3d" n="1">1.0 1.0 0.0</lightmap-color>
    <lightmap-factor type="float" n="2">1</lightmap-factor>
    <lightmap-color type="vec3d" n="2">1.0 1.0 1.0</lightmap-color>
    <lightmap-factor type="float" n="3">0.0</lightmap-factor>
    <lightmap-color type="vec3d" n="3">1.0 1.0 1.0</lightmap-color>
    <texture n="3">
      <image>AI/Aircraft/A380/Models/Effects/388-lightMap.png</image>
      <filter>linear-mipmap-linear</filter>
      <wrap-s>clamp</wrap-s>
      <wrap-t>clamp</wrap-t>
      <internal-format>normalized</internal-format>
    </texture>
  </parameters>
</PropertyList>


Image
Current Projects: AI Traffic, Models & Liveries
User avatar
BecOzIcan
 
Posts: 940
Joined: Tue Oct 04, 2011 10:43 pm
Location: Sydney, NSW, Australia
Version: 2.12
OS: Win10

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby Thorsten » Sat Jul 09, 2016 2:12 pm

Don't pass the property to the effect, use an expression.
Thorsten
 
Posts: 9529
Joined: Mon Nov 02, 2009 8:33 am

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby BecOzIcan » Sat Jul 09, 2016 2:45 pm

Thank you very much for the advice Thorsten, will look into that.

Cheers
Ian
Current Projects: AI Traffic, Models & Liveries
User avatar
BecOzIcan
 
Posts: 940
Joined: Tue Oct 04, 2011 10:43 pm
Location: Sydney, NSW, Australia
Version: 2.12
OS: Win10

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby BecOzIcan » Mon Jul 11, 2016 11:27 am

Me again...

So I think I got my expression under control but I coudn't find any documentation on the way to pass it to the factor.

Being fairly inexperienced with xml (and coding in general)I tried to nest it between my factor tags .... and failed like others apparently did

In most examples I found via the web (including the autopilot documentation), the expression is nested inside a filter with (in my example) the sun-rad as input and the lightmap-factor as output ???

Any help with this code (current failed state below) is welcome :-(

Cheers
Ian

Code: Select all
<PropertyList>
  <name>388-Lightmap</name>
  <inherits-from>Effects/model-combined-deferred</inherits-from>
  <parameters>
    <normalmap-enabled type="int">0</normalmap-enabled>
    <reflection-enabled type="int">1</reflection-enabled>
    <reflection-dynamic type="int">0</reflection-dynamic>
    <reflect_map-enabled type="int">0</reflect_map-enabled>
    <reflection-correction type="float">0</reflection-correction>
    <lightmap-enabled type="int">1</lightmap-enabled>
    <lightmap-multi type="int">1</lightmap-multi>
    <lightmap-factor type="float" n="0">
      <expression>
        <floor>
          <div>
            <property>sim/time/sun-angle-rad</property>
            <value>1.6</value>
          </div>
        </floor>
      </expression>
   </lightmap-factor>
    <lightmap-color type="vec3d" n="0">1.0 1.0 1.0</lightmap-color>
    <lightmap-factor type="float" n="1">1.0</lightmap-factor>
    <lightmap-color type="vec3d" n="1">1.0 1.0 0.0</lightmap-color>
    <lightmap-factor type="float" n="2">1.0</lightmap-factor>
    <lightmap-color type="vec3d" n="2">1.0 1.0 1.0</lightmap-color>
    <lightmap-factor type="float" n="3">0.0</lightmap-factor>
    <lightmap-color type="vec3d" n="3">1.0 1.0 1.0</lightmap-color>
    <texture n="3">
      <image>AI/Aircraft/A380/Models/Effects/388-lightMap.png</image>
      <filter>linear-mipmap-linear</filter>
      <wrap-s>clamp</wrap-s>
      <wrap-t>clamp</wrap-t>
      <internal-format>normalized</internal-format>
    </texture>
  </parameters>
</PropertyList>
Current Projects: AI Traffic, Models & Liveries
User avatar
BecOzIcan
 
Posts: 940
Joined: Tue Oct 04, 2011 10:43 pm
Location: Sydney, NSW, Australia
Version: 2.12
OS: Win10

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby Thorsten » Mon Jul 11, 2016 11:35 am

I'm fairly sure there needs to be a <use> tag whenever you pass a variable instead of a constant as a parameter, and the expression should then replace the property inside that.
Thorsten
 
Posts: 9529
Joined: Mon Nov 02, 2009 8:33 am

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby Harald » Mon Jul 11, 2016 6:47 pm

You can use a <use> instead of a constant in the effect parameters.
And if the expression does not work in the effect you can do that computation in a nasal script attached to your object.

hj.
Harald
 
Posts: 188
Joined: Fri Mar 02, 2007 4:30 pm
Location: Strasbourg, France
Version: nightly
OS: Windows 10

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby BecOzIcan » Sat Jul 23, 2016 1:32 pm

Quck Update.

Wrapping the Expression in <use> and nesting it didn't work but I just came across a piece of nasal in the WSSS custom scenery which looks like what I am after.

Thanks again for all your advice guys.

Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<PropertyList>
    <!-- Nasal helper: listen on sun-angle-rad and set lightmap-factor  -->
    <nasal>
        <load>
            if (getprop("/scenery/osm2city/lightmap-factor") == nil) {
                print ("installing osm2city nasal.");
                setprop("/scenery/osm2city/lightmap-factor", 0);
                setlistener("sim/time/sun-angle-rad", func(the_node) {
                    if (the_node.getValue() > 1.45 )
                        setprop("/scenery/osm2city/lightmap-factor", 1.)
                    else
                        setprop("/scenery/osm2city/lightmap-factor", 0.);
                });
            };
        </load>
    </nasal>
</PropertyList>
Current Projects: AI Traffic, Models & Liveries
User avatar
BecOzIcan
 
Posts: 940
Joined: Tue Oct 04, 2011 10:43 pm
Location: Sydney, NSW, Australia
Version: 2.12
OS: Win10

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby BecOzIcan » Wed Sep 06, 2017 12:03 pm

Back to the drawing board on this one. After going after pretty much every single XML related wiki page I realized the nasal avenue was not recommended. Also I am looking at implementing lightmaps to most of my AI aricrafts but with slight variations in "Day/Night" switching time so I don't want to set up tons of nasal listeners.

I came to the same conclusion than it0uchpods in this THREAD that I should use a Gain Filter to pass on the result of my calculation onto a property and then use it in my lightmap factor

Current Implementation is

Filter in my AI aircraft main.xml as follow :

Code: Select all
<?xml version="1.0"?>
<PropertyList>
  <description>Airbus A380-800</description>
  <author>Ian(Yves) Tolosa. July 2016 </author>
  <path>Models/388.ac</path>
  <!-- Gear Showed only < 180 knotspeed -->
  <animation>
    <type>select</type>
    <object-name>Gear</object-name>
    <condition>
      <less-than>
        <property>velocities/true-airspeed-kt</property>
        <value>180</value>
      </less-than>
    </condition>
  </animation>
  <!-- Lightmap Switch -->
   <filter>
    <name>NightSwitch</name>
    <type>gain</type>
    <gain>1</gain>
    <update-interval-secs>1</update-interval-secs>
    <input>
      <expression>
        <floor>
          <div>
            <property>/sim/time/sun-angle-rad</property>
            <value>1.6</value>
          </div>
        </floor>
      </expression>
    </input>
    <output>
      <property type="float">/ai/lightmapswitch</property>
    </output>
  </filter>
  <!-- Lightmap Effect -->
  <effect>
    <inherits-from>AI/Aircraft/A380/Effects/388-lightMap</inherits-from>
    <object-name>388</object-name>
  </effect>
</PropertyList>


An effect file and related png n a subfolder ; note the lightmap works perfectly when manually set to manual activation using <lightmap-factor>1</lightmap-factor>

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<!-- Lighting of Tail, Flanks and Windows -->
<PropertyList>
  <name>A388-Lightmap</name>
  <inherits-from>Effects/model-combined-deferred</inherits-from>
  <parameters>
    <normalmap-enabled type="int">0</normalmap-enabled>
    <reflection-enabled type="int">0</reflection-enabled>
    <reflection-dynamic type="int">0</reflection-dynamic>
    <reflect_map-enabled type="int">0</reflect_map-enabled>
    <reflection-correction type="float">0</reflection-correction>
    <!-- Enable 3 colors RGB LigntMap -->
    <lightmap-enabled type="int">1</lightmap-enabled>
    <lightmap-multi type="int">1</lightmap-multi>
    <!-- Red Channel (Tail) - Night Activation and Color -->
    <lightmap-factor type="float" n="0">
   <use>
   <property>/ai/lightmapswitch</property>
   </use>
   </lightmap-factor>
    <lightmap-color type="vec3d" n="0">1.0 1.0 1.0</lightmap-color>
    <!-- Green Channel (Windows) Multiplying Factor and Color -->
    <lightmap-factor type="float" n="1">1.0</lightmap-factor>
    <lightmap-color type="vec3d" n="1">1.0 1.0 0.0</lightmap-color>
    <!-- Blue Channel (Flanks) Multiplying Factor and Color -->
    <lightmap-factor type="float" n="2">1.0</lightmap-factor>
    <lightmap-color type="vec3d" n="2">1.0 1.0 1.0</lightmap-color>
    <!-- Alpha Channel (OFF) Multiplying Factor and Color -->
    <lightmap-factor type="float" n="3">0.0</lightmap-factor>
    <lightmap-color type="vec3d" n="3">1.0 1.0 1.0</lightmap-color>
    <!-- LightMap Image Location -->
    <texture n="3">
      <image>AI/Aircraft/A380/Effects/388-lightMap.png</image>
      <filter>linear-mipmap-linear</filter>
      <wrap-s>clamp</wrap-s>
      <wrap-t>clamp</wrap-t>
      <internal-format>normalized</internal-format>
    </texture>
  </parameters>
</PropertyList>


Still I cannot get that switch to work and kinda going crazy as I don't seem able to make any sense of the xml properties documentation in the FG wikis

1. Do I have the right implementation? I am under the impression you can create a new property 'on the fly' so I have not added/registered/declared my new ai/lightmapswitch property anywhere else than in the the filter in aircraft's main.xml. Is this enough for FG to create it and populate every time an A388 AI aircraft is used and displayed ? Am I missing something ?

2. I cannot debug : I was under the impression that once my new property added to my xml it would automatically appear in the list of properties in "Debug/Browse internal properties" (so I can check the expression result and the property content before adding it to the effect) but I do not see it in there. I noticed that if I alias the property and add a <use alias ... in tee lightmap factor then the property appear in the internal properties list but with no content.

I d appreciate a bit of help on this one
Thanks in advance
Ian
Current Projects: AI Traffic, Models & Liveries
User avatar
BecOzIcan
 
Posts: 940
Joined: Tue Oct 04, 2011 10:43 pm
Location: Sydney, NSW, Australia
Version: 2.12
OS: Win10

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby Thorsten » Wed Sep 06, 2017 1:32 pm

It's not
Code: Select all
    <lightmap-factor type="float" n="0">
   <use>
   <property>/ai/lightmapswitch</property>
   </use>
   </lightmap-factor>


but just

Code: Select all
    <lightmap-factor type="float" n="0">
   <use>/ai/lightmapswitch</use>
   </lightmap-factor>


(I know - why can't it be the same syntax everywhere... )
Thorsten
 
Posts: 9529
Joined: Mon Nov 02, 2009 8:33 am

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby BecOzIcan » Wed Sep 06, 2017 2:52 pm

Thorsten wrote in Wed Sep 06, 2017 1:32 pm:
(I know - why can't it be the same syntax everywhere... )


Thank you for that. Made the change and now at least the property now appears in the Browse Properties list, But as string. ie even if I set it manually to 0 for debugging pruposes the lightmap remains active.

I believe this is the same scenario I have seen before (in my "Let's use an alias" attempt) where it doesn't seem my property is recognized on the filter side but one is created from the presence of the <use> on the effect side except it is a default one it does does not carry the expected format/content (which are set from the filter.)

I am starting to wonder if maybe there is something in my main.xml about the order of my entries. Like I experienced with my first animation files back in 2012 ?
Current Projects: AI Traffic, Models & Liveries
User avatar
BecOzIcan
 
Posts: 940
Joined: Tue Oct 04, 2011 10:43 pm
Location: Sydney, NSW, Australia
Version: 2.12
OS: Win10

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby Thorsten » Wed Sep 06, 2017 3:59 pm

If the code containing the filter is literally copied and not just intended to summarize what you do, then there you have another issue - the filter definition needs to be part of a property rule declaration - you can't simply add it to any xml.
Thorsten
 
Posts: 9529
Joined: Mon Nov 02, 2009 8:33 am

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby Thorsten » Wed Sep 06, 2017 5:19 pm

Okay, I just realized you want to do this for AI models - you can't use a property rule inside the AI code.

Can you just connect your lightmap to /environment/lightmap-factor ? That's the property rule that takes care of the OSM building lightmaps and returns 0 when the sun is up and 1 when the sun is down.
Thorsten
 
Posts: 9529
Joined: Mon Nov 02, 2009 8:33 am

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby BecOzIcan » Thu Sep 07, 2017 9:33 am

Thorsten wrote in Wed Sep 06, 2017 5:19 pm:Can you just connect your lightmap to /environment/lightmap-factor ? That's the property rule that takes care of the OSM building lightmaps and returns 0 when the sun is up and 1 when the sun is down.


Jeez ! You got me so worried when I read your message this morning ... ("How did I miss that, why is it still not working, why don't I see that in my property browser etc.. etc etc. "). Only until I discovered later today this is a very recent change and a march 2017 commit. Versions installed on my machines (2.12 and 2017.1.3) obviously didn't have it)

Just installed 2017.2.1 and I can actually see this new property. Will change my implementation along your recommendation. Thanks a million times for your help

Cheers
Ian
Current Projects: AI Traffic, Models & Liveries
User avatar
BecOzIcan
 
Posts: 940
Joined: Tue Oct 04, 2011 10:43 pm
Location: Sydney, NSW, Australia
Version: 2.12
OS: Win10

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>  

Postby BecOzIcan » Thu Sep 07, 2017 11:49 am

Just a confirmation that using the new /environment/lightmap-factor as switch worked perfectly.

Between this one and the current successful experiment with NAV Lights, you should expect a bit of visual wow with our AI aircrafts in the coming weeks.

Marking the topic resolved. Effect code below. Thanks again
Cheers
Ian

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<!-- Lighting of Tail, Flanks and Windows -->
<PropertyList>
  <name>A388-Lightmap</name>
  <inherits-from>Effects/model-combined-deferred</inherits-from>
  <parameters>
    <normalmap-enabled type="int">0</normalmap-enabled>
    <reflection-enabled type="int">0</reflection-enabled>
    <reflection-dynamic type="int">0</reflection-dynamic>
    <reflect_map-enabled type="int">0</reflect_map-enabled>
    <reflection-correction type="float">0</reflection-correction>
    <!-- Enable 3 colors RGB LigntMap -->
    <lightmap-enabled type="int"><use>/environment/lightmap-factor</use></lightmap-enabled>
    <lightmap-multi type="int">1</lightmap-multi>
    <!-- Red Channel (Tail) - Night Activation and Color -->
    <lightmap-factor type="float" n="0">1</lightmap-factor>
    <lightmap-color type="vec3d" n="0">1.0 1.0 1.0</lightmap-color>
    <!-- Green Channel (Windows) Multiplying Factor and Color -->
    <lightmap-factor type="float" n="1">1</lightmap-factor>
    <lightmap-color type="vec3d" n="1">1.0 1.0 0.0</lightmap-color>
    <!-- Blue Channel (Flanks) Multiplying Factor and Color -->
    <lightmap-factor type="float" n="2">1</lightmap-factor>
    <lightmap-color type="vec3d" n="2">1.0 1.0 1.0</lightmap-color>
    <!-- Alpha Channel (OFF) Multiplying Factor and Color -->
    <lightmap-factor type="float" n="3">0.0</lightmap-factor>
    <lightmap-color type="vec3d" n="3">1.0 1.0 1.0</lightmap-color>
    <!-- LightMap Image Location -->
    <texture n="3">
      <image>AI/Aircraft/A380/Effects/388-lightMap.png</image>
      <filter>linear-mipmap-linear</filter>
      <wrap-s>clamp</wrap-s>
      <wrap-t>clamp</wrap-t>
      <internal-format>normalized</internal-format>
    </texture>
  </parameters>
</PropertyList>
Current Projects: AI Traffic, Models & Liveries
User avatar
BecOzIcan
 
Posts: 940
Joined: Tue Oct 04, 2011 10:43 pm
Location: Sydney, NSW, Australia
Version: 2.12
OS: Win10

Re: Using /sim/time/sun-angle-rad in </lightmap-factor>

Postby Thorsten » Thu Sep 07, 2017 1:02 pm

Cheers, to that!
Thorsten
 
Posts: 9529
Joined: Mon Nov 02, 2009 8:33 am


Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 1 guest