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!

Re: Sunrises

Postby Thorsten » Sat Jan 07, 2012 3:35 pm

Okay, let's see how this scheme works out.

Does anyone know how to pick up three properties in an effect file and pass them as a uniform vec3 into the shader? I am very bad in effect file syntax. I know how to pass each property as a uniform float and combine them as a vector then, but I'd rather code a proper solution.

I've been working some de-saturating and color rotating the fog beneath clouds - doesn't really do to have bright red glowing fog, as I could witness today sunset beneath overcast skies tends to give bluish light. I'm not quite there yet - the code is okay, but the parameters are badly tuned.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises

Postby icecode » Sat Jan 07, 2012 4:46 pm

Try with this:

Code: Select all
<uniform>
  <name>...</name>
  <type>float-vec3</type>
  <value type="float">...</value>
</uniform>


If this doesn't work, I think there isn't any way to do that, but combining several properties in a vec3 is a possibility.
icecode
 
Posts: 709
Joined: Thu Aug 12, 2010 1:17 pm
Location: Spain
Version: next
OS: Fedora

Re: Sunrises (download in first post)

Postby Thorsten » Sat Jan 07, 2012 5:07 pm

To illustrate what I mean - here's how overcast skies and 3 km visibility look with the default light in predawn - the fog acquires a bright red color, because that is what the ambient light is.

Image

This is how it looks after keeping the intensity fixed, but color-rotating everything (based on light attenuation, i.e. /rendering/scene/scattering and the fog attenuation factor) to a blue-grey:

Image

Quite dark, and this is in fact how sunrises below overcast skies are. The blue hue works *very* nice with the fog later in the day after the sun has risen - this is about 30 minutes later almost at destination (would have been orange-yellow otherwise, but I think this color is the correct one):

Image

The scheme affects only the terrain, clouds and haze though - in the first shots, the airplane itself seen from the sunward side is still colored in red, matching the first shot.

Should we blue-correct the whole light based on /rendering/scene/scattering outside of the shader?

GIT users - if you want to test and comment, download in first post.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises (download in first post)

Postby erik » Sun Jan 08, 2012 10:44 am

Thorsten wrote in Sat Jan 07, 2012 5:07 pm:Should we blue-correct the whole light based on /rendering/scene/scattering outside of the shader?


That would be a good idea. I hadn't thought about that issue yet.

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: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: Sunrises (download in first post)

Postby Thorsten » Sun Jan 08, 2012 3:51 pm

Actually, after studying pre-dawn conditions on a clear day today, it'd be worth thinking about generalizing this to even more situations.

It appears that pre-dawn light is blue rather than red. This makes a lot of sense, since red is direct light out of which the blue has been scattered away, but pre-dawn light it by necessity indirect - it's light which scatters from the high atmosphere which is already illuminated by the sun.

At the moment of dawn, all the shadow regions are still rather bluish, but as the first sunrays hit the clouds and the highest terrain points, things start to get a rosy hue (we can't get this without terrain self-shading of course). Only if there is direct light illuminating a cloud layer from below, and the light reflected from that cloud layer illuminates the ground is the pre-dawn light illuminating the ground actually red.

I've tried to color-rotate the predawn indirect ground illumination in the shader to blue, and the result looks much better, especially looking away from the sun, than keeping it intensity-reduced red. Again, this is something which is best done with the basic light rather than in every shader.

The relevant code for the terrain shader is:

Code: Select all
// change haze color to blue hue for strong fogging
float intensity = length(hazeColor);
hazeColor = intensity * normalize(mix(hazeColor, 1.5* vec3 (0.45, 0.6, 1.0), (1.0 - eqColorFactor)));
hazeColor = intensity * normalize(mix(hazeColor, 1.5* vec3 (0.45, 0.6, 1.0), max(2.0 * (0.5 - earthShade),0.0)));

// also indirect predawn light is blue
intensity = length(fragColor.xyz);
fragColor.xyz = intensity * normalize(mix(fragColor.xyz, 1.5* vec3 (0.45, 0.6, 1.0), max(2.0 * (0.5 - earthShade),0.0)));


Here, eqColorFactor[0,1] is scattering plus the fog attenuation and earthShade [0,1] is the mean light attenuation across the terminator, where 0.5 is at sunrise (i.e. when direct light becomes available).
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises (download in first post)

Postby i4dnf » Sun Jan 08, 2012 4:34 pm

That's what ambient light should be used for.. and yes no matter the conditions ambient light should have a slight blue hue (at least on Earth). A correct setting for the ambient light would make that computation in the shader obsolete, as it's already taken into acount by all shaders.
Btw, the "generic" common fog that's now present in all shaders behaves correctly and doesn't get strange colours in dawn/sunset conditions.
i4dnf
Retired
 
Posts: 743
Joined: Wed Sep 09, 2009 8:17 am
Location: LRBS
Callsign: YR-I4D
Version: GIT
OS: Gentoo Linux ~amd64

Re: Sunrises (download in first post)

Postby Thorsten » Sun Jan 08, 2012 5:49 pm

Hm, after some testing, maybe the light correction *should* remain in the shaders. This allows for the light here to be different from the light there in a really dramatic way, see this:

Image

The mountains further away are already in sun and glow in orange, whereas the near mountains are still in blue darkness - by the time I reached Juneau, the light had already crept past me, which was quite a wonderful scene.

Btw, the "generic" common fog that's now present in all shaders behaves correctly and doesn't get strange colours in dawn/sunset conditions.


The color isn't incorrect as such. After sunrise, if you have a patch of fog being illuminated from the side, the color would be correct. It all depends on the lighting conditions, the presence or absence of clouds,... i.e. on something we need to tell to the shader, not something it can assume.

This

Image

isn't an implausible scene, it could be realized if the layer doesn't extend very much further. Just in pre-dawn conditions when we know no direct light is available, glowing fog is wrong.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises (download in first post)

Postby Bjoern » Sun Jan 08, 2012 6:34 pm

The sunrises in these pictures beat every sunrise I've seen in FSX. Just...wow!
Bjoern
 
Posts: 484
Joined: Fri Jan 06, 2012 11:00 pm
Location: TXL (RIP)
Version: Next
OS: ArchLinux

Re: Sunrises (download in first post)

Postby erik » Sun Jan 08, 2012 8:32 pm

Thorsten wrote in Sun Jan 08, 2012 5:49 pm:Hm, after some testing, maybe the light correction *should* remain in the shaders. This allows for the light here to be different from the light there in a really dramatic way

Ok I'll let it be for now. I've spent a complete day figuring out why the fog color didn't align with sunrise properly and could use a break from it. Also, the new properties for ground-level or aloft will not make it in FlightGear before the new release since it's about a new feature and not a bug fix.

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: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: Sunrises (download in first post)

Postby Thorsten » Mon Jan 09, 2012 9:06 am

Ok I'll let it be for now.


Maybe I spend the time working out the theory using the shaders, and then we have a better picture of what should go out of the shader and is best C++-coded and what needs to remain in. This is like opening a huge can of worms - I fix one issue, but that has repercussions elsewhere, so then some other conditions look unrealistic, so I basically have to make it up as I go along.

Anyway, I had the first flight yesterday in which I actually liked the view facing away from the rising sun, so there's some progress... I'll try to put in some altitude dependence next, for the time being I rewrote terrain and default model shader such that I have complete control of the light and can overwrite gl_LightSource if needed. This isn't efficient, but does the job for development.

I think I'll put some altitude dependence of the shade in and see how it works with tall mountains.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises (download in first post)

Postby Zan » Mon Jan 09, 2012 11:55 am

erik wrote in Sun Jan 08, 2012 8:32 pm:Ok I'll let it be for now. I've spent a complete day figuring out why the fog color didn't align with sunrise properly and could use a break from it.


Do you mean the default, non scattering version of the skydome fog? I tried to trace that positioning bug too, no matter how I rotated the dome, the sunlight color was still off. It's very weird...

Zan
Zan
 
Posts: 123
Joined: Tue Oct 20, 2009 11:28 am

Re: Sunrises (download in first post)

Postby erik » Mon Jan 09, 2012 12:00 pm

Zan wrote in Mon Jan 09, 2012 11:55 am:
erik wrote in Sun Jan 08, 2012 8:32 pm:Ok I'll let it be for now. I've spent a complete day figuring out why the fog color didn't align with sunrise properly and could use a break from it.

Do you mean the default, non scattering version of the skydome fog? I tried to trace that positioning bug too, no matter how I rotated the dome, the sunlight color was still off. It's very weird...

Yes that should be fixed now.

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: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: Sunrises (download in first post)

Postby erik » Mon Jan 09, 2012 12:05 pm

Thorsten wrote in Mon Jan 09, 2012 9:06 am:Anyway, I had the first flight yesterday in which I actually liked the view facing away from the rising sun, so there's some progress... I'll try to put in some altitude dependence next, for the time being I rewrote terrain and default model shader such that I have complete control of the light and can overwrite gl_LightSource if needed. This isn't efficient, but does the job for development

Actually it's not enough to just take the altitude. What you need for proper coloring is the angle between the horizon and the sun at that particular altitude. That's how the current code (based on the viewer location) also works.
Doing it that way causes mountain tops (or high altitude clouds) to take the sun color pre-dawn while the mountain base will still have the darker (night) light at the same time.

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: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: Sunrises (download in first post)

Postby Thorsten » Mon Jan 09, 2012 12:48 pm

Actually it's not enough to just take the altitude. What you need for proper coloring is the angle between the horizon and the sun at that particular altitude. That's how the current code (based on the viewer location) also works.


I have the problem now structured in terms of y-position perpendicular to the terminator (with x being along the terminator shadow line) - if I add altitude dependence to that, I have the same information as the local horizon angle. It then translates into a 'distance of closest approach to the surface' problem for the light ray.

I'm just using a couple of Taylor-expansions assuming earthRadius >> altitude, view range to avoid getting too much spherical trigonometry in - doesn't work 100% from space, but since we just have one real spacecraft...
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Sunrises (download in first post)

Postby Thorsten » Tue Jan 10, 2012 10:01 pm

And... it works (after some serious fight with shader coordinate systems...)

Himalayan predawn sky - only the highest Cirrus clouds are illuminated:

Image

A few minutes later, the summits light up while the valleys are still in deep shade.

Image

Mt Rainier, facing away from the sun, the high clouds are in daylight already...

Image

... and a few minutes later, the summit is hit by the first sunrays.

Image

And a view from the side of Rainier facing the rising sun - the self-shading of the clouds makes them much darker in this view, which is actually correct:

Image

This makes for some really impressive dawn flights :-)
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

PreviousNext

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 3 guests