Lighting in Fuse-Breaker part 1: Rolling your own basic lighting system

Lighting in Fuse-Breaker is fairly basic, and there’s actually a good reason for that. I could have used Unity Pro’s real-time lighting system, but I want a bit more control and access to it for gameplay purposes (and for a game jam entry, the price is a bit high). Additionally, being able to see the strict boundaries of light and darkness are crucial for the player to judge where is safety and where is danger. A great game that makes use of this (although admittedly not intentionally) is Thief – Deadly Shadows:

Thief Deadly Shadows lighting

Those crisp shadows make it easier to tell where you’ll be seen and where you’ll slip past the enemies. Soft shadows make this a good deal more difficult. As Fuse-Breaker was initially made in only 48 hours, I didn’t have any time to research proper lighting technique. Therefore, the lighting calculations are just based on Euclidean distance from floor panels to nearby lights.

For shadow casting, each floor panel performs a ray cast towards every light in the scene, from closest to farthest. The first light hit by the cast is stored as that floor’s working light. The colour of the floor panel is then set by comparing the light distance to a lookup table of preset colours. Not very elegant, I admit, but when you’ve only got 48 hours…

Finally we have to update the lighting when the doors open or close. Because I was going for quick and functional, we actually update the entire floor when a door changes. Obviously, this is incredibly wasteful and it would be better to only update those panels within range of lights which shine on the door. The following code has since been added, which accomplishes that:

This function, in the Door class, acquires all lights which are within range of the door. When the player opens or closes the door, it tells these lights to update their floors.

And this function, in the Light class searches through every floor and stores a reference to it if it is within the radius of the light. That way we don’t update floors that aren’t affected by this light when this light updates.

Fuse Breaker lighting

And this is the result! Very chunky lighting, but easy to tell where you can tread and where can’t without being detected. It’s also updatable and casts shadows. Any objects that you don’t want to cast shadows from should be put into the IgnoresRayCasts group (or set up a special filter, if you need them to receive other casts), otherwise they will cast shadows during lighting changes. One early bug I grappled with during the first day of the game jam was that random black spots were appearing in the lighting result. It turned out that if the light turned on and the player was in the way, then the player’s mesh was casting a rudimentary shadow!

Leave a Reply

Your email address will not be published. Required fields are marked *