spenibus.net
2014-04-10 03:20:29 GMT

A simple day night cycle, part 4 - The other phases.

Step 9: All the other phases -- The logic behind a phase's computations being now explained, we can quickly go over the remaining phases. We blend from sunrise to day: ```` // sunrise, part 2 else if(timeLogic.hour >= 7 && timeLogic.hour < 8) { blendFactor = (timeLogic.daySecond - 7f * 3600f) / 3600f; sunColor = Color.Lerp(colorLightSunrise, colorLightDay, blendFactor); moonColor = Color.black; skyboxColor = Color.Lerp(colorSkyboxSunrise, colorSkyboxDay, blendFactor); ambientTint = Color.Lerp(colorLightSunrise, colorLightDay, blendFactor); moonTint = colorMoonDay; sunIntensity = sunIntensityMax; moonIntensity = 0f; } ```` Nothing special during the day: ```` // day else if(timeLogic.hour >= 8 && timeLogic.hour < 20) { sunColor = colorLightDay; moonColor = Color.black; skyboxColor = colorSkyboxDay; ambientTint = colorLightDay; moonTint = colorMoonDay; sunIntensity = sunIntensityMax; moonIntensity = 0f; } ```` We blend from day to sunset: ```` // sunset, part 1 else if(timeLogic.hour >= 20 && timeLogic.hour < 21) { blendFactor = (timeLogic.daySecond - 20f * 3600f) / 3600f; sunColor = Color.Lerp(colorLightDay, colorLightSunset, blendFactor); moonColor = Color.black; skyboxColor = Color.Lerp(colorSkyboxDay, colorSkyboxSunset, blendFactor); ambientTint = Color.Lerp(colorLightDay, colorLightSunset, blendFactor); moonTint = colorMoonDay; sunIntensity = sunIntensityMax; moonIntensity = 0f; } ```` We blend from sunset to night: ```` // sunset, part 2 else if(timeLogic.hour >= 21 && timeLogic.hour < 22) { blendFactor = (timeLogic.daySecond - 21f * 3600f) / 3600f; sunColor = Color.Lerp(colorLightSunset, Color.black, blendFactor); moonColor = Color.Lerp(Color.black, colorLightNight, blendFactor); skyboxColor = Color.Lerp(colorSkyboxSunset, colorSkyboxNight, blendFactor); ambientTint = Color.Lerp(colorLightSunset, colorLightNight, blendFactor); moonTint = Color.Lerp(colorMoonDay, colorMoonNight, blendFactor); if(timeLogic.minute < 30) { sunIntensity = Mathf.Lerp(sunIntensityMax, 0f, blendFactor*2f); moonIntensity = 0f; } else { sunIntensity = 0f; moonIntensity = Mathf.Lerp(0f, moonIntensityMax, (blendFactor-0.5f)*2f); } } ```` This is the end of part 4. Then comes [part 5](http://spenibus.net/b/p/6/A-simple-day-night-cycle-part-5-Applying-the-loop-values).