Using Light Probes and Loading Scenes Additive
If you are using Unity prior to Unity 2019.3, and want to load in adjacent scenes using LoadSceneMode.Additive with light probes and couldn’t bake them all together in one bake (using a manager scene to store light probes for all the scenes), then you have a small issue to deal with. Unity uses the light probes from the last scene loaded. This will cause light probes from your already loaded scene to no longer function, and will cause lighting issues on any renderers that rely on light probes within the previously loaded scene.
A WORK AROUND
When I first started exploring this solution, I came up with an idea. Since I need to have dynamic object lit correctly in my scene, why don’t I just copy the renderers of the connecting scenes fo baking purposes (with the lightmap resolution set to 0 for these meshes). so that I can get the
First off, this solution requires a bit of coding knowledge to get it working as the steps are quiet involved.. Secondly, I’m sure it not the only way to tackle the problem , but its the solution we came up with for our project.
Caveats
Because the light probes copied, don’t belong the current scene, its possible to get double lighting on any object that is lit by a light of the other scene. This is most apparent with directional lights as they light everything. We mitigate this in one of ttwo ways.
Designing our scene to prevent the issue by making sure directional lights are only on when nesaary.
Using non static renderers to block the light using shadow only.
For our game, The Living Remain we use load in scenes additively when the player reaches the end of a scene. Our scenes, are much too large to bake all lighting in the scenes together as they cannot fit in memory simultaneously. We use an asset called Super Scene Baker to manage the baking for us. It allows us to bake all of the scenes in our game with one click and I recommend it for any project that requires multiple scenes to be baked. We built our solution baking light around this tool after doing it manually for a while (I know…totally nuts!). This also allows us to automate the whole process and save a lot of time in the process.
Without further ado, here are the steps
Copy light probes from adjacent scenes
Bake lights for the scene
Copy light probe values from adjacent scenes
1 Copying light probes from adjacent scenes
Quick Note
When automating the copying of light probes, its important to keep track of which scenes a particular light probe group belongs. We do this by using tags on the light probe group GameObject. So if we create a new light probe group and place it in a scene, its tagged as LightProbeGroup. Once our automated process copies the scene, it tags the copy as AdjacentLightProbGroup.
2 Bake Lights For All Scenes
This is by far the easiest part of the whole process, as its just baking the scenes individually as normal. Keep in mind that at this step, all the scenes should have their own light probe groups along with any light probe groups from adjacent scenes.
Note: They adjacent scene light probes will contain values that aren’t correct or usable until we copy the values from the source scene.
3 Copy light probe values from adjacent scenes
This step is a little tricky. We need to copy the light probe values, but the values are stored in LightmapSettings.lightProbes.bakedProbes and LightmapSettings.lightProbes.positions so we don’t know what light probe group each individual light probe belongs to .
The solution we came up with is when copying the light probe values, we also store their world position and compare this to all of the baked light probes in the scene. If its not found, then we know its from an adjacent scene and we can safely populate the values.
There are a few additional things.
Before we start each bake, we do some house cleaning, such as deleting previous adjacent light probe groups as there may have been changes.
Also, because the light probes copied, don’t belong the current scene, its possible to get double lighting on any object that is lit by a light of the other scene. This is most apparent with directional lights as they light everything. We mitigate this in one of ttwo ways.
Designing our scene to prevent the issue by making sure directional lights are only on when nesaary.
Using non static renderers to block the light using shadow only.