Board index FlightGear Development Effects and shaders

Keeping the grass effect under the chopper?

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

Keeping the grass effect under the chopper?

Postby StuartC » Mon Jul 30, 2018 9:59 pm

Simple question

Keeping the grass effect under the chopper? How to do it so the grass effect doesn't move around on external views.
StuartC
 
Posts: 3175
Joined: Fri Jun 18, 2010 9:18 pm
Location: Arse end of the Universe
Callsign: WF01
Version: 2019.1
OS: W10 64 bit

Re: Keeping the grass effect under the chopper?

Postby Thorsten » Tue Jul 31, 2018 6:12 am

You do the relevant coordinate transformation based on eye position - see the Alouette-III effect_manager.nas code for an example that's basically ready for copy/paste (*) (you'll also find a host of code to drive other effects there, including an environment-dependent dust/spray/snow thing that I'm rather proud of).

(Small drawback - this requires actual update cycles, and hence doesn't work when FG is paused...)

(*) Strictly speaking, the Alouette-III is GPL and you can't simply copy/paste code from GPL into non-GPL, but I'm willing to permit dual-licensing for FGUK :mrgreen:
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Keeping the grass effect under the chopper?

Postby AndersG » Tue Jul 31, 2018 8:31 am

IIRC you can run a Nasal timer w.r.t. wallclock time rather than sim time so you can adjust the visuals even when paused. It's controlled by one of the extra arguments to settimer.
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2524
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: Keeping the grass effect under the chopper?

Postby Thorsten » Tue Jul 31, 2018 8:41 am

Thanks, very cool - I didn't know that.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Keeping the grass effect under the chopper?

Postby StuartC » Tue Jul 31, 2018 9:28 am

From the effects_manager.nas I found the rotorwash stuff and made a little rotorwash.nas file to try it:-

Code: Select all
var effect_manager = {

# rotor wash

         var delta_x = (apos.lat() - vpos.lat()) * me.lat_to_m;
         var delta_y = -(apos.lon() - vpos.lon()) * me.lon_to_m;
         
         me.nd_ref_wash_x.setValue(delta_x);
         me.nd_ref_wash_y.setValue(delta_x);
         
         var rpm_factor = rotor_rpm /350.0;
         
         var strength = 20.0/alt_agl;
         if (strength > 1.0) {strength = 1.0;}
         strength = strength * rpm_factor;
         
         me.nd_ref_wash_strength.setValue(strength);
         
};


effect_manager.init();   


Its not actually having any effect on the grass though.
Last edited by bugman on Tue Jul 31, 2018 10:04 am, edited 1 time in total.
Reason: Clean up - added [code] tags.
StuartC
 
Posts: 3175
Joined: Fri Jun 18, 2010 9:18 pm
Location: Arse end of the Universe
Callsign: WF01
Version: 2019.1
OS: W10 64 bit

Re: Keeping the grass effect under the chopper?

Postby Thorsten » Tue Jul 31, 2018 9:30 am

It looks like you never actually define nd_ref_wash_x and nd_ref_wash_y or nd_ref_wash_strength... neither do you supply the init function, or even loop anything.

You need to extract all relevant code, otherwise your program doesn't know what properties to set 8)
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Keeping the grass effect under the chopper?

Postby StuartC » Tue Jul 31, 2018 9:42 am

Well as I know nothing about nasal, I looked for the section marked rotorwash.
StuartC
 
Posts: 3175
Joined: Fri Jun 18, 2010 9:18 pm
Location: Arse end of the Universe
Callsign: WF01
Version: 2019.1
OS: W10 64 bit

Re: Keeping the grass effect under the chopper?

Postby StuartC » Tue Jul 31, 2018 9:48 am

code now looks like this, but still nothing

Code: Select all
var effect_manager = {

run: 0,
 
   lat_to_m: 110952.0,
   lon_to_m: 0.0,

# rotor wash

         var delta_x = (apos.lat() - vpos.lat()) * me.lat_to_m;
         var delta_y = -(apos.lon() - vpos.lon()) * me.lon_to_m;
         
         me.nd_ref_wash_x.setValue(delta_x);
         me.nd_ref_wash_y.setValue(delta_x);
         
         var rpm_factor = rotor_rpm /350.0;
         
         var strength = 20.0/alt_agl;
         if (strength > 1.0) {strength = 1.0;}
         strength = strength * rpm_factor;
         
         me.nd_ref_wash_strength.setValue(strength);
         
         
   nd_ref_wash_x: props.globals.getNode("/environment/aircraft-effects/wash-x", 1),
   nd_ref_wash_y: props.globals.getNode("/environment/aircraft-effects/wash-y", 1),
   nd_ref_wash_strength: props.globals.getNode("/environment/aircraft-effects/wash-strength", 1),

         
};


effect_manager.init();
Last edited by bugman on Tue Jul 31, 2018 10:04 am, edited 1 time in total.
Reason: Clean up - added [code] tags.
StuartC
 
Posts: 3175
Joined: Fri Jun 18, 2010 9:18 pm
Location: Arse end of the Universe
Callsign: WF01
Version: 2019.1
OS: W10 64 bit

Re: Keeping the grass effect under the chopper?

Postby StuartC » Tue Jul 31, 2018 10:27 am

Tried code from the aircrane as well and have this:-

Code: Select all
var rotor_wash_loop = func {

   ##### water and grass shader effect
   var vpos = geo.viewer_position();
   var apos = geo.aircraft_position();

   var lat_to_m = 110952.0;
   var lon_to_m = math.cos(apos.lat()*math.pi/180.0) * lat_to_m;

   var alt = getprop("/position/altitude-agl-ft");

   var delta_x = (apos.lat() - vpos.lat()) * lat_to_m;
   var delta_y = -(apos.lon() - vpos.lon()) * lon_to_m;

   setprop("/environment/aircraft-effects/wash-x", delta_x);
   setprop("/environment/aircraft-effects/wash-y", delta_y);

   var rpm_factor = getprop("rotors/main/rpm")/380.0;

   var strength = 20.0/alt;
   if (strength > 1.0) {strength = 1.0;}
   strength = strength * rpm_factor;

   setprop("/environment/aircraft-effects/wash-strength", strength);
   }


But still no grass effect. On checking the property tree "environment/aircraft-effects/wash-strength" remains at zero so what am I missing. Do I need to enable something in the set file of model xml ( apart from the call to the nasal file).
StuartC
 
Posts: 3175
Joined: Fri Jun 18, 2010 9:18 pm
Location: Arse end of the Universe
Callsign: WF01
Version: 2019.1
OS: W10 64 bit

Re: Keeping the grass effect under the chopper?

Postby Thorsten » Tue Jul 31, 2018 11:06 am

No - you really just need to set the properties. If strength remains at zero, chances are you're not actually doing it or your computation to get it is off. Not sure whether /rotor/main/rpm exists for your chopper for instance - try setting strength to 1 for debug purposes, work from there.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Keeping the grass effect under the chopper?

Postby StuartC » Tue Jul 31, 2018 11:27 am

rotors/main/rpm does exist in all FGUK choppers.
Setting the strength to 1 in the nasal file still shows a 0 in the property tree.
Console is not showing any errors relating to the nasal file ether.
StuartC
 
Posts: 3175
Joined: Fri Jun 18, 2010 9:18 pm
Location: Arse end of the Universe
Callsign: WF01
Version: 2019.1
OS: W10 64 bit

Re: Keeping the grass effect under the chopper?

Postby Thorsten » Tue Jul 31, 2018 11:49 am

This is standard Nasal debugging 1x1 - if you set a property from a Nasal file but it remains at a different value, you

a) aren't executing the code - put in a print statement to see whether it runs
b) are mistaken about the argument of setprop - print it to the console to see whether it is what you think it is
c) have mis-spelled the property and are setting a different property- check spelling and/or set the property by hand in the property browser to see whether your code overwrites it

Well as I know nothing about nasal,


How do you make even halfway realistic aircraft systems - especially with your preference for YaSim which doesn't have a fuel system etc :?: Admitteldy I kind of assumed anyone who wants to implement effects can read, understand and debug Nasal code.

Consider learning it - it'll help you an awful lot in FG-world!
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Keeping the grass effect under the chopper?

Postby Richard » Tue Jul 31, 2018 1:13 pm

StuartC wrote in Tue Jul 31, 2018 10:27 am:Tried code from the aircrane as well and have this:-

Code: Select all
var rotor_wash_loop = func {


But still no grass effect. On checking the property tree "environment/aircraft-effects/wash-strength" remains at zero so what am I missing. Do I need to enable something in the set file of model xml ( apart from the call to the nasal file).


Is rotor_wash_loop actually being called. Do you have an aircraft loop (i.e. something driven from a timer?).

I'm happy to have a look at this and fix it; I'll even make one of my tedious videos showing what I did (if you like). Just send me a link to the files.
Richard
 
Posts: 810
Joined: Sun Nov 02, 2014 11:17 pm
Version: Git
OS: Win10

Re: Keeping the grass effect under the chopper?

Postby StuartC » Tue Jul 31, 2018 2:32 pm

This the nasal I am using which is lifted from the AirCrane, minus the particle dirt stuff.

Code: Select all
var rotor_wash_loop = func {

   ##### water and grass shader effect
   var vpos = geo.viewer_position();
   var apos = geo.aircraft_position();

   var lat_to_m = 110952.0;
   var lon_to_m = math.cos(apos.lat()*math.pi/180.0) * lat_to_m;

   var alt = getprop("/position/altitude-agl-ft");

   var delta_x = (apos.lat() - vpos.lat()) * lat_to_m;
   var delta_y = -(apos.lon() - vpos.lon()) * lon_to_m;

   setprop("/environment/aircraft-effects/wash-x", delta_x);
   setprop("/environment/aircraft-effects/wash-y", delta_y);

   var rpm_factor = getprop("rotors/main/rpm")/380.0;

   var strength = 20.0/alt;
   if (strength > 1.0) {strength = 1.0;}
   strength = strength * rpm_factor;

   setprop("/environment/aircraft-effects/wash-strength", strength);
   }
StuartC
 
Posts: 3175
Joined: Fri Jun 18, 2010 9:18 pm
Location: Arse end of the Universe
Callsign: WF01
Version: 2019.1
OS: W10 64 bit

Re: Keeping the grass effect under the chopper?

Postby Richard » Tue Jul 31, 2018 2:56 pm

Stuart I'd really like to see the whole -set and contents of the Nasal folder so I can figure out how this should be wired up. You can send me a cloud link (privately) if you like.
Richard
 
Posts: 810
Joined: Sun Nov 02, 2014 11:17 pm
Version: Git
OS: Win10

Next

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 2 guests