stormwarestudios Posted August 22, 2015 Share Posted August 22, 2015 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). 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 Quote Link to comment Share on other sites More sharing options...
Sebi Posted August 22, 2015 Share Posted August 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.