itch.io is community of indie game creators and players

Devlogs

Lighting System - Optimization

Slimegeon
A downloadable game

Author: Zak Levine

Date: April 28, 2023

A significant aspect of all dungeons is ominous lighting. The developer must address two central elements to integrate lighting into the dungeon successfully. The first is visibility. The player should be able to see their surroundings and enough of the dungeon to make it playable and fun. The second issue is performance. Many separated lighting sources can cause performance to drop heavily, so the lights need to be optimized to where they cost little for the performance.

The first part of setting up lighting was spawning the lights themselves. I created two light objects—one that generates on the walls and spawns on the ceiling. Every wall has a torch, while only 1/3 tops will spawn a light. The ceiling lights are brighter and have more attenuation, distance, and fog distance than the torches. To make the rooms more visible, I turned all the lights and particles on in a room when the player entered, and I turned them all off when the player exited. The method differs from the lights in the halls that act on a collision radius to turn on. The radius creates a fantastic visual where the torches light up as the player walks through the tunnel and turns off the further they walk through. Since the ceiling lights only have a 33% chance to spawn, that may create a few dark areas within the dungeon where the player may not have the best visual.

I added and altered many changes and functionality to increase performance:

  1. By default, I made all the lights and particles off and only turned them on when the player entered the correct room. I added a collision box that turns the lights and particles on for the torches not in rooms when the player is within its range.
  2. I altered the attenuation, max distance, and fog size. The alteration significantly improves cost and performance since the lights do not intersect as much and dim or darken fully when the player is out of range.
  3. The main issue with the lighting for the performance was shadows.

Since everything is procedural, the shadows and lights cannot be baked; also, Unreal treats all of the shadows, including those from static objects, as dynamic shadows. To figure this out, I turned off dynamic shadows and found no shadows, even from stationary objects; however, this was the most significant performance boost.

Overall, I created the lighting system without a significant performance cost. The system needs work and can be altered, but the core working features are there.

Leave a comment