In a previous article I talked about a simple trick I used to make the clouds more vivid. Recently I added some more effects to the sky, namely : shadows.
Since I forgot to add a gif for the cloud-transparency trick here is one.
Since I use Box2d for physics I experimented a bit with box2dlights. I had some trouble finding an exact way to render shadows in 2.5. So I decided I didn’t need actual shadow on my objects, but I’d rather have some kind of crepuscular rays. (Out of pure lazyness)
To avoid having shadows cast from my world object I created a second Box2d world containing only clouds. I currently have 4 different textures for clouds, so when a new cloud is generated, a spherical box2d object is added at the center. To add some randomness, I also add a small amount of smaller circle shapes in the cloud.
To add some realism and a change the mood of the scene at night, the color of the light is changed to a “blue-er” tone at night.
private void updateAmbientColor(double timeOfTheDay) { final float blueRatio = 1 + (float) Math.sin(timeOfTheDay * (Math.PI) + Math.PI); float minColor = 0f; float maxColor = .25f; ambientColor.b = (maxColor - minColor) * blueRatio + minColor; }
Finally, don’t forget to use the same trick for the shadows : the closer we are, the more transparent !
Thank you for reading so far ! Here is a video of an accelerated day/night cycle for you to judge the end result.
Wow that’s really cool! Awesome stuff, thanks for sharing.
LikeLike