Light baking in Unity and the use of Bakery plugin
What is light baking?
Light baking is a technique used to optimize performance in Realtime applications like video games and VR applications.
This technique is used to pre-calculate light information, like shadows and reflections, offline before running the application and packing this light information into textures called Light maps, which are then combined with the materials' textures during runtime to give the light and reflections effect without the need to calculate them real-time, thus improving performance.
GameObjects are categorized into 2 categories:
Static objects: Objects that do not move relative to lights in the scene, like walls, floors, mountains, meaning that neither they move relative to the lights or the light moves relative to them
Non-static objects: Objects that move in the scene relative to the light. Like players, NPCs and so-on.
Lights are categorized into 3 categories:
Baked Lights: Lights that have their light data baked into textures for static game objects offline. These lights will not have impact on non-static objects.
RealTime lights: Lights that have their light data calculated during runtime.
Mixed Lights: They have the power of both Baked and Realtime lights. They will have their light data baked for static objects before runtime, and their light data calculated during runtime for non-static game objects. So, it offers the optimization needed for static objects and the correct light information for the non-static objects
In order to bake lights for a static game object, you will need 4 things:
GameObject must be marked as Static and contribute to Global Illumination
GameObject must be properly UV unwrapped to be able to receive lightmap texture.
Note: There is an option in Unity to create a new UV for Light maps when importing an FBX file
Also, if you have multiple UVs (one for material texture sand one for Light maps),you are able to swap the UVs from the FBX import options
The light(s) that are to be baked must be marked as Baked or Mixed
Sky and Fog Volume(Set it as Global to impact the entire scene, or local for only part of the scene)
Light baking in Unity:
In order to view light settings in Unity, you can view Lighting settings from here:
You need to create a new Lighting settings and adjust these settings, the most important settings are:
LightMapper: Specifies which device will bake the lights. CPU is most accurate, however, it takes a very long time. GPU is much faster.
LightMap Resolution: Specifies the resolution for each light, the higher the value, the more quality for shadows and light information, however, the longer the baking will take.
Max LightMapSize: The resolution of the light map texture, the higher the value, the sharper the quality you will get for shadows and light information, how ever, the longer it will take.
Max Bounces: The number of times the indirect lights bounces after being reflected on surfaces that is calculated in the bake. Every step increase increases the light baking time significantly.
Once you hit Generate Lighting,Unity creates a folder inside the path that has your scene with the same name of the scene and saves the light maps
Bakery Unity Plugin:
Bakery is a paid Unity plugin that simplifies the light baking in Unity. It automatically detects the optimum settings for light baking and the optimum device for baking in your system.
Bakery requires a specific script to be added to all lights that are to be baked using it. The main scripts are:
Bakery Direct Light Script: To be added for Direct lights
Bakery Point Light Script: To be added for Point lights
Bakery Sky Light Script: To be added for Sky lights
Bakery Light Mesh Script: To be added to Area Lights
If you bake without adding the needed scripts, the lights will not be baked.