Jump to content

Day/night cycle, best practises?


Recommended Posts

Hello all,

 

I've recently begun working on a day-night cycle system for my game.

 

Synopsis:

The server tracks the time of day, and calculates an opacity value based on that (0.0 for day, 1.0 for night, [0,1] for sunrise/sunset).

The server broadcasts this opacity value to connected websocket clients.

Clients then set the alpha of a bitmap overlay. The bitmap itself is a simple black-to-white gradient image, blended with PIXI.blendMode.MULTIPLY

 

The end result: Day and night cycle gradually (currently takes 2 game-hours for day to switch to night, which equates to a gradual but noticeably eerie 2 real-time minutes).

post-11007-0-39967600-1440242014.png

 

What I want to accomplish is additional light-sources in the games (other players carrying lanterns, flaming projectiles, glow bugs, whatever).

 

My idea for this is to:

(1) maintain an original copy of the bitmap overlay

(2) per-frame, blit all light sources' gradient overlays onto it

(3) render the modified bitmap overlay on the screen

 

Does this seem like a sound design? Are there performance concerns apart from too many light sources? Is there a better way to achieve the end result?

 

Thanks for reading!

- Peter

 

 

 

 

 

 

Link to comment
Share on other sites

I would set the background to black and skip the drawing calls on all tiles that are not in the radius of a light sources, then render the tiles in the radius of a light source normally and at the end I would draw the shadow texture on the coords of the light source.

You want to minimize drawing calls and to keep your shadow texture small.

If you are not rendering per tile then you should just write a custom webgl shader and for canvas keep your current approach.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...