Very cool . Rakastan! This almost calls for a "Romantic atmosphere screenshot challenge" .One little issue - when I set the time to "night", I get this... I suppose, that isn't intended? Although it looks kinda cool too!

2d clouds don't seem to inherit the current light, they're probably emissive white. I'm not sure if they're actually maintained any more, if they do have a maintainer, it'd probably be a good idea to set them to the ambient light and to give them a few more interesting textures.

Anyway, there's a reason I am working on sunset/sunrise conditions... The skydome scattering shader looks much more realistic, but it needs a lot of support structure to blend properly into everything else.

There was a time FlightGear 0.9.x-ish) where everything you saw and everything you heard in FlightGear was influenced by work that I'd done (pre-shaders!) but looking at this I'm glad you took over and took it to the next level. Nice work Thorsten!

I have to say, I enjoy this a lot. I've always admired clouds and atmosphere and light effects when I was travelling by airplane, and it is great to have the chance to not simply hope that eventually someone will make a flightsim that includes all I'd like but to simply put it in myself.

Although, it is occasionally frustrating... Now that I had the skydome blend the terminator line seamlessly with the terrain edge after a long fight, the altitude dependence screws everything up of course for any really high terrain, since the skydome assumes that terrain which isn't actually loaded is at zero elevation. Which makes up for a pronounced mismatch in the Himalaya region, where even the plains reach easily 10.000 ft.

So, the skydome needs to be told the altitude of the surrounding terrain somehow. Which we can do at least withing Local Weather because the terrain presampling is running anyway and contains that info...

Also, somehow the lighting of the aircraft itself is not in sync with the terrain - possibly (again) a case of different coordinate systems. It's something that can drive me mad at times...

Would a simple LOD system be useful? I've been wanting to work on one for a while, but it's such a huge undertaking. I need to finish up my current projects in the next couple of months, but would be interested in helping out.

I am thinking of a very simple proof of concept with just 2 levels of detail, where we can load very simplified terrain (2-4 triangles per tile, and a single generated low-res texture per tile). Obviously this will pop when switched to the high level of detail, and have tremendous gaps. But the transition would happen very far from the user. The terrain could then be visible to the horizon, and from space we would simply have a huge textured sphere.

If we get something that's workable, perhaps we can then add intermediate LOD levels, stitch gaps, etc...

Your sub-orbital experiments are leading me to believe that 16 levels of detail may not be necessary.

Very - it'd ease the load on the shaders a lot, and the skydome wouldn't have to fake terrain any more. And a textured sphere from space, possibly combined with 2d orbital cloud textures, would certainly look better than a fog sphere.

... and the next try - now the mean terrain altitude info as generated by Local Weather's presampling system is passed on to the skydome shader, which adjusts the terminator position accordingly. This is a bit better, but still generates seams at the edge of visibility, so... for the purpose of lighting computations, we force the terrain elevation at the visibility edge smoothly down to the mean value as passed to the skydome shader, and so the seams disappear again.

The only remaining problem I see now is that the light everywhere changes with aircraft altitude - so I'll wait for Erik's fix to be pushed after new features are again possible. Or maybe I'll experiment with my own light model inside the shader in the mean time just to make nice screenshots

Cloud coloring: Actually the color of light reaching you changes quite rapidly when increasing altitude at sunset. Take of from an airport and observe the sun color and you'll see what I mean. So the color change is not linear and only using 2 points for interpolation probably will not be correct. But give it a try anyway. It just has to look good enough and having a gradient will already make a remarkable difference.

When I was busy with coding the "new" sun implementation several years back I was studying the effects of sunrise and sunset quite extensively. I always had the impression that sunrises have a more rosy/pink quality while sunsets are more orangey-red. May be this is because of the earth's shadow or just because the atmosphere is cleaner after the night.

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.

True - as Erik says what is taken in account is the angle, but actually what I did was calculate the distance the light has to travel through the atmosphere - which depends on the angle.

The sun implementation also considers two further things: 1) The earth is not a perfect sphere (ellipsoid, thicker at the equator), so the path distance of the light rays will differ depending on latitude.2) The thickness of the atmosphere varies. It is thickest around the equator and thinnest around the poles. Since the difference is up to 10 or more kilometers this will have an impact on scattering. So both of these effects should have an influence on the amount of scattering depending on the viewers latitude.

And of course particle density is taken in account - both depending on the altitude (based on the standard model) and as a proxy the viewing distance. I also investigated into particle data. Emissions do make a considerable difference. For example there are spectacular sunsets in big cities like Bejing or Mexico City. I found some interesting datasets that could have been used for an implementation. But I thought this was too much work and not enough benefit.

Eventually we should consider unifying the color calculation of the sun and the shader. Then we could for example turn off the outer halo. This would also take care of the airplane coloring problem you mentioned (which one of the halos colors). I also always wanted to add a gradient to the sun itself (and the halos) by just adding an upper and lower color with linear interpolation. This is actually very easy to implement. But I currently don't have anything set up for developing anymore.

Cloud coloring: Actually the color of light reaching you changes quite rapidly when increasing altitude at sunset. Take of from an airport and observe the sun color and you'll see what I mean. So the color change is not linear and only using 2 points for interpolation probably will not be correct.

Yes, I've worked that out on the way home yesterday. What should enter the color model is the length of the light through the atmosphere. We can't do that, we can do it for the local position of the airplane, but not for every pixel in the scenery.

So it has to be an effective shadow 'wedge', the projection of which on the ground is the terminator, and where you are in this 3d shadow wedge determines (aproximately) light intensity *and* color. Inside this wedge, the effective forward shift in shadowing conditions goes like sqrt(2 * R * altitude) with altitude where R is the Earth radius - if you plot that, you note that indeed that is a rapidly growing function initially.

1) The earth is not a perfect sphere (ellipsoid, thicker at the equator), so the path distance of the light rays will differ depending on latitude.

2) The thickness of the atmosphere varies. It is thickest around the equator and thinnest around the poles. Since the difference is up to 10 or more kilometers this will have an impact on scattering. So both of these effects should have an influence on the amount of scattering depending on the viewers latitude.

I suspect the variation of lighting with aerosols and water vapour is *much* more significant than that, so unless we start getting control over those, there's no need to delve into this.

The problem is, quite simply stated, that you need to compute a different color for every point in the scene - not just for the sun, or for the airplane position - for a suborbital view for an area of ~200.000 km^2 actual scenery and 3.200.000 km^2 skydome posing as scenery and all in all ~2.000.000 pixels with 20+ fps. So whatever scheme you have better be *really, really* fast, and that means approximations to geometry and plausible-looking schemes instead of actual calculations.

Okay, I have a working implementation of a lightfield which is based on the (rgb) values of the default Flightgear lighting on the ground and extrapolates that forward/backward from the sun and in altitude based on effective angle with the sun, taking the surface normal with the sun into account to generate some shade where it should be,

In other words, each position you see gets approximately the light assigned which would be computed if you would be in that position. This makes no difference during the day, but is quite dramatic at sunrise/set since the light 100 km or 1 km higher towards the sun is completely different from the light at the current position.

It actually looks sort of okay from low altitude - the colors are maybe a bit larger than life...

Light illuminating as a function of altitude:

Just dawn:

A bit later:

Yet a bit later:

The terminator is now nicely shaped by mountain ridges with seamless blending that the visibility range. The colors just look very wrong from high altitude.

I've been thinking for a few hours what is wrong here, since these *are* pretty much the colors Flightgear would put on the ground, and they don't look bad on the ground or from low altitude, till I figures out that you would see the whole scene from high altitude through a (much thinner) layer of brightly illuminated haze, effectively leading to an altitude-dependent de-saturation of the colors - which is presumably just what is missing. I'll try that next...

Another cute thing is that it's quite easy to add moonlight to the night side - just some background diffuse light term will do nicely.