The Theory Behind Atmospheric Scattering

This is the second part of the tutorial on volumetric atmospheric scattering. In this post we will start deriving the equations that govern this complex, yet beautiful optical phenomenon.

You can find all the post in this series here:

You can download the Unity package for this tutorial at the bottom of the page.

Introduction

In the first part of this tutorial, we have discussed how light can be deflected by the air molecules present in a planet’s atmosphere. This process is called scattering, and we have highlighted two special cases. Out-scattering occurs when a ray of light that was directed towards the camera is deflected away from it (diagram below).

Conversely, in-scattering occurs when a ray of light is deflected directly towards the camera.

 

The Transmittance Function

To calculate the amount of light transmitted to the camera, is helpful to take the same journey that light rays from the sun undergo. By looking at the diagram below, is easy to see that light rays reaching C travel through empty space. Since nothing is in their path, all the light reaches C without being subjected to any scattering effect. Let’s indicate with I_C the amount of unscattered light that the point C receives from the sun. During its journey to P, light enters the planet’s atmosphere. Some rays will collide with the molecules suspended in the air, bouncing in different directions. The result is that some of the light is scattered away from the path. The amount of light reaching P (denoted with I_P) will be lower than I_C.

The ratio between I_C and I_P is called transmittance:

    \[T\left(\overline{CP}\right) = \frac{I_P}{I_C}\]

and we can use it to indicate the percentage of light that is not scattered (transmitted) during the journey from C to P. We will explore later the nature of this function. For now, the only thing you need to know is that it corresponds to the contribution of atmospheric out-scattering.

Consequently, the amount of light that P receives is:

    \[I_P = I_C \, T\left(\overline{CP}\right)\]

The Scattering Function

The point P receives light directly from the sun. However, not all that light passing through P is transferred back to the camera. To calculate how much light actually reaches the camera, we need to introduce yet another concept: the scattering function S. Its purpose is to indicate how much light is deflected in a certain direction. If we look at the diagram below, we notice that only those rays of lights that are deflected by an angle of \theta are going to be directed towards the camera.

The value of S\left(\lambda, \theta, h\right) indicates the ratio of light deflected by \theta radians. This function is at the heart of our problem, and we will explore its nature in a future post. For now, the only thing you have to know is that it depends on the colour of the incoming light (indicated by its wavelength \lambda), the scattering angle \theta and the altitude h of P. The reason why the altitude is important is because the atmospheric density changes as a function of the altitude. And the density is, ultimately, one of the factors to determine how much light is scattered.

We now have all the tools necessary to write a general equation that shows how much light is transferred from P to A:

    \[I_{PA} = \boxed{I_P} \, S\left(\lambda,\theta,h\right) \, T\left(\overline{PA}\right)\]

We can expand I_P using the previous definition:

    \[I_{PA} = \boxed{I_C \, T\left(\overline{CP}\right)}\, S\left(\lambda,\theta,h\right) \,T\left(\overline{PA}\right)=\]

    \[=\underset{\text{in-scattering}}{ \underbrace{I_C \,S\left(\lambda,\theta,h\right)} }\,\underset{\text{out-scattering}}{\underbrace{T\left(\overline{CP}\right)\, T\left(\overline{PA}\right)}}\]

The equation should be self explanatory:

  • Light is travels from the sun to C, unscattered in the vacuum of space;
  • Light enters the atmosphere and travels from C to P. In doing so, only the fraction T\left(\overline{CP}\right) reaches its destination due to out-scattering;
  • Part of the light that has reached P from the sun is deflected back to the camera. The ratio of light subjected to in-scattering is S\left(\lambda,\theta,h\right);
  • The remaining light travels from P to A, and once again only the fraction T\left(\overline{PA}\right) is transmitted.

The Numerical Integration

If you have paid attention to the previous paragraphs, you might have noticed an apparent inconsistency in the way intensity have been written. The symbol I_{PA} indicates the amount of light transferred from P to A. However, that quantity does not account for all the light that A receives. In this simplified models of atmospheric scattering, we are taking into account the in-scattering from every point along the camera’s line of sight through the atmosphere.

The total amount of light A receives, I_A, is calculated by adding together the contribution from all the points P \in \overline{AB}. Mathematically speaking, there are infinitely many points in the segment \overline{AB}, so looping through all of them will be impossible. What we can do, however, is splitting \overline{AB} into many smaller segments of length ds (diagram below), and accumulating the contribution of each.

This process of approximation is called numerical integration, and leads to the following expression:

    \[I_A = \sum_{P \in \overline{AB}} {I_{PA}\, ds }\]

The more points we’ll take into account, the more accurate our final result will be. In reality, what we will have to do in our atmospheric shader is to loop through several points P_i inside the atmosphere, accumulating their contribution to the overall result.

❓ Why are we multiplying by ds?

Directional Light

If the sun is relatively close, it is best modelled as a point light source. In that case, the amount of light received at C depends on the distance from the sun itself. If we are talking about planets, however, we can often assume the sun to be so distant that its rays arrive at the planet all with the same angle. If that’s the case, we can model the sun as a directional light source. The light received from directional light sources remain constant regardless of the distance it travels. Hence, every point C receives the same amount of light, and the direction towards the sun is the same for all points.

We can use this assumption to simplify our set of equations.

Let’s replace I_C with the constant I_S, which represents the sun intensity.

    \[I_A = \sum_{P \in \overline{AB}} {\boxed{I_{PA}}\, ds } =\]

    \[= \sum_{P \in \overline{AB}} {\boxed{I_C  \,S\left(\lambda,\theta,h\right) \,T\left(\overline{CP}\right)\,  T\left(\overline{PA}\right)}\, ds }=\]

    \[= I_S   \sum_{P \in \overline{AB}} {S\left(\lambda,\theta,h\right) \,T\left(\overline{CP}\right) \, T\left(\overline{PA}\right) \,ds }=\]

There is another optimisation that we can perform, and it involves the scattering function S\left(\lambda,\theta,h\right). If the sunlight always comes from the same direction, the angle \theta becomes a constant. We will see in a future post how the directional contribution of S\left(\lambda,\theta,h\right) can be factored out of the summation. For now, let’s keep it inside.

Absorption Coefficient

When describing the possible outcomes of the interaction between light and air molecules, we have only introduced two. Passing straight through, or being deflected. There is a third possibility. Some chemical compounds absorb light. The atmosphere on Earth has plenty of chemicals with such a property. Ozone, for instance, is present in the higher atmosphere and is known to react strongly to ultraviolet light. Its presence, however, has virtually no effect on the colour of the sky, since it absorbs light outside the visible spectrum.Here on Earth, the contribution of light-absorbing chemicals is often ignored.

Here on Earth, the contribution of light-absorbing chemicals is often ignored. The same cannot be done for other planets. The typical colouration of Neptune and Uranus, for instance, is caused by the abundant presence of methane in their atmospheres. Methane is known for absorbing red light, resulting in a blue hue. In the rest of this tutorial we will ignore the absorption coefficient, although we will add a way to tint the atmosphere.

❓ What causes the Sun to turn red during the Ophelia storm of 2017?

Coming Next…

In this tutorial, we have derived a very general form of the equations that govern single scattering. The approach described is, in theory, applicable to all translucent volumes receiving light from a single source.

The two key aspects are, of course, the transmittance function T and the scattering function S. In the next tutorial, we will explore their nature, and derive equations depending on the physical properties of a planet’s atmosphere.

You can find all the post in this series here:

Download

Become a Patron!
You can download all the assets necessary to reproduce the volumetric atmospheric scattering presented in this tutorial.

FeatureStandardPremium
Volumetric Shader
Clouds Support
Day & Night Cycle
Earth 8K
Mars 8K
Venus 8K
Neptune 2K
Postprocessing
FeatureStandardPremium

Comments

3 responses to “The Theory Behind Atmospheric Scattering”

  1. Thank you very much! I learn a lot from this.

    1. I’m glad it helped!

  2. […] Part 2. The Theory Behind Atmospheric Scattering […]

Leave a Reply

Your email address will not be published. Required fields are marked *