razluta / UnityLightsLodSystem

A Unity system to downgrade light quality (all the way to completely disabling them) as the camera gets further or as the light's area of influence is out of frustum with the purpose of improving performance.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unity Lights LOD (Level of Detail) System License

A Unity runtime system to downgrade light (Point, Spot) quality (all the way to completely disabling them or downgrading shadow quality) as the camera gets further (and also based on frustum) in order to improve performance.

The tool has been verified on the following versions of Unity:

  • 2021.3 (LTS)

Branches

  • main = the main active branch of the project, representing the stable main thread approach to the system
  • development-singlethreaded = the (sometimes unstable) development branh for the main thread approah to the system
  • multithreaded = a (very experimental) Unity Jobs + Burst version of the system - may perform better or worse, depending on your own game performance

Features

  • Adjustment of light LOD based on player distance
  • Disable lights that have areas of influence outside the camera's frustum
  • Ability to set custom LOD values for each light in the scene
  • Supports different types of lights (recommended only for Point and Spot)
  • Easy-to-use user interface and setup
  • In editor visual debugging using gizmos (a sphere for the light range - if applicable and a line from the camera to the light that shows the distance)

Installation

To use the Unity Lights Lod System in your Unity project, simply:

Option A) Clone or download the repository and drop it in your Unity project.

  1. Clone or download the repository
  2. Import the UnityLightsLodSystem folder into your Unity project's Assets folder

Option B) Add the repository to the package manifest (go in YourProject/Packages/ and open the "manifest.json" file and add "com..." line in the depenencies section). If you don't have Git installed, Unity will require you to install it.

{
  "dependencies": {
      ...
      "com.razluta.unitylightslodsystem": "https://github.com/razluta/UnityLightsLodSystem.git"
      ...
  }
}

Option C) Add the repository to the Unity Package Manager using the Package Manager dropdown.

The repository is at: https://github.com/razluta/UnityLightsLodSystem.git


Dependencies

While the tool has no dependencies outside of the core Unity Editor and Engine, I recommend using the Unity Lights Audit Tool to first sort the lights in the scene in order to be critical about what lights you are targetting.

Alternatively, you can use the default Unity Search to sort and examine your lights.


Using the tool

To implement the Unity Lights Lod System in your Unity project, simply:

Step 01 - Add the LightLodManager.prefab in your scene (or add the 'LightModManager.cs' script to an empty GameObject in your scene)

You can simply drag the LightLodManager.prefab in your scene. The manager acts as a singleton. The main parameter in the UI is the Update Rate, which dictates how often the the LightLodManager will update LODs in the scene. By default, it is set to 0.1f, which means it will run try to run about 10 times per second.

Step 02 - For each light you want to LOD, add a LightLod.cs script in their GameObject

The LightLod component will be the one to tell the manager what properties we want to LOD on each light. The "Is Disable After Last Lod" property will disable the light after the last LOD's max distance is surpassed. If the light should be visible at high distances, feel free to keep this flag disabled. Note: make sure the min and max distances are not overlapping otherwise you might experience unexpected behavior. Include as many LODs as you need. The screenshot below shows an LOD setup example.


Special notes

Please note that I highly recommend you only use the LOD component on Point and Spot lights. Any type of LODing optimizations would be very noticeable and jarring on other light types.


Use-cases

I recieved enough questions about why this is useful that I figured I would address it: in large dynamic worlds with many lights (especially small range, low intensity point lights), there's a not insignficant CPU cost to the calculating the lights (direct light influence, shadow casting, etc). This tool allows you to significantly reduce (possibly to completely eliminate on some lights, at certain distances) the calculations needed to be performed every frame.

This project is most useful for large levels with many small lights, especially if there are objects blocking the player's line of sight (so they don't see the quality change or the light pop on or off).


Contributing

If you would like to contribute to the Unity Lights LOD System, please:

  1. Fork the repository
  2. Create a new branch
  3. Make your changes
  4. Submit a pull request

License

The Unity Lights LOD System is licensed under the MIT License. See the LICENSE file for details.

About

A Unity system to downgrade light quality (all the way to completely disabling them) as the camera gets further or as the light's area of influence is out of frustum with the purpose of improving performance.

License:MIT License


Languages

Language:C# 100.0%