A system that allows for switching lightmaps at runtime. Allows for switching for individual renderers, switching for light probes and smooth switching by lerping.
- Switching between pre calculated lightmaps and light probe data at runtime
- Allows for individual control of lightmap and light probes for specific bounds, rather than a whole a scene
- Allows for lerping between lightmaps and light probe data
- Several performance settings to save on CPU and memory usage
- Create a new
LightState
scriptable object, found in the create asset menu under "Runtime Lightmap Controller". - Bake lighting for a specific lighting state of your scene (such as all lights on), then create a new folder anywhere in the assets folder and copy paste all of the generated lightmaps into this new folder.
- Add the copied textures to the
LightState
, be sure that the textures array index matches its position in the lightmap arrays. Note: Be sure you add the copied textures and not the original! - Press
Store Current Baked Light Probes
. - Repeat for all light states you need for a scene. (all lights off, all lights a different color, etc)
- Create a new empty game object and add the
LightSwitcher
component to the game object, each scene needs a differentLightSwitcher
. - Add all
LightStates
to theData
array, the first index in the array will determine whatLight State
is set upon starting the game. - Create a new empty game object and add the
LightBoundDefiner
component, this component allows you to switch the light maps for everything within its bounds. - Add the newly created
LightBoundDefiner
to theLightSwitcher
bounds array. - Create as many as needed for the scene (one per room for example) and scale so it covers all static game objects and light probes. (if you have any)
- Press one of the
Get Static Renderers
buttons and then press theGet Probes Within Bounds
button.
Should Warn About Static Nonuse Of Lightmap
: Will warn if a static game object is found within bounds and doesn't make use of lightmap when trying to switch lightmap data for bounds. Disable this bool if this was intentional.Will Use Smooth Light Transition
: If this is disabled, you will save a small amount of CPU and memory usage when starting the game. This will also prevent you from calling the smooth transition methods.
This system is pretty well optimized, but using the smooth transition methods can be quite costly. (especially if you run this for multiple LightBoundDefiner
at once) The smooth transition also requires quite a bit of preparation when the game is first started. If performance is a concern: consider disabling smooth transitions all together. This can be done under the Tools/Runtime Lightmap Controller
menu, found at the top of the screen.
This package is licensed under the MIT License. For more information read: LICENSE
.
You also need to manually enable shadow mask support under the Tools/Runtime Lightmap Controller
menu.
Since switching lightmap and light probe data involves a lot of switching and editing arrays, there are times where the system can break if it is constantly in use.
The use of UPM Git Extension is highly recommended, for easy updating of this package.