Important Optimization


Optimizing Dynamic Lighting in My Game with a Custom LightManager

In my recent development sprint, I focused on improving the performance of my game by optimizing how dynamic lights are managed and rendered. Initially, the game experienced noticeable frame drops, especially during the first few seconds of gameplay, due to the computational cost of updating all dynamic lights (like torches) every frame.

To address this, I implemented a custom LightManager class that efficiently handles dynamic lights by prioritizing and culling them based on their relevance to the player's position and camera view.

Cluster-Based Light Management

I began by organizing lights into spatial clusters using a grid system. Each light is assigned to a cluster based on its position in the game world. When the player moves, the LightManager identifies nearby clusters and only considers the lights within these clusters for rendering. This reduces the number of lights that need to be processed each frame.

Prioritizing Lights in the Camera's View

To ensure that the most relevant lights are rendered, I incorporated frustum culling with an adjustable offset. This means lights within the camera's view (and slightly beyond) are prioritized. By expanding the camera's frustum slightly, we capture lights near the edges of the screen, ensuring they illuminate the scene appropriately even if their source isn't directly visible.

Files

dist.zip Play in browser
63 days ago

Leave a comment

Log in with itch.io to leave a comment.