I'd like to simulate a day/night cycle, and am thinking to do this with two components:

  • an underlay to simulate sky color, accompanying either an alternating cloud or star rotation animation containing lots of transparency depending on time of day. The sequence for the sky's color-shifting is the focus of this post.

  • a translucent overlay for the ground, which may or may not tint for color, but would reflect light intensity for time of day.

Looking at similar posts on this site, the authors were interested in either an intensity curve between black and white to reflect the non-linear way sunlight changes (useful for my overlay objective), or just a handful of states (night, dawn, noon, dusk). My game has a realistic look and feel, and I'd like to try for subtle shifts in chroma.

While I'm interested in precision, I don't care about accuracy for a particular lat/long or time of year. A generic light cycle model would do, and, if I do decide to simulate seasons, I'll just adjust the proportion of light vs. dark length in the daily sequence.

At a minimum the day/night simulation would take a minute. 30 fps * 30 seconds = 900 frames. Besides adjusting how many frames I spend on each step, I imagine I would also be padding this by stretching out how long the animation stayed at pitch black or high noon.

An alternate solution would be if I could find a time-lapse video of the sky throughout the day. With GIMP and the GAP plugin, I could turn this into a texture atlas I can use in my game (I'm programming in Java libGDX, btw). Even if the video were focused on landscape and not the sky, if I just had a tiny, unobstructed patch of the sky in frame (a pixel, even) I could crop the video to that portion of the frame and expand it to fill the screen later in my game. I've not found any such videos though. Besides a google search, the site I've used the most to find videos to deconstruct is www.videezy.com

Minus a sequence chart, or a video, I'll start experimenting with sequences. My first thought is to start from black, and then plot a path mostly along the edge of the RGB color cube: black(255,255,255)->magenta(255, 0, 255)->red(255, 0, 0)->yellow(255,255,0)-[diagonal from yellow to cyan, bypassing green]->cyan(0,255,255). I'd step through all the states between each of these vertices in a straight line, and, upon reaching the endpoint, I'd reverse the sequence.

  • \$\begingroup\$ It sounds like you have multiple workable plans for how to get the colour sequence you need. How have you tried putting these plans into practice? Are the results unsatisfactory for your needs? In what specific way can we help you improve upon your current solution? \$\endgroup\$ – DMGregory Jul 7 at 19:41
  • \$\begingroup\$ I have little faith that my RGB sequence idea will be any good out of the box - nature is not that linear. It's just the only place I could think of to start. If someone else had a related sequence to share it could save me potentially days of guess and check as I tweak mine into something that looks right. Alternatively, any sites for timelapse videos that I may have overlooked could be very helpful. \$\endgroup\$ – RocketScienceGuy Jul 7 at 20:03
  • \$\begingroup\$ Finally, if there are standard design patterns for simulating realistic day/night cycles known by more experienced developers, I'd love to learn from their experience and would be happy to let go of the path I cooked up out of nothing above. \$\endgroup\$ – RocketScienceGuy Jul 7 at 20:08
  • \$\begingroup\$ Would you be interested in analytical formulas like those often used in physically-based rendering? \$\endgroup\$ – DMGregory Jul 7 at 20:15
  • \$\begingroup\$ I had been thinking of set of color values, but you're right, a formula to derive those values would be just as good. Thank you for helping me see another way to solve/search the problem. \$\endgroup\$ – RocketScienceGuy Jul 7 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.