Pic 1: Time-lapse of a full cycle achieved in CRYENGINE
We won’t be going over all of these parameters as some of them don’t require any changes for the generic earth like scenario we’re aiming for. We will however cover the sections that we are changing to get a better idea of what they control. We will also go through the process of creating smooth transitions as the time of day changes by using the curve editor.
In this example our goal is to achieve a generic day-night cycle at 45° latitude.
We will begin by opening up our example level day-night_cycle.cry. As you probably noticed the scene is already set up with the cycle, to start from scratch we will have to create a new environment preset. To do that right click on the left side under Presets/File view - > Add -> New and save it as day-night_cycle.xml. To open up an existing preset you will have to select Add -> Existing. Presets are saved in the \gamesdk\libs\environmentpresets folder.
Next we need to set up the Sun direction and the latitude. These values are located under the preset list on the left side of the editor. Set the Sun Direction to 180° so it rises in front of the camera. For the latitude we have to change the NortPole..Equator..Southpole value to 45. These two values are not stored in the environment preset file so you can use the same preset with different settings for orientation and latitude.
The first thing that we need to do before we start setting up our cycle is change the Film curve whitepoint to 4 ( default is 1 ). This can be found under the HDR group in the Environment Editor. We will also be using the new and improved Eye Adaptation mode, to do this open up the console and simply type in r_HDREyeAdaptationMode 1. These 2 values dramatically change the sensitivity to light so they need to be set up properly before changing any of the other parameters.
Pic 3: Location of the Film Curve Whitepoint setting.
Now we are ready to start creating our day-night cycle.
Setting up the Sun
The Sun category contains the settings that affect the color and the intensity of the direct sun light.
Sun Color :
We start off by setting the current time to 12:00 and giving it a slightly yellow tint ( 240, 225, 210 ). This will create a key at that time and update the preview to represent the change we just made. Select the newly created key and set the In/Out tangent to linear.
This value needs to remain constant throughout the day so we will create another key at 09:00 and assign it the same color. For this one set the In tangent to Zero and the Out to linear. Mirror the result at 15:00.
As it nears Dusk/Dawn the sun color transitions into a saturated orange, to set this up change the current time to 06:00 and assign it the appropriate color ( 170, 84, 0 ) and set both In/out tangents to Zero. Mirror this newly created key at the 18:00 time.
At this point it is worth noting that the Sun parameters are also used to control the Color/Intensity of the light coming from the moon, although the moon doesn’t move throughout the night.
To set this up we create a key at 05:56 and give it a blue tint ( 140, 160, 176 ). To keep this constant over the whole night we need additional keys with the same value at 00:00, 18:04 and 23:59 respectively. Change the In/Out tangents for all of these keys to linear.
If you set this up correctly your preview and curves should look like this:
Pic 4: Screenshot of the Sun Color gradient preview and curves.
Sun intensity ( lux ) :
This property controls the illuminance of the sun and as mentioned previously it is important to keep this close to the physically based value. A quick search on the internet comes up with an average illuminance value of 100000 lux for bright sunlight.
Pic 5: Screenshot from the Wikipedia page containing the Illuminance values chart.
Change the current time to 12:00 and create a key with the value set to 120000. The reason why this is higher than real world values is some of the light gets absorbed by the materials giving them a final lux value that’s considerably smaller than the source. We will get back to this once we set up our Sky Light later on.
Now that we have the basis for our Sun Intensity laid out we can go ahead and set up the rest of the keys for this value.
The intensity of the sun diminishes as it gets closer to the horizon so to achieve that we need to set up a few more keys. Change the time to 08:00 and set the intensity down to 110000, do the same on the opposite side at 16:00.
As we get closer to sunset/sunrise the intensity drops very low. We will now create a key at 06:00 with the value set to 5 and mirror the value at 18:00.
Real world measurements read <1 lux values for moonlight, this number is way too small for the engine to still accurately render shadows coming from the moon, so we will stick with the same constant value of 5 for night time. For that we need to set up keys at 00:00 and 23:59.
Making sure the transitions between your keys are smooth your gradient and curves should look like this:
Pic 6: Screenshot of the Sun Intensity (lux) gradient preview and curves.
Sun Specular multiplier :
As you might have guessed this controls the specular contribution of the sunlight. For any realistic lighting scenario this value should always be kept at 1.
You’re probably wondering why we skipped all the way to sky light. The reason is a lot of the settings in the environment editor affect each other. It’s good practice to get the sun/sky settings nailed down before you go into setting up your fog.
Sun Intensity Multiplier
Change the time to 12:00 and set the intensity to 50. At 05:45 and 18:15 drop this value to 1. Create two more keys at 00:00 and 23:59 and set the value to 0. The transition from 0 to 1 gives us the effect of the sky brightening in the area where the sun is just about to set.
Parameters in this section are solely used to compute the sun light scattering through the atmosphere effectively controlling the appearance of the sun disk as well as the hue of your sky. They do not directly affect the rendering of objects in the world (for example, lighting colors and intensities). They do however affect the overall illuminance of your scene through the use of Environment Probes as mentioned earlier.
To get an accurate reading of the illuminance in your level you need to measure it on a surface that’s perpendicular to the sun. We already have a couple of planes set up for this purpose so all you need to do is set r_HDRdebug 1 in the console and simply look at the surface. Keep in mind that turning this on brightens the whole scene so don’t forget to turn it off once you’re done measuring your illuminance.
Pic 7: Planes facing the sun used for measuring full sunlight/shadow illuminance.
By looking directly at the surface we’re getting a reading of approximately 80000 lux. At this point the only source for our illuminance is the sun light so to refine this further we will have to enable the sky light to contribute to it as well.
In order to do that we will need to set up an Environment Probe. This handles indirect lighting effectively acting as ambient lighting that you would normally get from the sky. We won’t get into specifics about Environment Probes ( for that check the dedicated page Environment Probes ) but for now go to your objects tab and under Misc there’s the Environment probe entity. Drag that into your scene, change its size to encompass your whole terrain, make it active and generate cubemap. Keep in mind that any changes that you do to your time of day will require regenerating the cubemap ( It’s recommended to do that with the entity turned off so it doesn’t pick up any lighting information from a previously generated cubemap ).
By doing this we are now getting blue tinted shadows as opposed to pure black and our lux value also jumped up to about 100000 which suits our given scenario.
This controls how much the sun light is scattered by the atmosphere. Set this to 1 for the whole timeline.
The parameters that control the hue of the atmosphere are the Wavelength (R/G/B) values. We only need to set these once for the whole cycle.
Taken from the Wikipedia page on Diffuse Sky Radiation ( also known as Skylight ) we set these values at 650 (R), 550 (G), 450 (B).