Optimize Baked Lighting in Unity
Baking is a process that extracts and stores information from the geometry of an object, which can then be used to drive vertex-based processes later on. This is done in order to reduce the number of resources needed for an asset during run time. Even though baking is an extremely useful thing to use in your projects, it can also wreck loading times so, let’s take a look at one of the most optimal ways you can use to bake lighting in Unity!
Objective: This article will explain to use bake lighting in Unity, and how you can maximize its effectivity by using Contribution GI.
Table of Contents
· Why use Baked Lighting?
· Baking Lights in Unity
· The Result
∘ Summary
Why use Baked Lighting?
You have two alternatives for rendering a static light in a video game: Realtime Lighting or Baked Lighting, you can also use mixed lighting for both but we’ll focus on looking at these individually and why you may want to use bake lighting instead.
Realtime Lighting — Realtime lighting can be used to cast realistic shadows and specular highlights on both dynamic(moving) and static objects(non-moving). By using Realtime lighting, the information is put through the pipeline of shaders where it needs to calculate everything around it at every frame as it travles on screen. This complex set of processes can be very expensive.
Baked Lighting — Baked Lighting is used for static lights, soft shadows are present but there are no specular highlights and dynamically lit objects don’t cast shadows. The way Baked lighting works is by gathering data from the textures surrounding the light source and generating a lightmap for subsequent use. The lightmap is then used to pre-calculate the brightness of the surfaces. Unity does not incorporate these Lights in any run-time lighting calculations; instead, it calculates the illumination from them beforehand. Since this is not being calculated frame-by-frame, it’s a lot less expensive to use.
Despite this, Baking can still wreck load times, especially if you’re using auto-generate. Let’s take a look at how we can make things run smoother!
Baking Lights in Unity
- First, let’s make sure you have access to the Lighting window in Unity. You can open it by going to Window →Rendering → Lighting.
Feel free to dock this beside the Inspector for a cleaner layout.
2. Set your light source of choice to Baked
If you are using an emissive object rather than a regular light, you can still use baked lighting.
3. Select your static objects(the ones that won’t be moving in your scene) and use this drop-down menu to toggle Contribution GI. If you don’t toggle this or at least make your objects static, they won’t be affected by your baked lights at all.
Let’s pause for a moment and talk about Contribution GI or Contribution Global Lighting, this is one of the most important bits to speed up your baked load times.
Historically, indirect lighting has only been employed in non-real-time applications such as CG animated films because the calculations needed for it were too slow to be used in video games and other real-time graphics applications. Games can get around this restriction by only calculating indirect light for surfaces and objects that are known to be static beforehand. All the otherwise slow calculations can be done before run time and any indirect lighting is pre-calculated so that everything is still accurate during runtime. Source
Alright! Back to the step-by-step!
4. In your Lighting window, make sure that Progressive GPU then clicks on Generate Lighting.
You will notice this blue bar at the bottom right of your screen, which means your baked light is loading. Loading times can depend on your hardware.
The Result
For my Control Room scene, I used area lights and emissive textures. The emissive textures are complimented by area lights which are shaped to fit the emission zone of each object.
Summary
Use baked lighting to avoid the over-taxation of resources in your project but still achieve beautiful visuals. To make your bake time smoother and less time-consuming, make use of Contribution GI.
I hope you have found this information valuable! Follow me for more Unity Development articles! :) I am a video game narrative designer on a journey to learn more about Unity Development and Software Engineering.