Unity VR Optimization : Light Probes

If we want to have dynamic lighting in our games, we should learn how to use Light Probes.

Light Probes are an invaluable tool in Unity for creating realistic lighting effects. These probes store information about how lighting behaves in a particular area and can be used to create dynamic lighting effects. This blog post will discuss how to use light probes in Unity. 

This process is kind of similar to how we baked our lights in the previous blog post. If you haven’t gone over that tutorial, I highly suggest doing so here.

Setting Up the Scene

For this tutorial, feel free to use your own projects, but make sure they have these minimum requirements to successfully implement Light Probes.

  • URP (Universal Render Pipeline) setup
  • Lights in Scene
  • Objects that aren’t moving set to Static
 

As an example, I’ll show what my Scene looks like and explain what I’ve put in it.

In my scene, I’ve placed two Spotlights facing that ground. I have two different floors, which each have their own color. This will be important to show off light bouncing on different colored surfaces that will then reflect that colored light. We also have a ball that will stay Dynamic and be able to move throughout the Scene.

With this simple setup, lets kick things off by baking our first Light Map.

Our First Bake

Our project should already have the URP setup. Let’s now bake our lights and see what is working correctly and what isn’t.

  • Select all objects that we do not intend to move and set them to Static
  • Set our lights to Mixed or Baked
    • Mixed – This will allow us to have Dynamic Shadows, but at a greater cost to performance.
    • Baked – This removes Dynamic Shadows, but will help performance.
  • Go to Window -> Rendering -> Lighting
    • Click the bottom right button that says Generate Lighting
There are greater details in how to optimize our baked lighting, but for this tutorial we’re just going to use the default settings.

Notice that the wall behind now has a tint of red/blue due to the light bouncing off the ground and onto the wall. Our scene looks great, but there is a major problem with the Dynamic Ball in the center.

First the Dynamic Ball doesn’t have any of the bouncing color that we’d expect. In fact, it doesn’t have any illumination at all! 

Baked
Mixed

We can also see the difference between using the Baked vs Mixed light settings in these pictures. 

The Mixed lights up our Dynamic Ball when it is directly underneath it and produces a shadow, but it’s still missing that light red color that we see on all the other surfaces. 

The Baked lighting does no lighting or shadows at all for our Dynamic Ball. 

So how can we get the same colored lighting on our Dynamic objects without absolutely destroying our performance?

Light Probes

Now comes the help of Light Probes to our Scene. When we add them and bake our lighting, each probe will store precalculated information about how light should behave around each probe in the Scene.

This ultimately saves us a lot of computational power by doing the work upfront in order to give us realistic dynamic lighting.

  •  Right click in Scene -> Lighting -> Light Probe Group

This is a Light Probe Group. If we select it and look at the Inspector, we can see that additional Light Probes can be added, deleted, ect. In order to use Light Probes correctly, we will need to position them in such a way that covers major changes between well lit areas, shadowed areas and areas where conflicting colored light would be.

A good example is the difference between this well lit area and this shadowed area.

Another example would be these two areas that divide the different colored regions. Although they’re both shadowed, they’re close enough to the light source that bouncing colored light between the two areas should effect each side of our Dynamic Ball.

In order to edit and add probes, simply select the Light Probe Group and select “Edit Light Probes”.

After playing around with our Scenes a bit, we should have something like this. 

One important note is to make sure not to have any probe inside of another object. This will greatly screw up the probes data when we go to bake the Scene.

Final Bake

With that let’s bake our Scene again an see if the Light Probes are working!

Go to the Lighting settings from before and click Generate Lighting.

There it is! Our Dynamic Ball is now lit and also simulates the bounced colored lighting that we’d expect.

So there we have it! Light Probes and the ability to give our dynamic objects lighting and color shading from light bouncing around in our Scenes.