spenibus.net
2014-04-12 09:49:29 GMT

A simple day night cycle, part 6 - A better skybox.

Step 11: The skybox. -- So we added a skybox. And then the sky was bright and blue all the time. Even at the darkest hour of the night. Our illusion now broken, we make the life changing decision of becoming a cheese maker somewhere in the alps. Or we just fix the damn skybox. Your choice. The next 2 pictures show one of the default unity skyboxes being added to the scene and the issue it raises: Broken night: ![](http://spenibus.net/f/g/1l) Broken sunrise: ![](http://spenibus.net/f/g/1k) To eliminate this perpetual day, we add this at the end of "Update()": ```` RenderSettings.skybox.SetColor("_Tint", skyboxColor); RenderSettings.fogColor = skyboxColor; ```` This will change the material color of the skybox according to the current phase. We also match the fog color with the skybox color. Which leads to this: ![](http://spenibus.net/f/g/1e) ![](http://spenibus.net/f/g/1f) While the skybox material is affected by our colors, said colors are diluted because the texture itself is blue. We also have a sun drawn directly onto the texture. We solve this by using a greyscale skybox texture. This will not affect our colors beyond luminosity. We also delete the sun since we have our own physical sun in the scene. It's a simple modification of the original textures, as illustrated in the following picture: ![](http://spenibus.net/f/g/1j) Using this new set of textures shows our colors as intended, as seen in the following 2 pictures: ![](http://spenibus.net/f/g/1m) ![](http://spenibus.net/f/g/1n) We now have a skybox with a dynamically changing color reflecting our phases. Everything is in place, and it would all be well if there wasn't a tiny issue: The sun and the moon are invisible. This is the end of part 6. Then comes [part 7](http://spenibus.net/b/p/8/A-simple-day-night-cycle-part-7-Visibility-scale-and-trickery-also-the-end).