Atmospheric Light Scattering

Atmospheric Light Scattering (ALS) is an OpenGL rendering framework developed for the Flightgear OpenSouce flight simulation. Technically it is a forward rendering scheme utilizing a collection of GLSL vertex and fragment shaders to compute the effect of light passing through an atmosphere filled with haze and clouds to a reasonable accuracy.

Basic idea

When looking at a scene, our attention is inevitably captured by the more spectacular elements - bright specular highlights, reflections in shiny, mirror-like surfaces or bloom effects of bright, blinding light.

However, more often than not, natural scenes are not spectacular. Rather, nature usually is a bit bland and unassuming, and most of all subtle. We all know that a clear sky is blue, but there are for instance subtle variations in the hue of that blue throughout the sky. Likewise, fog is usually some blue-grey, but there are subtle variations dependent on where in a sheet of fog the observer is, where the sun is and what direction the observer is looking at.

The atmosphere and the clouds and hazes it contains are in fact a major player in what we see - especially in a flightsim where we usually observe the scene from high above. In fact, most color values of the pixels we see outside the cockpit are either sky, cloud or at least partially haze.

Early morning haze around Nanga Parbat.

The idea of the Atmospheric Light Scattering framework is to render what light does as it crosses the atmosphere in great detail to reproduce part of the subtlety observed in nature.

Light scattering physics

To first approximation, the normal lighting situation of a scene during daytime is that the sun is high in the sky and illuminates an object, from which reflected sunlight falls into the eye. There are thus two light rays involved in the process – the illumination ray (I-ray) goes from the sun to the object and the observation ray (O-ray) from object to the eye.

In vacuum, that’s all there is to it, and pictures from the surface of the Moon illustrate this – objects remain visible no matter how far away, and any surface which is not in direct light is pitch black.

In an atmosphere, light scattering can affect both the I-ray and the O-ray - there can be in-scattering and out-scattering of light. In-scattering corresponds to light from somewhere else in the scene being scattered onto the object (or into the eye), out-scattering corresponds to light from the sun being scattered away from the object or light from the object being scattered away from the eye. I-ray in-scattering causes ambient (non-directional) light – shadows are no longer pitch black but receive still some kind of illumination. Under a thin overcast haze layer, there is for instance strong I-ray in-scattering – while there is lots of light available, it comes from almost everywhere in the sky and no shadows are cast onto the ground. O-ray in- and out-scattering both cause objects being shrouded by haze, but in-scattering causes a bright haze, out-scattering a dark haze effect. To complicate matters, there are three basic physical scattering mechanisms which can take place: Rayleigh, Mie and diffuse scattering.

  • Rayleigh scattering occurs on very small particles – the air molecules themselves or fine dust (‘dry haze‘). It has no preferred direction, but is much stronger for blue light than for red light. The reason a clear sky is blue is Rayleigh in-scattering on air - whatever point in the sky we look at, there's blue light from the sun scattered into the O-ray during the day.

  • Mie scattering occurs on larger particles – usually water droplets (‘wet haze‘). It has no color dependence, but is much stronger at small angles than at large angles, i.e. Mie-scattered light almost keeps its original direction. Mie scattering is the reason the sun is often surrounded by a bright halo.

  • diffuse scattering isn’t really a distinct elementary process but the effect of multiple scattering processes over which direction and color specific dependence is blurred, hence diffuse scattering has no color or directional dependence. Consider an overcast cloud layer - clearly there is light coming through, but it has no preferred direction (no shadows are cast) and its color is a rather uniform blue grey.

The combination of Rayleigh, Mie and diffuse in- and out-scattering on I-ray and O-ray makes for twelve distinct channels of which ALS computes eleven in at least some approximation.

Mathematically, the in- and out-scattering conditions along the rays form a set of nested integral equations (for instance, the number of light scattered into a direction at any given point of the ray is the integral over all possible directions from which light can arrive times the scattering probability into the given direction - this needs to be integrated in turn over all poins on the ray). ALS solves these equations with a number of techniques - partially numerically, partially by analytically integrating Taylor-expanded versions of the integrand, partially by suitable parametrizations of the approximate result and at times fully analytical for simple density distributions.

To see the effect of different channels, consider the following example rendering the US Southwest north of Las Vegas.

A complex mixture of different haze layers.

There's lots of variation in the hue of the haze. There is a high layer of wet haze which dominates in the Mie channel and makes the horizon appear white, underneath is a stronger wet haze which has a touch of diffuse scattering and is responsible for the visible fog bank just underneath the mountaintops. The higher layers absorb some amount of light which makes the lower layers and the terrain a bit darker. The lowest layer is a dry dust haze which is predominantly active in the Rayleigh channel and gives the terrain a blue tint. All these different layers and channels combine to give the scene a great deal of complexity.

Low light

During the day, the I-ray is typically much shorter than the O-ray because the sunlight crosses the atmosphere vertically. The density of the atmosphere is variable in altitude, but effectively the whole vertical extent correspondsto a length of perhaps 10 km, whereas on a clear day objects 200 km distant can easily be seen. This is why Rayleigh out-scattering for the incoming light is not dominant while the sun is high. When the sun is however low or even below the horizon, the path of the illuminating ray through the atmosphere becomes very long. In this situation, light is no longer white but becomes changed in color (predominantly by Rayleigh scattering). Since the blue component is scattered out of the I-ray most strongly, the remaining light is shifted to red, which is why sunrises and sunsets illuminate a scene in red-golden color hues.

Under such conditions, it is crucially important that light is computed in a position-differential way, i.e. for every pixel separately and not once for the whole scene. This can only be done inside the GLSL code on the graphics card. Consider the following pre-dawn scene:

Predawn sky with the sun well below the horizon.

The sun is well below the horizon, yet the upper atmosphere is high enough to be already illuminated. As the high atmosphere thins rapidly, scattering also fades out as one looks higher, leading to a thin stripe of dawn color along the horizon.

Dawn sky with high clouds already in light.

As the sun rises further, high clouds get illuminated long before the low clouds or the lowest layers of haze and fog. In fact, to get the scene right, it is crucially important to compute lighting twice for every pixel - once for the terrain or object itself, and once for the haze between object and eye. The reason is that it can easily be that the haze itself is illuminated and bright while the terrain behind it is still in shadow, or vice versa, that one sees a brightly lit high mountain summit through low, still shadowed haze.

While often low light scenes are dominated by Rayleigh scattering on the I-ray, this is not always the case. Compare the following two scenes:

If Rayleigh out-scattering of the I-ray is dominant, the whole scene is cast into a strong, golden light:

A glorious sunrise colored by strong Rayleigh scattering of incoming light.

However, if the haze distribution is different, there can be a sizable amount of Rayleigh in-scattering along the O-ray which leads to the appearance of a bluish fog. While the sun position is not drastically different, the whole mood and coloring of the scene is completely changed, yet just as visually plausible:

A muted sunrise colored by Rayleigh scattering along the observation ray.

The role of clouds

Clouds in nature are just localized patches of particularly thick wet haze. Yet rendering them, they cannot be treated by the same techniques as diffuse haze, because they are not computed as volumetric fog distributions (which would make the integral equations prohibitively expensive to do) but as distinct objects placed into the scene. The problem with this is that while their effect in nature is very pronounced (usually they absorb light much stronger than diffuse hazes), they are not part of the scattering integral equations described above.

The ALS framework addresses this problem on multiple fronts. First, Flightgear's weather system passes the relevant properties of the current weather situation to the renderer (i.e. at what altitudes the main layers are, how thick they are, whether there are thicker layers sunward of the current scene and for thick, localized clouds even the location of up to thirty explicit shadows). Second, light scattering effects are rendered on the clouds themselves. For instance, the cloud shader effect lights up thin clouds when sunlight passes through them and strong Mie scattering is active but darkens thicker clouds when the sun is behind them. Since real clouds are a mixture of thin and thick patches, the net effect looks fairly compelling:

A mixture of thin and thick clouds illustrating the role of Mie vs. diffuse scattering.

In low light, multiple effects are approximately taken into account to generate compelling visuals. Among them are shadowing of a layer by thick clouds sunward and above, down-scattering of light from a high haze layer, Rayleigh scattering on observation and illumination ray and Mie and diffuse scattering on the clouds themselves. The general rule is that the more clouds are in the scene, the more muted the colors will be, but dependent on the distribution of the various hazes, the result may be rather different.

Strong cloud cover leads to muted colors of the lower sky with the brighter morning sky seen through gaps in the layer:

Clouds in a predawn sky.

Weak cloud cover in combination with strong Rayleigh scattering leads to subtle pastel hues:

Pastel-colored clouds in a dawn sky.

Optical phenomena in icy layers

If haze is frozen, its optical properties are potentially very interesting. The reason is that dependent on temperature and relative moisture in the air, ice crystals form in various different shapes. Very common at low temperatures are hexagonal columns and plates. Unlike e.g. a dust haze, all constituents of such an ice haze have the same size and shape. Their shape makes them respond to air currents in a characteristic way so they have a tendency to assume the same orientation. Moreover, they are translucent, i.e. allow light refraction and reflection at characteristic angles driven by their hexagonal structure. As a result, a whole host of interesting optical phenomena can be observed in ice hazes.

The most common one is the 22 degree ring which surrounds the sun and tends to occur regardless of the particular shape of the crystals. It is often seen on high diffuse hazes (which are almost always frozen).

If the haze is frozen into hexagonal plates, the ring can be accompanied by 'sundogs', two bright light maxima at the altitude of the sun at the position of the 22 degree ring:

Sundogs and the 22 degree ring in icy haze.

Hexagonal column-shaped crystals lead to a different reflection condition which enhances the light above and below the sun, leading to the appearance of a light pillar when the sun is low in the sky:

The light pillar in icy haze.

Technically, the ALS framework receives the input on the nature of the haze and its crystal distribution from the weather system and renders lights at the appropriate reflection conditions into the haze.

A few closing remarks

Haze is often treated in rendering as a simple device - as a tool to avoid having to display terrain to a large distance for instance. For a good simulation, especially a flight simulation, this is not what should be done. Haze is a major actor in the visuals we see, and hazes are characterized by complex physics - from the way aerosols and dust are often confined into the lowest boundary layer and trapped by a capping inversion to the complicated play of colors at low light.

It seems more tempting to spent graphics card performance on more obvious visual effects than on something as bland as haze, but in fact the resulting visuals are well worth it. After all, haze, clouds and sky is most of what a pilot will see during a flight.

Getting ALS

The ALS framework is merged into the main Flightgear development repository and, including all recent developments, comes automatically with the latest version.
Back to main index     Back to rendering

Created by Thorsten Renk 2015 - see the disclaimer and contact information.