Aurora polaris🌌

Main components

  • Aurora raymarching shader

Tools used

  • Mixture (noise texutres)
  • Unity URP

📝Description

The latest challenge on the Technically Speaking Discord had the theme of "aurora", and as such I had add one to my sky. It is a raymarching shader, which means it is quite performance heavy and somewhat complex, but I think it captures the look and feeling of an aurora rather well.

From a very basic point of view the shader can be summarised as follows. I calculate the intersection points between the view direction and two spheres that represent the atmosphere layer in which auroras take place. These intersections are the start and end point of the raymarch. For each step I calculate the distance and direction from the current ray position towards the planet's centre, which I define as below the camera at \(y = -6.371\)km (the earth's radius). From this direction I calculate spherical UVs using \(u = \frac{atan2(z, x)}{2\pi}\) and \(v = \frac{acos(y)}{\pi}\).

I use these UVs to sample a noise texture multiple times. Each sample is a set of 2 samples, where I pan the 2 in opposite directions and add them together to reduce the directionality of the noise. One noise sample is used to distort a line texture, resulting in the wave motion of the aurora. Another is panned much faster with high density to cause the flickering of the aurora. And a final noise sample is used to breakup the aurora into different parts that move in and out of existence.

The colour of the aurora is determined by sampling a gradient texture, depending on the height of the current ray position. It is goes from purplish-blue at the start of the atmosphere, followed by a bright green, moving towards a turquoise-like colour and ending in a pinkish red. The colour of each raymarch step is then added together and blended additively with the background.

Aurora at start of dusk.
Aurora at end of dusk.
Aurora at night.
Aurora at night.

📘Acknowledgements

There are no notable Acknowledgements for this post, as it is mostly a culmination of previous knowledge. Mainly the previous post on my new skybox and my experience with raymarching shaders for clouds and black holes.

☀️Astronomical skybox🌑