TDS2: The past 3 weeks of lighting

There hasn't been a blog post in a while because on top of my game development, I have been busy working 57 hours a week across two dead-end jobs to try to keep my finances afloat while I continue on my search for a software development job.

I have been working on a top-down shooter. I don't want to talk too much about the plans and would rather have the current work speak for itself, because things are always subject to change as the game becomes more fleshed out.

Currently, it doesn't even have a name. It's simply called TDS2 for Top Down Shooter 2. Yes, there was a TDS1.

I figure I would describe the development of the project so far in general terms, not going too heavily into the details.

By April 20th

This is my game prior to trying to implement lighting. The basic elements of a TDS, not that there are really that many, are there, fog of war included. For my particular game, lighting would play an critical role in both the planned stealth aspects of the game along with the general atmosphere. For that reason, it would be unwise to not get something so fundamental to my game out of the way first.

I had dabbled with 2D lighting in the past in the failed experiment described here.

By May 1st

I was going to write a detailed writeup about how exactly I did this, but a short explanation will suffice for now. I generate a "visibility mesh" for each light, representing the area that can be lit by a given light. This mesh is then colored with a gradient that goes from white to the color of the darkness depending on the distance from the light origin. All of these gradients are rendered to a render texture, which is then multiplicatively blended in with everything else to darken parts that are not lit.

The darkness color can be any arbitrary color, so this supports day, night, dusk, dawn, etc.

Most solutions I've seen online only care about just the visibility part (mainly for calculating line of sight stuff for stealth games), or just the lighting part (interaction with walls is not considered). I needed both so this does both.

By May 6th

I implemented simple weapon lights and more lighting features such as flickering and crackling (like, from a fire. Not really shown in the video sadly). Lights interact with each other far less offensively than they had in my naive lighting gradients post, but it still looked not great.

By May 16th

I made the lights blend in together much more nicely, and honestly just look much nicer in general. All I really had to do was apply gaussian blur to the lighting texture before it was multiplied to the rest of the scene. This video also showcases how movable light-blocking objects such as doors interact with the light. Fog of War was temporarily disabled because honestly, the lighting color would sometimes appear through the fog of war. The video quality on this was also pretty atrocious, regrettably.

By May 17th

I got the lighting to play nice with the fog of war, at the cost of colored lights becoming more "clear". This is not really a pro or a con and is more of a stylistic thing, but I did believe the foggier lights fit more with the atmosphere I was trying to produce. That can be decided later, however.

With the lighting system more or less completed, I decided to put it into use. Lights can be combined with each other to create composite lights. This is used for the player's weapon light, to both make it far more realistic and honestly far more usable. Muzzle flashes also illuminate the surrounding area, but just like real life, this only really shows in areas without much lighting.

Aside from lighting, the screen shake was tuned a bit to have an angular component too, but the screen shake will probably be completely redone.

What next?

This isn't to say that I am completely finished with the lighting system, but as of now I'm fairly happy with where it is currently at and would rather work on other parts of the game.