- One of the most powerful features in Unity is the ability
to bake your lighting data into light maps. - [Announcer] Bake light's at
4,000 Kelvin for 30 minutes for a crisp surface and a juicy core. - Hmm, not only does this make your game a lot more performant, but it also makes the
lighting much more detailed and realistic and apparently delicious. But of course, the problem
with baked lighting is that not all objects
in your scene are static. Sometimes you want objects
such as your player to move around but still react to the different lighting
conditions in your scene. Luckily, Unity has a solution
for this, light probes. With light probes, you
can get all the benefits of baked lighting on the static
objects while making sure that moving objects
stay appropriately lit. In fact, when you create a new project, the Unity sample scene already has a bunch of light probe set up. So it's something I
really recommend you use, and it's actually insanely easy to set up. But before I show you
how to do exactly that, Unity is currently giving away free eBooks on improving your game
development workflow. The eBook is called "Nine Ways to Optimise
Your Game Development" and it's filled to the brim
with cool and very useful tips, tricks, and good practises
to help you finish your game faster and avoid
headaches along the way. Although I think it's
a really cool checklist for people making a game. I've been using Unity
for over 10 years now and I still found plenty of
cool stuff in there on topics like physics, performance,
UI, and the list goes on Again, it's completely free and I don't know how long
this offer will be up. So make sure to get it while
it's available by simply clicking the link in the description and filling out the form. It literally takes just 10 seconds. It's a really solid addition
to your game dev library so make sure to check it
out even just for later use. Now, before we start adding
light probes to our scene, let's have a look at how they work. Well, when you bake your lighting, Unity does its best to
simulate real light rays bouncing around the scene. It will then take this
lighting data and turn it into large textures that are then overlaid on top of your objects. What light probes do is allow
us to add certain points around our scene that will
store the lighting information in that particular place. For example, if we add a light probe to a place in the shadow, the probe knows that at this
point, the lighting is darker. Or if we add a light probe
close to a coloured surface, the probe knows that at this
point there is coloured light bouncing off of that surface. Then when we add in a moving object, that object will automatically
check what light probes are nearby and light itself based on the information in those probes. And not only that, it will
also smooth the transition from one probe to another. Now, how do we go about
doing this in Unity? Well, let's find out. So as you can see, I've set up this quick
assemble scene in Unity. And all I have in here are two white cubes making up our walls. I have two cubes making up a floor, one is red and one is blue. And finally I have this fear here, which is going to represent
our moving object. So you could imagine this
being a player for example. And of course I have a directional light lighting the entire scene. So let's first of all get
our scene ready for baking. To do that, we want to
select all the objects that are static in our scene and go to the right
corner of the inspector and mark them as static. I'm going to hit yes, change children to change all these selected
objects and right away, you will see that Unity
starts baking a light map. I'm also going to go to
our directional light here and mark that as static as well. And under the light settings
here, there is a mode and I'm going to change
that from real time to mixed because we want to use a mix between baked and real time lighting. This way, our light will bake in all of the lighting information
on all the static objects and still have our real
time objects cast shadows as you see here. If for some reason your
scene isn't baking right or you just want to play around with some of the light mapping settings, you can always go window, rendering and open up the lighting settings. Here there are of course
a bunch of settings for configuring your light
mapper and at the bottom, you can control whether or not you want to automatically
generate light maps or do so manually. I'm just going to set those to auto. Of course, to learn more
about begging your lighting, check out our video on
symbol lighting in Unity. There's a lot more info there. So now that our lighting is baked, we can see that we already have some more detailed lighting in here. We have some ambient
occlusion and we even have some bounced lighting where
you can see some of the colour of nearby surfaces spilling
onto the white walls here. However this doesn't apply to our sphere. This is not marked as static, and so when we start to move this around, we can see that there's no
bounce lighting being applied. And if we move it into the shadow, well, it stays completely lit. In other words, we need to add
light probes to this scene. So to do that, let's go to our hierarchy, let's hit the plus sign, let's go under light and
select light probe group. And right away you can
see this adds a group of light probes into our scene. Let's move this up to make sure that all of our light probes
are above our ground. And what we can now do
is start to distribute these probes around our scene. So I'm going to hit edit
light probes over here. And with that selected, we can now select each
one of these light probes. We can also select the multiple at once and actually start moving these around. So I'm going to start
by placing a light probe in each corner of our
scene here, there we go. And I'm going to take all
of the top light probes and move them up to the
top of our scene as well. So now we've created this
big cube of a light probes. However, this is currently
not very detailed. What we really want to do is go ahead and add additional light probes to wherever there's a change
in the conditions of our scene. A good example of this is
this colour change right here. Now this is going to
influence the bounce lighting that is going to spill onto our sphere. So we probably want to add a light probe on either side of this change. So if we go from the right here, we will have some red light
and that will slowly transition as we moved to the left to blue light. So to do that, let's go
ahead and simply select some of these light probes here. Let's hit control D to
duplicate and move them over. You can also use the buttons out here and I'm going to put one
to the left of this change, hit control D again and put one
to the right of this change. Similarly, we want to do
the same thing with shadows. So if we go over here, we
can see there's a change between fully lit and shadow. So let's go in here
and let's select all of these light probes here,
let's hit control D and let's move them over to
one side of the shadow here. And the other side of the shadow here. And for these here, we
could actually go ahead and select only these
light probes right here, and we could move them over and maybe just take a couple of them here and move those over here, just to kind of follow the
direction of our shadow. So with that, we've actually gone ahead and covered most of the changes in lighting conditions
throughout our scene. We can definitely go in
and fine tune some of this. And one thing that you
definitely want to be aware of is that you don't place
any of these probes inside of all the objects. That will definitely cause
very weird behaviours. So don't go inside of the cube because then it will be
completely dark for these probes. Just leave them right outside
of all of these things. And if you now stop
editing these light probes, it should just work automatically. If we now select our sphere, because this is not marked as static, it's automatically going to show which light probes are nearby. And as we start moving it
around, we can see it changing between the different
light probes available, really, really cool. In fact, we can see the lighting
change on a sphere already. Right now, it's actually
receiving some red bounce light from the surface, but as
we go and move over here, we can see that bounce light
changing to a more blue colour. And if we move it into the shadow here, we can see transition
to a much, much darker lighting edition because we are now inside of the shadow, really cool. And all this again, just
happens automatically. In fact, something really cool that you might not have noticed is that each one of these probes
here actually display the lighting conditions on a tiny sphere. So you can see what's going on with these probes inside of the editor. Take, for example, these two right here, we can actually see the red
light bouncing onto one of them and the blue light bouncing onto another. And all we're doing here is just moving from one of these probes to
another, really, really cool. And this should actually work
right away in game as well. However, sometimes I've
noticed that Unity light maps can be a bit weird when playing a scene, especially when transitioning
from one scene to another. So if this is causing
weird behaviour for you or the light probes simply
aren't working in game, I recommend disabling auto-generate and then manually generating the lighting by hitting this button. For me, this has always
solved a bunch of issues and if we now select our sphere, I've gone ahead and added
a quick move script to it. So if we now hit play, we
can see that the lining here is indeed working inside
of the game as well, just as intended, awesome. And of course you can go
completely nuts with this and add as many real objects as you want. We could go in here and
quickly create a cube as well. Let's move it up here and
place it, let's say here, and it's just add a white material to it. And right away you can see that this is also being influenced
by all of our probes. So it's that easy to now
start adding new objects. You only have to do this set up once. Woo hoo, and that's pretty
much it for this video. This is a really quick effect, but it's just so incredibly useful. And a lot of people get scared
to use it because they see a bunch of light probes around the scene and think it's way more
complicated than it really is. So we thought we just
had to make a video on it to show that it's really not that hard. And if you enjoyed this video, make sure to subscribe and
ring that notification bell so you don't miss the next one. Also, don't forget to
check out the free eBook on improving your game development. Simply click the link in
the description to get it. On that, thanks for watching and I will see you in the next video. Thanks to all of the
awesome patron supporters who donated in November
and especially thanks to Infinity PBR, Dante Sam,
Samuel, Lost to Violence, Love Forever, Chris, Faisal
Marafie, Megan Frazier, Leo Lesetre, Miami Pop, Muhammad Younis, Danijel Dusanic, Jacob
Sanford, Naoki Iwasaki, Marc-Antonie Girard, Gregory
Pierce, TheMightyZeus, Alison the Fierce, Yigit Kaya
and Erasmus, you guys rock.