In this tutorial I detail the components that go into making the Atmocity day/night cycle. First off, the cycle itself has no function on gameplay, it is instead just cosmetic and can be turned on or off at any time or switched from the in game clock to the system clock so that da/night corresponds to system time.

All in all, it's a fairly simple system, although it has many small components. First of all, the sky cube map is given a color gradient. This color gradient is also applied to the sun lighting, so that the color matches well.

The exposure curve tones down the exposure of the skybox in the evening, night and morning time, so that there is a larger contrast between day and night.

The second curve, visibility curve, is used to trigger when buildings will turn their lights on. To preserve performance this is a simple on/off of the Emission module in the Unity Standard Shader. I also use the sharedMaterial setting to preserve more performance and avoid instantiating too many materials. Currently all changes to the emission module occur at the same time in the visibility curve. However, I will move this so that individual building types will be triggered at different times in the curve. Once I am closer to finishing the game, I will also retest performance and see if unique materials for each building will work or if it becomes too heavy.

The solar and moon renderers are the renderers for the sun and moon. Aside from the sun and moon being rotated around the sky, the sun fades out during the night when the moon is faded in instead.

The different day/night cycle options are controlled via a delegate. This is the delegate for the option to cycle using the in game clock. In terms of code, this might come to change. Especially things like length of day etc. Currently the variable inGameTime runs between the values 0 to 1 and is used to evaluate what color should be used for the sun and skybox. Similarly the value is used to determine the exposure value and when to trigger the building lighting.

On the building side of things, the emission map is loaded at all times. Emission is the triggered on or off turning the lighting on or off. Currently, I only use black and white emission maps, but might introduce some with specific colors etc. to avoid having to set this value on a lot of buildings if I end up changing my mind. It's easier to automate using a script in Photoshop, than to change material properties in unity after all.

There's still some work required to make the system exactly the way I want it. Moving things over to being triggered at different times and adding street lights and other small details to each building will really bring things to life.

Here's the end result in a time lapse video:

Post a comment

Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.