Board index FlightGear Development Effects and shaders

ALS landing lights

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

ALS landing lights

Postby Thorsten » Sat Oct 04, 2014 8:37 am

It's not Rembrandt, and it's computationally dead cheap:

Image

(so far just a simple proof of concept, the technique is similar to the cloud shadows)
Thorsten
 
Posts: 11194
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby radi » Sat Oct 04, 2014 10:22 am

That is awesome! A realistic spot light has been the single bit I've been missing about ALS.

The best (non-rembrandt) I've seen so far is the landing light of the 777-200, but that appears to 'just' brighten up the scenery in a fixed screen area.

Is it still going to be computationally cheap to get a realistic effect on rotation and climb? I reckon you'd have to compute/approximate where the light cone intersects the ground?
OSM buildings for LOWI, EDDC
Custom scenery for VHXX YMML
Edit .stg via the FG Object Placement Tool
radi
 
Posts: 643
Joined: Mon Aug 25, 2008 4:24 pm
Location: YMML, EDDC

Re: ALS landing lights

Postby Thorsten » Sat Oct 04, 2014 11:10 am

The current screenshot is something like a searchlight (I guess some helicopters are equipped with one) - it follows where you look, and it projects correctly and has 1/r^2 fading in the distance.

For the aircraft, the idea would be to just pass the intersection point of the light with the ground relative to the current camera position, the size and brightness to the shader (just like the centers of cloud shadows are done).

That's just a relatively simple once per-frame computation (like in the case of clouds, no need to do this per pixel), and it may even be easy to offload it to a property rule - so the shader just draws a single blurry illuminated spot.

That wouldn't be a real light like in Rembrandt, but I suspect it may be close enough that you can't tell the difference unless you go looking specifically. I don't know, I'd have to try, the searchlight is a bit easier to do. Also, landing lights which work from the cockpit only would be much easier than those which work in external views as well.

I guess the key is that under no circumstances secondary lights should make an appearance in the vertex shader, because this is where it gets costly.
Thorsten
 
Posts: 11194
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby Hooray » Sat Oct 04, 2014 11:23 am

Thorsten wrote in Sat Oct 04, 2014 11:10 am:That wouldn't be a real light like in Rembrandt, but I suspect it may be close enough that you can't tell the difference unless you go looking specifically.


And I guess it can only be supported easily for a cockpit-only camera view and the main aircraft, right ?
Otherwise, we'd need to encode positions of lights and specify some meta information to support other aircraft, e.g. AI aircraft and do the whole thing in relation to the current view/camera position.
But it's definitely a cool feature still, and it having a low-overhead could easily make this popular among aircraft developers once you document the scheme and provide a few more examples/screen shots
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11376
Joined: Tue Mar 25, 2008 8:40 am

Re: ALS landing lights

Postby radi » Sat Oct 04, 2014 11:41 am

it projects correctly and has 1/r^2 fading in the distance.

Fantastic!

Also, landing lights which work from the cockpit only would be much easier than those which work in external views as well.

Why is that? Because of the distance fading?
OSM buildings for LOWI, EDDC
Custom scenery for VHXX YMML
Edit .stg via the FG Object Placement Tool
radi
 
Posts: 643
Joined: Mon Aug 25, 2008 4:24 pm
Location: YMML, EDDC

Re: ALS landing lights

Postby ludomotico » Sat Oct 04, 2014 12:10 pm

Thorsten wrote in Sat Oct 04, 2014 8:37 am:the technique is similar to the cloud shadows


To realize these things, sir, you need the spark of a genius.
User avatar
ludomotico
 
Posts: 1018
Joined: Tue Apr 24, 2012 1:01 pm
Version: git
OS: Debian GNU/Linux

Re: ALS landing lights

Postby Thorsten » Sat Oct 04, 2014 2:17 pm

And I guess it can only be supported easily for a cockpit-only camera view and the main aircraft, right ?

Why is that? Because of the distance fading?


Because if you are (almost) at the origin of the light beam, doing near exact geometry in screen coordinates is a matter of two lines, whereas if you're not at the origin of the light beam, you actually need to compute a bit of geometry.

As the cloud example shows, we can (in principle) do semi-projective geometry seen from outside as well as multiple 'objects' (light spots or shadows) - but eventually, if you want a hundred lights reflecting in the water, Rembrandt is the better way to do it.

So my idea at the moment is to support three property-driven light types - searchlight (which follows the eye axis), cockpit view landing light (which follows the plane axis) and external view landing light spot, and it'd be up to the airplane developers to utilize these in a view-dependent way.
Thorsten
 
Posts: 11194
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby Thorsten » Sun Oct 05, 2014 11:31 am

Okay, generic implementation for a searchlight and a landing light has been pushed. Lightspots are property controlled (see pic) and currently realistic from cockpit view only.

Image

(Still need to work on relative intensity when the sun is out and some scaling with screen geometry, but it's something to play with).
Thorsten
 
Posts: 11194
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby Thorsten » Sun Oct 05, 2014 2:51 pm

Seems to be working okay... I have no idea what the realistic lighting would be, but this doesn't seem too bad:

Image
Image
Image
Thorsten
 
Posts: 11194
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby Lydiot » Sun Oct 05, 2014 3:38 pm

Hey Thorsten...

You're awesome!
Lydiot
 
Posts: 987
Joined: Tue Oct 22, 2013 10:50 pm

Re: ALS landing lights

Postby F-JJTH » Sun Oct 05, 2014 4:55 pm

Hi,

Does it light up models ? e.g, hangars, building, windsock, other MP aircraft, trees...
In other words: does it light up *everything* in the scene or only the ground (terrain/runway) ?

Regards,
Clément
User avatar
F-JJTH
 
Posts: 697
Joined: Fri Sep 09, 2011 11:02 am

Re: ALS landing lights

Postby Thorsten » Sun Oct 05, 2014 5:41 pm

In other words: does it light up *everything* in the scene or only the ground (terrain/runway) ?


Right now just the terrain, airport keep and runway. Potentially... everything to which I add the relevant lines in the shader. It's mainly a question of what you want to illuminate, and how much performance you're willing to sacrifice. In all of ALS, light is always computed inside the shader, so it's not so different from sunlight, which also needs to be computed the same way in every effect shader.

It can light up clouds if you like, technically it's easy, just putting stuff into the cloud fragment shader is costly.
Thorsten
 
Posts: 11194
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby wlbragg » Mon Oct 06, 2014 7:36 am

Thorsten,

This is truly impressive.

Try as I might I couldn't get it to work on models. Therefore I will probably suffer the same for anything else I try to apply it to. Would you be so kind as to add it to models, trees, water and buildings (especially the spotlight) or instruct me as to how to do it. I thought I understood it well enough to make it work but apparently not, or I am missing some minor detail.

I added

Code: Select all
uniform int use_searchlight;
uniform int use_landing_light;
vec3 searchlight(in float dist);
vec3 landing_light(in float dist);

if (use_searchlight == 1)
{
   color.rgb += searchlight(dist);
}
if (use_landing_light == 1)
{
   color.rgb += landing_light(dist);
}
fragColor = color * texel + specular;

to model-default.frag

Code: Select all
(about line 29)
<display_xsize><use>/sim/startup/xsize</use></display_xsize>
<display_ysize><use>/sim/startup/ysize</use></display_ysize>
<view_pitch_offset><use>/sim/current-view/pitch-offset-deg</use></view_pitch_offset>
<view_heading_offset><use>/sim/current-view/heading-offset-deg</use></view_heading_offset>
<view_fov><use>/sim/current-view/field-of-view</use></view_fov>
<use_searchlight><use>/sim/rendering/als-secondary-lights/use-searchlight</use></use_searchlight>
<use_landing_light><use>/sim/rendering/als-secondary-lights/use-landing-light</use></use_landing_light>

(in <program>)
<vertex-shader>Shaders/terrain-haze-ultra.vert</vertex-shader>
<fragment-shader>Shaders/terrain-haze-ultra.frag</fragment-shader>
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>

(with other uniforms)
<uniform>
   <name>view_pitch_offset</name>
   <type>float</type>
   <value><use>view_pitch_offset</use></value>
</uniform>
<uniform>
   <name>view_heading_offset</name>
   <type>float</type>
   <value><use>view_heading_offset</use></value>
</uniform>
<uniform>
   <name>field_of_view</name>
   <type>float</type>
   <value><use>view_fov</use></value>
</uniform>
<uniform>
   <name>use_searchlight</name>
   <type>int</type>
   <value><use>use_searchlight</use></value>
</uniform>
<uniform>
   <name>use_landing_light</name>
   <type>int</type>
   <value><use>use_landing_light</use></value>
</uniform>
<uniform>
   <name>display_xsize</name>
   <type>int</type>
   <value><use>display_xsize</use></value>
</uniform>
<uniform>
   <name>display_ysize</name>
   <type>int</type>
   <value><use>display_ysize</use></value>
</uniform>
(I tried it in both technique 5 and 11 not knowing for sure where it should go)

to model-default.eff

I have wanted search lights like this for as long as I have used FG. Again, hats off, this is a gem.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4989
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480

Re: ALS landing lights

Postby Thorsten » Mon Oct 06, 2014 8:20 am

Nice... you almost figured it out on your own!

Code: Select all
<vertex-shader>Shaders/terrain-haze-ultra.vert</vertex-shader>
<fragment-shader>Shaders/terrain-haze-ultra.frag</fragment-shader>
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>


This is where you specify what shader code is to be used by the technique. ALS has the lowest techniques, with higher quality preceding lower quality. Whenever in the <predicate> section of the technique

Code: Select all
 <property>/sim/rendering/shaders/skydome</property>


appears, then it's an ALS technique.

The lowest technique (5) in model-default utilizes terrain-haze.vert and terrain-haze.frag to render - this makes things tricky, because chances are that your own cockpit is also rendered using the same shaders, so you can't add light the same way as for the others, there needs to be a distance cutoff in addition.

Now comes the tricky part, because a model might be rendered using model-combined.eff or model-combined-deferred.eff, and these inherit from the base effect, i.e. all the parameters you defined in model-default.eff remain in force, but can be overwritten. model-combined.eff brings an ALS technique 4, which is for the fancy models using normal mapping, lightmaps,... etc - so if you're trying to render such a model, it utilizes different shader code:

Code: Select all
<program>
<vertex-shader n="1">Shaders/ubershader.vert</vertex-shader>
<fragment-shader n="1">Shaders/ubershader-lightfield.frag</fragment-shader>
<fragment-shader n="2">Shaders/cloud-shadowfunc.frag</fragment-shader>
</program>



Technically, what you'd have to write to technique 5 would be

Code: Select all
      <program>
        <vertex-shader>Shaders/terrain-haze.vert</vertex-shader>
      <fragment-shader>Shaders/terrain-haze.frag</fragment-shader>
      <fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
      </program>


to include the functions and then make your modifications to terrain-haze.frag - you can't use terrain-haze-ultra.* because that comes with a different set of uniforms which are not declared in model-default.eff, which is probably why it didn't work properly.
Thorsten
 
Posts: 11194
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby wlbragg » Mon Oct 06, 2014 7:06 pm

:D

Image

Thank You!
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4989
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480

Next

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 1 guest