Board index FlightGear Development Effects and shaders

Moon and Sunlight in shaders

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

Moon and Sunlight in shaders

Postby Necolatis » Fri Sep 06, 2019 4:07 am

What is the difference between fg_SunDiffuseColor and gl_LightSource[0].diffuse?

Is one supposed to be used in Rembrandt the other in default pipeline? It also looks like ALS is using some custom code to generate its diffuse light.

If that is all the case wouldn't it be easier to do all 3 in C++ and just set the gl_LightSource[0].diffuse accordingly, and same for ambient/specular?

Moonlight also seems to be fully defined via custom Effect uniforms, couldn't that be converted to gl_LightSource[1]? ..To avoid doing tons of custom code each fragment and to make life less confusing for shader coders.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Moon and Sunlight in shaders

Postby Thorsten » Fri Sep 06, 2019 5:42 am

If that is all the case wouldn't it be easier to do all 3 in C++ and just set the gl_LightSource[0].diffuse accordingly, and same for ambient/specular?


Light is actually different at every pixel, that's the point of ALS - a high thunderhead might be in full sunlight while the low parts are getting red and beneath it's dark already.

So yes, it would be much easier to not compute light per pixel, but it would take away all ALS does different from the classic renderer - the 'tons of custom code per fragment' is what ALS is fundamentally about.

(And while the position difference in light might not very notable across your aircraft, it is for tall buildings which also use the model shader).
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Moon and Sunlight in shaders

Postby Necolatis » Fri Sep 06, 2019 5:59 am

Makes sense, thanks.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Moon and Sunlight in shaders

Postby bugman » Fri Sep 06, 2019 10:03 am

Adding moonlight as the second OSG light source (or replacing the first one - the sun) is something I looked at. I need to revisit that subject again but haven't had time yet. Note that adding additional OSG light sources is very GPU unfriendly. I first have to find the bug in the ancient ephemeris code causing the exposed moon position to be incorrect and catch in the test suite. Anyway, having moonlight as an OSG light source would allow a lot of the ALS goodness to be ported into the night time scene.

Regards,
Edward
bugman
Moderator
 
Posts: 1808
Joined: Thu Mar 19, 2015 10:01 am
Version: next

Re: Moon and Sunlight in shaders

Postby icecode » Sat Sep 07, 2019 11:23 am

What is the difference between fg_SunDiffuseColor and gl_LightSource[0].diffuse?


gl_LightSource[0] can't be accessed from fullscreen passes. Rembrandt makes intensive use of them (lighting is essentially done exclusively in fullscreen passes), so the light position and color need to be passed manually as non-default uniforms (fg_SunDiffuseColor, fg_SunDirection etc.)

Note that adding additional OSG light sources is very GPU unfriendly.


Not really. Adding the light source to the scene doesn't have any inherent computational cost, it all depends on how you use it in shaders. If we use a simple enough lighting model with a constant light colour (something more simplified than ALS), you are basically adding one or two matrix multiplications to the fragment shader, apart from some basic arithmetic.
icecode
 
Posts: 709
Joined: Thu Aug 12, 2010 1:17 pm
Location: Spain
Version: next
OS: Fedora

Re: Moon and Sunlight in shaders

Postby Necolatis » Sat Sep 07, 2019 9:11 pm

Icecode GL wrote in Sat Sep 07, 2019 11:23 am:gl_LightSource[0] can't be accessed from fullscreen passes. Rembrandt makes intensive use of them (lighting is essentially done exclusively in fullscreen passes), so the light position and color need to be passed manually as non-default uniforms (fg_SunDiffuseColor, fg_SunDirection etc.)


That cleared up my confusion, thanks.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10


Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 4 guests