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!

Re: ALS landing lights

Postby wlbragg » Wed Oct 08, 2014 8:13 am

No idea - is it peculiar to the model in question?


It appears to be any model with no texture is just showing up white. Can that be addressed without having to create a texture for the model?
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
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 wlbragg » Wed Oct 08, 2014 8:50 am

Alright, I just verified what I did against what you just said and I did it all according to what you said.

In water.eff I had added
Code: Select all
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>

to the <programs> section and added all the uniform information.

I also had added the appropriate additions to water_lightfield.frag.

I was pretty sure I understood what to do and you just verified I was correct.
So I still don't understand why I am getting the "call to undefined function" error. Its there, were it is suppose to be.

I'll go ahead and post the pertinent code for documentation purposes.

water.eff
Code: Select all

<technique n="1">
....
....
....
<program>
   <vertex-shader>Shaders/water_lightfield.vert</vertex-shader>
   <fragment-shader>Shaders/water_lightfield.frag</fragment-shader>
   <fragment-shader>Shaders/cloud-shadowfunc.frag</fragment-shader>
   <fragment-shader>Shaders/hazes.frag</fragment-shader>
   <fragment-shader>Shaders/secondary_lights.frag</fragment-shader>   
</program>
            
<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>


water_lightfield.frag
Code: Select all
uniform int use_searchlight;
uniform int use_landing_light;

vec3 searchlight(in float dist);
//I'm still using old version for now.
vec3 landing_light(in float dist);


//I wasn't sure about this but haven't got that far yet.
if (use_searchlight == 1){
   finalColor.rgb += searchlight(dist);
}
if (use_landing_light == 1)   {
   finalColor.rgb += landing_light(dist);
}

Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
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 » Wed Oct 08, 2014 10:32 am

Hm... I don't see anything obvious. What I would do next is to copy-paste the searchlight function from secondary_lights.frag directly into the water shader code where all the water-specific functions are defined and see if that cures the problem - if yes, it's the way the function is referenced in the effect.

Maybe the various fragment shader functions also want indices - <fragment shader n="1">... and so on - I'm not really sure when this should be used, it always seems to be working for me.
Thorsten
 
Posts: 11189
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby Hooray » Wed Oct 08, 2014 10:41 am

Did you really ever have to add explicit indexing to your effects files ? That would be interesting but unexpected - internally, the GLSL compiler will take all sources and compile them into objects to link them together - if some effects work/stop working once you change explicit indexing, that would suggest that something else is going on - normally, this should only affect compilation order - but as long as you're using forward declarations and/or include files (preprocessor directives), the compiler should not be bothered by re-arranging your sources.

The C++ code will internally run the equivalent of a Nasal foreach() loop and then compile each file, and finally link all objects together. So I don't quite see why/where this might fail?
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: 11375
Joined: Tue Mar 25, 2008 8:40 am

Re: ALS landing lights

Postby Thorsten » Wed Oct 08, 2014 10:42 am

I didn't ever, but I know that Emilian and Fred have used it now and then - presumably for some reason (?)
Thorsten
 
Posts: 11189
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby wlbragg » Wed Oct 08, 2014 4:27 pm

What I would do next is to copy-paste the searchlight function from secondary_lights.frag directly into the water shader code


That was my first reaction, but not knowing this code that well, I didn't want to go off on some "less than desirable" path, especially if it was something else causing it. I'll try to combine it.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
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 » Wed Oct 08, 2014 4:56 pm

I'll look into water tomorrow myself and see if there's anything specifically bothersome. I think I have the base code under control now, I managed a rather credible illumination of the fog at low visibility today, so then the rest of the work is less difficult.

it's pretty freaking cool watching this - I mean, turning this into a little night vision/FLIR gadget by using a greenish filter would seem entirely possible now and it would also look incredibly cool, overlaid with a HUD, our combat folks should be pretty excited about this, and it probably won't take long for someone to come up with a Canvas-based sniper scope


Yeah, we could do an extra run with different light color and distance fading behavior to implement this. Let's see...
Thorsten
 
Posts: 11189
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby wlbragg » Wed Oct 08, 2014 10:35 pm

Something else is happening even if I remove all my shader modifications were getting

Code: Select all
opengl:4:..\..\..\..\flightgear\src\Viewer\fg_os_osgviewer.cxx:193:glLinkProgram "" FAILED

opengl:4:..\..\..\..\flightgear\src\Viewer\fg_os_osgviewer.cxx:193:Program "" infolog:
Fragment info
-------------
0(24) : error C1013: function "rand2D" is already defined at 0(53)
0(32) : error C1013: function "cosine_interpolate" is already defined at 0(57)
0(40) : error C1013: function "simple_interpolate" is already defined at 0(65)
0(45) : error C1013: function "interpolatedNoise2D" is already defined at 0(71)
0(99) : error C1013: function "Noise2D" is already defined at 0(91)


This is with the initial #e91a6f3 commit.

Unless it is also in another shader those functions are in water_lightfiled.frag

Tried using #ifndef on the entire shader but it still is seeing the functions twice.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
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 wlbragg » Thu Oct 09, 2014 3:38 am

I made a little progress.
Technique 2 in water-inland.eff and moving secondary_lights.frag code into water_lightfield.frag.
Image
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
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 wlbragg » Thu Oct 09, 2014 4:30 am

Thorsten, I have some info that might mean more to you than it does to me.

First off.
I was able to get the secondary_lights.frag code to work WITHOUT having to move it into water_lightfield.frag. It works correctly using

water_inland.eff
Technique 2
secondary_lights.frag in <programs> with water_lightfield.frag edited with the normal uniforms and functions.

Now some things I figured out during the process.

The secondary_lights work without any code to any water eff or frag files on the ocean but not on inland water with shaders on minimum (or off i guess?). Arranging the code as per above in Tech 2 of water_inland.eff and appropriate code in water_lightfield.frag the secondary_lights work at the highest shader level on BOTH inland water and ocean. I found that strange, but I'm sure that make sense to you. It must have to do with water inheriting effects from terrain-default.

Now the other interesting thing. The "already defined" error is only happening if I start FG with <use-searchlight type="bool">true</use-searchlight> set to true in preferences.xml and have "shaders' on high (not sure if it is a specific one) and I move over from land to water. I KNOW, that if I start up with <use-searchlight type="bool">true</use-searchlight> set to true in preferences.xml and immediately shut down the shaders before moving then turn them on after I move over water with the light, I don't get the error. Go figure?

One more thing,
is this the correct place and way to use the functions in water_lightfield.frag?
They are the last thing before the final gl_FragColor = finalColor, yet in both tree-haze.frag and terrain-haze.frag, rather than adding them twice, they are before the if statements "if (dist > 0.04 * min(visibility,avisibility))".

Code: Select all
if (use_searchlight == 1){
      finalColor.rgb += searchlight(dist);
   }
   if (use_landing_light == 1)   {
      finalColor.rgb += landing_light(dist);
   }
   
   gl_FragColor = finalColor;
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
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 » Thu Oct 09, 2014 5:19 am

Okay, I think I remember what's peculiar about water.

At low water shader quality, water isn't rendered separately from the terrain, i.e. it runs via terrain-default.eff - since you modified that to allow light, light works for water out of the box.

At high water slider, the techniques in water.eff kick in, and only then do you need to modify the specific water shader code. Now, the peculiar thing about water is that there are two effects (water.eff and water_inland.eff) sharing the same shader code (but calling it with somewhat different parameters). So the function not found error was presumably caused by you modifying water.eff whereas the water you were seeing was initiated by water_inland.eff, and in that effect, the secondary_lights.frag wasn't initially in the program section. So if you alter the water shader code, you need to modify two effect files rather than one to pass the right parameters and access the functions you need.

They are the last thing before the final gl_FragColor = finalColor, yet in both tree-haze.frag and terrain-haze.frag, rather than adding them twice, they are before the if statements "if (dist > 0.04 * min(visibility,avisibility))".


At that stage, you actually add them _after_ fogging, which isn't what you want - you'll see that if visibility is <100 m, everything will go black at night, because fog color is black at night, so finalColor.rgb of a heavily fogged object will also be black, and then when you light it up, you multiply your light value with black and it'll be black. Or, if you add the light value (which you should only do if the object you add it to is a light color itself), then you'll get a featureless grey. You want to add light after texel color and before fogging.

Since the function branches just before fogging, you don't have to insert anything twice.
Thorsten
 
Posts: 11189
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby wlbragg » Thu Oct 09, 2014 5:42 am

Crystal clear, thank you!

I see you did tree.eff and tree_ALS.frag in addition to fog, does this mean your going to do the works, including model, water etc.?
I'm only asking because if you are then I'm done here and I'll leave off with, thank you and is there anything you would like me to do, writeup or doc's or anything?

I merged back into your latest commit and everything is working including my model and water additions using your syntax and arrangement..

light_distance_fading NICE!

:D

EDIT:
This is what happens when you know what your doing. This is the results after Thorsten placed the light shader code in the right place using the right combination of light filtering settings that he created. Notice it now picks up the water color when the version that I made didn't.
Also note, these pictures were taken with the shader and effects code merged into 3.2 RC2 not 3.3.

Image
Image
Image

These are showing all the different shader elements, except fog.
Image

Model, water, tree and land. All in one shot.
Image

OUTSTANDING!
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
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 wlbragg » Fri Oct 10, 2014 8:18 am

ALS secondary lights and Rayleigh haze for urban effect are in, yeah!

Image
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
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 » Fri Oct 10, 2014 4:50 pm

I see you did tree.eff and tree_ALS.frag in addition to fog, does this mean your going to do the works, including model, water etc.?
I'm only asking because if you are then I'm done here and I'll leave off with, thank you and is there anything you would like me to do, writeup or doc's or anything?


I sort of realized when illuminating the fog that I had to go over a lot of shaders with this, and there's some tricky issues (like getting the specular channel to work as well, which is relevant for water, buildings and glossy models). I'm still not quite sure up to what quality level I will implement this, it's still very much fluid.

In any case, I hope you won't consider the work you did wasted. You are all in all rather interested in shaders, and it'd not be a bad thing if you come to the level where you can do small experiments and changes yourself according to what you need - and one needs to start somewhere with that, so I tried to pass some of the information on how effect and shader files tie. Maybe non-expert speech writeup would be good (there's README.effects, but I understood that only after I had worked it all out from the existing examples myself...)
Thorsten
 
Posts: 11189
Joined: Mon Nov 02, 2009 8:33 am

Re: ALS landing lights

Postby wlbragg » Fri Oct 10, 2014 5:40 pm

I hope you won't consider the work you did wasted


Not at all.
I am somewhat familiar with GLSL by working with it in c++ programming. Things like creating a heat map for a keno game to see if the random number generator had any patterns to it. What I was totally unfamiliar with is how FG was setup to allow a user to create and use custom shaders without touching the c code. Absolutely brilliant imho. Now I am up to date on that aspect, so this was an exercise I greatly appreciated.

I sort of realized when illuminating the fog that I had to go over a lot of shaders with this, and there's some tricky issues (like getting the specular channel to work as well, which is relevant for water, buildings and glossy models)


Exactly, and that is where if is really difficult for anyone, short of someone extremely experienced, or the original author to make major changes and enhancements. I found that out as soon as I saw the specular aspects.
I worked with the model again last night to see if I could figure out the models without texture and only specular and after a couple hours decided it will wait for your handy work. I can't wait to see how it's done.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480

PreviousNext

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 1 guest