Well, I figured I’d open with this topic for two reasons:
- I just finished it up and it’s still at the forefront of my mind
- I have some neat pictures of it so I can show you what I’m talking about
There are two components to a basic day/night cycle system. The position of the sun and the moon in the sky, and the colour of the light they cast (or, for the nitpickers, the colour of the light that reaches you.) The position of the sun and the moon determines the angle of the light relative to the viewer.
Some relatively simple trigonometry generates a circular path around the scene by calculating an angle from the horizontal plane using the time of day; the angle for the sun is zero at dawn and increases toward dusk where the angle is 180 degrees. So far, the sun moves across the sky and the angle of light is calculated based on the sun’s position. The lighting looks right in the middle of the day, but around dawn and dusk, it appears unnatural. This is because, in real life, we’re using to seeing a change in the colour of light whenever we observe light from the sun coming at a shallow angle. There’s some important explanation for this, involving the atmosphere and light scattering but that’s beyond the scope of this article. So, we introduce a “sunset colour.”


The sunset colour is blended with the “day sun colour” with the ratio between the two gradually increasing and decreasing as we get closer to and further from dawn and dusk. To accomplish this, I first used cosine to simulate these curves as pictured in fig. 1 where the yellow line represents how much of the sunset colour is getting blended in to the final light colour and the red line represents how much of the day sun colour is blended in to the final light colour. In fig. 1 I’ve labeled dawn and dusk, but you can deduce that the peak of the red line is noon (the midpoint between dawn and dusk.) A canny observer will soon realize that the sunset colour becomes more prominent than the day light colour exactly in the middle of the afternoon and the dawn doesn’t end until the middle of the morning. Clearly, this isn’t how the real world works, a new curve must be found.
The new curves (pictured in fig. 2) are much more satisfying. You can see the drawn out plateaus in the middle of the day, leading into the exchange of dominant colour more tightly around dawn and dusk.
The Result:

Next related task: Generating and lighting clouds and other celestial phenomenon (like stars.)
