“Physically-based rendering” (or PBR) is a concept that’s received quite a lot of attention in recent games. The term itself is somewhat loosely-defined, but essentially it describes techniques which use sophisticated mathematical models of how light interacts with different surfaces and materials – creating more accurate and detailed graphics than those traditionally used in realtime rendering engines. You’ll see it used to great effect in The Order, Assassin’s Creed Unity/Syndicate, and Battlefront, for example.
In Nome, we’re using a similar physically-based approach to create a dynamic sky that accurately reflects a day/night cycle, with atmospheric scattering of light based on calculations described here.
The sky doesn’t simply get darker as daytime turns into night – it changes through a wide gradient of colours depending on atmospheric conditions, and these are modelled using two equations:
Rayleigh scattering occurs when light from the sun gets reflected off tiny molecules as it passes through the atmosphere. Light of different wavelengths gets scattered by different amounts – light with shorter wavelengths is scattered the most, whereas light with longer wavelengths is less scattered.
This explains why the sky appears blue in the daytime, because the blue wavelength light emitted by the sun is scattered all around you and enters your eye from every angle. At sunset, the sky turns yellow/orange/red because, at a shallow angle, the sunlight must travel further through the atmosphere and becomes more scattered – as a result, almost all of the green/blue light is scattered away before it reaches the earth’s surface, leaving just the orangey-red colours. In Nome, we simulate this scattering of light to create rich sunrises and sunsets (and everything inbetween!) to give the player an intuitive visual indication of the time of day, without them needing to always explicitly check the exact time on the in-game clock.
A secondary form of light scattering is “Mie scattering”, caused by light reflecting off larger particles in the air such as dust and pollution. This tends to scatter all wavelengths of light equally, and creates hazy skies and halos around the sun. Mie scattering can also be used to simulate light scattered from water or ice particles in the atmosphere, which is how rainbows are produced. The weather is an important part of Nome’s gameplay mechanic, and Mie scattering calculations applied to the sky gradient helps provide a visual indication of environmental conditions.
Much of Nome’s gameplay takes place in exterior environments in which the main source of light comes from the sky, which we model using the scattering approaches described above. The formulae we use are relatively well-known, and it’s becoming increasingly common to see them used in modern games. However, there’s two things that make our approach somewhat noteworthy:
- Firstly, we’re making a 2d game. You may think that 2D games are simpler to make than 3D games (less dimensions to consider makes it easier, right?) but actually, some things get harder. We need to consider how light will interact with flat sprites, and how they cast reflections and shadows, for example, but without the depth information that you’d normally get from a 3d model. Although the Unity engine which we’re using provides inbuilt functionality for PBR lighting, this doesn’t apply to sprites (in fact, sprites don’t even cast shadows since it’s not considered a common use case), so we’re having to write a custom lighting and shadowing system. But that’s the subject of another post….
- We don’t just have one sun, but twin suns. This shouldn’t be considered unusual – while being most closely associated with the alien planets of sci-fi movies, the majority of stars in our galaxy are part of multiple star systems, so your average alien planet should be expected to orbit two (or more) suns. However, to our knowledge, no other game has modelled a physically-based sky with more than one sun before, and we think it looks pretty good 🙂