Board index FlightGear Development Effects and shaders

Sunrises (version 1.3 available)

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

Sunrises (version 1.3 available)

Postby Thorsten » Wed Dec 21, 2011 8:57 pm

Edit: The project page for this has been moved to the wiki: http://wiki.flightgear.org/Atmospheric_light_scattering

After staring at a couple of sunsets (a few weeks ago, I used to get nice ones driving home from work for free), I think I have figured out what makes the various colors when the sun is near the horizon: There's very little coming from the atmosphere itself, there's red coming from haze and brighter red from high-altitude clouds. Now, after teaching this to the skydome shader, we get quite plausible results dependent on the availability of clouds and haze.

Very clear air, little clouds brings a red band close to the horizon (where the path through the atmosphere is very long) and otherwise the almost undistorted atmospheric scattering:

Image

A bit more haze in the air increases the band close to the horizon:

Image

A lot of water vapour in the air places us inside a thick layer characterized by diffuse scattering - as a result the rosy color spreads over the whole sky.

Image

With a bit less diffuse water vapour, but more pronounced clouds, also spectacular colorings can appear.

Image

Finally, light shining underneath a layer in nearly overcast conditions gives a somewhat gloomy sunrise:

Image

Now, it doesn't look quite as nice taking off at this point, and the reason is the color mismatch. Flightgear gives us the light for the current location (i.e. in the air, where the apparent sun position is already much above the horizon, but the same light is then used to color the terrain (which I correct for in the terrain shader) and the clouds (which I don't). If anyone has a bright idea how to manage clouds getting the light of 'their' altitude rather than the average light, that'd be really cool.

In principle, I think I can put altitude computations into the cloud shader, the problem is that I'd need the same light function which flightgear runs internally, and also that the cloud shaders are not too fast to start with... So, I haven't really worked that one out yet.

Edit: For anyone who wants to try - version 1.2 is the latest copy of the shaders with the sunset/sunrise code. This makes lightfield rendering switchable (by the skydome scattering shader selector) and ignores other shaders if running.

The package is running on 2.7, for anyone who has a 2.6 release version 1.0 should be working instead.

For best effect:

* skydome scattering shader -> on
* all other special shaders (water, urban, terrain, landmass, transition,...) -> off
* random vegetation -> off
* Advanced Weather -> on

(all other settings may or may not cause rendering artefacts).

For the time being (= till I get to fix this properly everywhere and make new packages), start with --prop:/sim/rendering/scattering-shader=true
Last edited by stuart on Wed Apr 25, 2012 10:43 am, edited 11 times in total.
Reason: Add link to wiki page, update version number at Thorsten's request
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises

Postby Johan G » Wed Dec 21, 2011 10:45 pm

Beautiful screen shots.

I'll bet you already have a sensation watching real sunrises, from both the fact that real life so full of complex interactions and yet still seem so simple and beautiful, and from that sunrises are such a challenge to replicate. :)
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: Sunrises

Postby erik » Thu Dec 22, 2011 10:52 am

The internal lighting code got quite complicated over time but maybe it's time to explain it a bit. The C++ code can be found in the FGLight::update_sky_color function in src/Time/light.cxx

There we have a base_sky_color[] (red: 0.31, green: 0.43, blue: 0.69) and a base_fog_color[] (red: 0.63, green: 0.72, blue: 0.88)
The overall color gets influenced by:
    * the humidity (/environment/relative-humidity)
    * saturation (/rendering/scene/saturation)
    * scattering (/rendering/scene/scattering)
    * overcast (/rendering/scene/overcast)
    * sun_angle (/sim/time/sun-angle-rad)
    * sun_color (/rendering/dome/sun)
    * ambient_tbl (read from data/Lighting/ambient)
    * diffuse_tbl (read from data//Lighting/diffuse)
    * specular_tbl (read from data/Lighting/specular)
    * sky_tbl (read from data/Lighting/sky)

visibility_log is set to: log(humidity*45.0)/11.0
visibility_inv is set to: (45000.0 - visibility_log) / 45000.0

ambient is set to: (interpolate(ambient_tbl(sun_angle)) + visibility_inv/10.0) * saturation
diffuse is set to: interpolate(diffuse_tbl(sun_angle)) * saturation
specular is set to: interpolate(specular_tbl(sun_angle)) * visibility_log * saturation
sky_brightness is set to: interpolate(sky_tbl(sun_angle)) * saturation

// Fog and Cloud color
sqrt_sky_brightness = (1.0 - sqrt(1.0 - sky_brightness))*_scattering
fog_color[] = base_fog_color[] * sqrt_sky_brightness
sky_color[] = (base_sky_color[] + (1.0-base_sky_color[])*overcast) * sky_brightness
cloud_color[] = base_fog_color[] * sky_brightness
ambient_color[] = fog_color[] * ambient
diffuse_color[] = scene_color[] * diffuse
specular_color[] = sun_color[] * specular

Code: Select all
// adjust the cloud colors for sunrise/sunset effects (darken them)
if (sun_angle > 1.0) {
   sun2 = sqrt(sun_angle)
   cloud_color[] = cloud_color[] / sun2
}

After this we correct all the colors for gamma:
Code: Select all
system_gamma = 2.5
function gamma_correct(color[], reff=2.5, system = system_gamma)
{
   if (reff != system)
   {
      tmp = reff/system;
      color[] = pow(color[], tmp)
   }
}

gamma_correct(fog_color[], gamma)
gamma_correct(sky_color[], gamma)
gamma_correct(cloud_color[], gamma)
gamma_correct(ambient_color[], gamma)
gamma_correct(diffuse_color[], gamma)
gamma_correct(specular_color[], gamma)

The resulting colors can be found under/rendering/dome
But this still does not correct for view angle (towards or away from the sun)
Last edited by erik on Thu Dec 22, 2011 11:42 am, edited 1 time in total.
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: Sunrises

Postby erik » Thu Dec 22, 2011 11:41 am

Updating the colors to correct for view angle is done in FGLight::update_adj_fog_color
gamma = system_gamma
color[] = scene_color[]

sun_color[red] = color[red]*color[red]*color[red]
sun_color[green] = color[green]*color[green]*color[green]
sun_color[blue] = color[blue]*color[blue]

visibility = CLAMP(visibility, 0.0, 45000.0)
adj_visibility = 0.87 - (45000.0 - visibility) / 83333.33
sun_influence = CLAMP(0.5 - cos(sun_angle*2.0)/2.0, 1e-4, 2.0)

sun_hor_norm = abs((sun_angle_hor - PI) / PI)
fact = adj_visibility * pow(sun_hor_norm*sun_hor_norm, 1.0/sun_influence) * 1.0639 * saturation * scattering
fact_inv = 1.0 - fact

gamma = system_gamma * 0.9 * sun_influence * adj_visibility
gamma_correct(fog_color[], system_gamma, gamma)

adj_fog_color[] = fact_inv * fog_color[] + fact * sun_color[]
gamma_correct(adj_fog_color[], gamma)

gamma_correct(fog_color[], gamma)
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: Sunrises

Postby Thorsten » Thu Jan 05, 2012 5:23 pm

Some progress...

First, the global view, i.e. what is actually causing a lot of the effects: Earth's shadow moving across terrain and clouds:

Image

(now more or less seamless, after a hard fight with the skydome shader geometry and modifications of the cloud shader not to have bright clouds over dark terrain).

From the ground, it darkens clouds and terrain in predawn conditions, which looks very compelling:

Image

Image

Once clear of Earth shadow from the air, it looks pretty much as before:

Image

Image

Now, we need some solution for the light... Erik, how difficult would it be not only to write out the light at the aircraft position but also the light if aircraft altitude would be zero, or would be 30.000 ft? If that can be done, we should be able to keep cloud colors consistently altitude-independent.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises

Postby erik » Thu Jan 05, 2012 5:40 pm

Hmm, calculating for every altitude would be quite math intensive I would guess. Maybe just add ground level and at some altitude (40km?) and use linear interpolation between the two would be enough?

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: Sunrises

Postby xiii » Thu Jan 05, 2012 5:45 pm

/me speechless....

Not only you guys are awsome programmers, but now you are pushing FG on step ahead in the great classical painting domain :-)
How far are we from seing FG screenshots hanging on a Nationnal Gallery wall?
If the engines are Pratt and Whitney, the seats best be Martin Baker
xiii
 
Posts: 472
Joined: Tue Jan 08, 2008 11:04 pm

Re: Sunrises

Postby Hooray » Thu Jan 05, 2012 5:53 pm

wow, that's indeed quite impressive!
We need to upload these screen shots to the wiki, so that we can use them in the "picture of the week" column and in the newsletter! That will be great PR for FG!
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Sunrises

Postby erik » Thu Jan 05, 2012 6:04 pm

Thorsten wrote in Thu Jan 05, 2012 5:23 pm:Erik, how difficult would it be not only to write out the light at the aircraft position but also the light if aircraft altitude would be zero, or would be 30.000 ft? If that can be done, we should be able to keep cloud colors consistently altitude-independent.

I see the clouds layers are kept under /environment/clouds/layer[*] and every layer has an elevation above zero if active. In theory it should be possible to add a color/red, color/green and color/blue property to every active layer then.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: Sunrises

Postby someguy » Fri Jan 06, 2012 5:03 am

Screenies = jawdropping.

Thorsten, when you're done with this, how about modeling the Green Flash? ;)
User avatar
someguy
 
Posts: 1650
Joined: Tue Nov 25, 2008 6:54 am
Location: USA
Version: 2019.1.1
OS: Mac OS X 10.11.6

Re: Sunrises

Postby sgofferj » Fri Jan 06, 2012 5:06 am

...and soon, we'll need at least 8 cores at 5GHz, 48GB RAM plus 4 GeForce GTX999+ in an SLI cluster just to get FG at least started... :lol:
Just kidding... Looks amazing Thorsten! Great work!
FG 3.1 GIT / Opensuse 12.3 / Phenom II X4 / GForce GTX560
Stefan's little Flightgear corner | The Finnish Weather Center | Wolves in Finland

Working on: EFTP
COM: IAX2:home.gofferje.net/stefan (MO-FR 0700-2000 UTC, SA+SU 0900-2000 UTC)
sgofferj
 
Posts: 789
Joined: Mon Dec 05, 2011 5:13 pm
Location: EFTP
Callsign: OH-SW
Version: 3.1 GIT
OS: Opensuse

Re: Sunrises

Postby Thorsten » Fri Jan 06, 2012 9:40 am

Hmm, calculating for every altitude would be quite math intensive I would guess. Maybe just add ground level and at some altitude (40km?) and use linear interpolation between the two would be enough?


Yes, that was what I had in mind - just ground level and 30.000 ft (40 km is a bit too high even for Cirrus clouds, and these are about the highest objects I want to illuminate). The shader can then interpolate.

I see the clouds layers are kept under /environment/clouds/layer[*] and every layer has an elevation above zero if active. In theory it should be possible to add a color/red, color/green and color/blue property to every active layer then.


That works fine with Global Weather, but isn't good with the more general Local Weather altitude concept - think of a Cb tower, it's altitude isn't well given by a layer altitude, its top might be in brighter light whereas the bottom is already dark. Layer altitudes get you only so far, some types of clouds just don't fit well.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises

Postby fredb » Fri Jan 06, 2012 10:01 am

I see the clouds layers are kept under /environment/clouds/layer[*] and every layer has an elevation above zero if active. In theory it should be possible to add a color/red, color/green and color/blue property to every active layer then.


That works fine with Global Weather, but isn't good with the more general Local Weather altitude concept - think of a Cb tower, it's altitude isn't well given by a layer altitude, its top might be in brighter light whereas the bottom is already dark. Layer altitudes get you only so far, some types of clouds just don't fit well.


You could interpolate between the layers. Accuracy should be better with an interpolation table instead of simply 2 points
User avatar
fredb
 
Posts: 753
Joined: Fri Dec 01, 2006 11:41 am
Location: Paris, France

Re: Sunrises

Postby Thorsten » Fri Jan 06, 2012 12:07 pm

In my experience, the cloud vertex shader is a very delicate place to put additional stuff in because it is performance-critical. For instance, I could not use the haze layer shading I use for terrain and skydome in the cloud vertex shader since this cut my framerate by 2/3 but had to settle for a simplified scheme.

Two interpolation points means passing two more uniform vectors into the shader, with an interpolation table with n entries we need to pass n vectors and interpolate a table rather than execute a single linear function.

On the other hand, accuracy is not an issue - we're not getting the correct light unless we include inter-cloud shadowing anyway (with the sun coming horizontally, that is a very big issue!), the main thing I want to fix is that the cloud color doesn't depend on airplane altitude any more.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises

Postby erik » Fri Jan 06, 2012 12:28 pm

Ok, let's start with ground-level and aloft colors then.

Update:
I plan on adding a third diffuse color at 9km (the highest mountain of the world) which could be used for terrain altitude shading.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Next

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 3 guests