Important Notice:

The Digital-Tutors site will soon be retired and your access will be turned off - but don’t worry, you can still enjoy all your favorite Digital-Tutors content on Pluralsight (plus thousands of additional courses, skill assessments, paths and more). You can log in to Pluralsight with your Digital-Tutors credentials, as well as update your password at any time on Pluralsight. Please contact us with questions or concerns: support@pluralsight.com.
Baking lightmaps
See Details
Joshua Kinney

Pluralsight

Joshua Kinney
In this tutorial, we're going to discuss lightmapping in Unity. All right. So at this point, we should have all of our lights set up, here in Unity. And we went ahead in the last lesson and created some prefabs with our Mesh and our Light Objects. And we've created those and scattered those throughout our level here. And we've lit that. Now, at this point, what we want to do is, we want to bake lightmaps. And baking lightmaps, what they're going to do is create lightmaps and apply those to the textures of our environment. So that way, we can get rid of any lights in our scene. And by doing so, that is going to make our game run smoother. Now, to get started with this process, there are a couple of things that we need to do first. First off, we need to tell our environment or our lightmapping system what is static and what is not static. OK. So what we mean by static? Well, basically, any objects that are going to be standing still, they're not going to be moving in any way, in our scene. So what we need to do is, we need to go through. And let's select our base environment here. And because this is set up as a parented group, we can just simply check Static. Now, by doing so, we're going to say, yes, change these children. So we're going to change that over to Static. And I'm going to go to my lights. And I'm going to say the same thing here. And it's going to receive that mesh information. And then, we're going to Set Dressing, which is all of our props. And we're going to set those to Static as well. Now, that we've set all of those to Static, can come in. And we could start baking out our maps. So to get started with that, let's go into our are window and then Lightmapping. This is going to bring up our Lightmapping window. And inside of here, we have three panels. We have Object, Bake, and Maps. So under our Object options, we're basically telling it, what do we want to bake in this scene. What do we want to be affected? So in this case, we could have our Lights, Renderers, Terrains. Or we just do all of those. So I'm going to say All. And we've already set everything to Static. So we should be ready to go there. Now, at this point, you should see zero lightmaps in your scene. But if you do have lightmaps, you want to go ahead and hit Clear. And that will clear those from your level. Now, moving on from here, let's go to our Bake options. And we're going to leave everything as Default. But I will kind of go through these with you, just a little bit. So the first thing we have is our Mode. And we have Dual Lightmaps set by default. And this is going to be really helpful because it's going to create two sets of lightmaps. It's going to create a far set and a near set. And that's just going to help with the overall quality. And so usually, Dual Lightmaps is a pretty good place to stay. We're going to move past our forward rendering, because we're using deferred at this point. So if you were going to be using forward rendering, let's say that you were creating a mobile game or something like that. You didn't want shadows. But you still wanted to access these lightmapping capabilities. You would want to go ahead and check that. We're going to set our quality to high. The number of Bounces is going to be set to one. And then, if we have an exterior scene, we want to go ahead and set up a skylight color, just kind of give it a hint of that color in our lightmaps. Now, going through the rest of these options and sliders, we have the ability to increase the quality of our lightmaps. We could do things like adding ambient occlusion our lightmaps. But remember, doing so is going to increase your bake time. So you want to be careful with those. So I'm going to leave everything by default here. And then we're going to move on into our maps. Now, inside of here, you're going to be asked if you want to include any Light Probes in your lightmapping process. And we do want to use Light Probes. Now, Light Probes are going to be really helpful whenever we create baked lightmaps. And we still want that information to affect dynamic objects in our scene. So we talked about how lightmaps require objects to be static. So they can apply those lightmaps to those static objects. But we do have dynamic objects in our game. It wouldn't be a video game without dynamic objects. So a dynamic object, just for a quick example, could be the third-person controller or the third-person player in your scene. So for our example, if I hit Play here, you'll notice that I have a lantern tied to my character. And if I move throughout the scene, because the lights are actual lights, they're applying light to the lantern itself. And this object is going to be moving throughout the scene. Now, if I've baked lights, those lights are going to be removed. And I will no longer have any lighting influence on this object. So what I need is to use light probes to be able to gather that light information and apply it to dynamic objects like this. So let's go through the process of creating light probes. The way I like to do this is to create an empty game object. And I'll set this at zero, zero, zero. So that way, I know exactly where to find it. I'll give it a name. And I'll call this Light Probes. And then, we're going to go ahead and add a Light Probes group component to this. So we can Add Component. And then, we'll go to Rendering, Light Probe Group. Here, you can see that we can add a probe. We can select all of our probes. We can delete the selected probes. And we could also duplicate probes. So to get started, we need to add a probe. So we'll add a single probe. And you can see that it's basically just a sphere. You can tell that it's selected because its colored blue. When you deselect it, it will turn yellow. So let's go ahead and select it and put it in our first position. So light probes are kind of like vertices of a volume. So we're going to be creating a series of light probes that will create a volume in our level. So I'm going to start right here at this beam and pretty close to the floor. But I do want to make sure that I'm above the floor. OK. So we're looking good there. And then, what I'm going to do is, I'm going to duplicate that by getting control and D and pulling that up. We want to make sure that we're still inside the level. And we're looking good there. And then, I'm going to take those two, select those by holding Control. And then, we're going to duplicate those as well. So I can hit Duplicate Selected as well, beyond Control D. And it will give me the same result. Let me select all four of these. I'm going to hit Control D. And now, watch what happens. Whenever I move this out, it creates a volume that has connected between those four. So I'm going to take this up to this point right here. I'm going to hit Control D. And I'm going to pull that across to here. And then, I'm going to continue to Control D, until I've created a length of volume here. So I'm going to go Control D. And I'm just going to go all the way across here. Now, you might be asking me, why are we creating these volumes across every section of our level. Well, the reason that I want to do this is because the more light probes you have, the more of a sample you're going to get from these different lit areas. So if I have a dark area, I want to have as many samples as I can get for that dark area, to translate between this dark area and this light area. All right. So once I've created those, let's go ahead and deselect our light probes. And now what I want to do is, I want to go back into my Lightmapping option. So let's go to Window, Lightmapping. Let's go to Maps. And let's select the light probes that we've created. Now, you'll see that it's not showing up in here. So let's go ahead and bake the light probes that we have available. So we're just going to simply bake those probes. It's going to go through that process. Those have been baked. And now they've been added to our maps. Now, what I can do is, I can go into my Object here. And I can switch it from Bake Probes to Bake Scene. Now, once I bake the scene, it's going to go through that process and start baking all of our lightmaps. Now, this process is going to take anywhere from 10 to 15 minutes. So what I'm going to do is, I'm going to go ahead and pause the video here and let that bake out. And then I'll show you what we need to do after these have been baked. OK. So now that the maps have finished baking, we want to go ahead and test out our level. So now that we've baked those, we need to get rid of those lights. Because whenever you bake textures or you bake your maps, it's replacing the original light. So we want to go ahead and get rid of those out of our scene. Now, I'm just going to temporarily get rid of those. So what I'm going to do is, I'm going to go into my Prefabs folder. And I'm going to expand our Prefab Wall Light. And I'm going to select the point light portion of that prefab. And I'm just going to simply turned out that light. And that will turn off all the lights throughout the scene. And now what we see is just the texture. So if I hit Play, and we come in here. And we start to move around throughout our level. You're going to notice that I don't necessarily have any light probe activity on my model here. So let's go ahead and hit Play again. Let's turn that light back on and see what it should look like. So if I hit Play, we should be able to see our lantern showing up here. So let's come right up to this rock with that turned off. So we're going to turn that off again. Let's hit Play. And we'll come up to that rock, and again, still no light probe action going on here. So what's going on? Well, we need to make sure that we activate that model to receive that light probe information. So let's go ahead and go to our First Person Controller. And in here, we're going to see our lantern. And we want to go to the Lantern geometry. Now, just the Lantern geometry is all we need. We don't necessarily need the globe. But with that lantern object selected, let's go to Use Light Probes. With that selected, and if we hit Play, that information is now going to be projected onto our lantern. So it does look a little bit lighter in the scene. Let's go ahead and pause it. And I'm going to go to my Game View, just so I can see what's happening here. And let's turn off Light Probes. And you can see that information is changing there. Now, the reason that it looks a little bit different than the actual lights is because of the sampling that's happening between the light probes. So we may have to add a few more light probes in there, to get the perfect sample that we want for this area. But we do know that is working now. OK. So that's how we can set up lightmapping and how we could up our light probes. And in our next lesson, what we want to start taking care of are particle systems and how we can bring those into our level.
In this series of Unity tutorials we are going to learn about the core features in Unity.

We will start out by learning the Unity Interface where we'll talk about the different panels and tools available in the Unity editor. From there we'll learn how to properly export and import assets into Unity. With those assets imported, we'll discuss how to create prefabs that will help us speed up the construction process of our level.

Then we'll learn how to create and apply materials to our level prefabs. Then we'll take our textured prefabs and build a simple game environment. Once the base level has been built, we will talk about adding props and set dressing our level. From there we'll continue full speed by learning how to add lights, particles, and physics objects.

Once we're happy with our level, we'll jump into scripting in Unity. We'll learn how to create a random player spawn, a HUD, item pickups, and so much more. Finally, we'll end the course with how to publish our game to the platform of our choosing.

For an additional learning resource, download your free copy of our Key Game Development Terms Reference Guide and PDF so you can get comfortable with important game dev terminology.
Introduction and Project Overview
1

Introduction and Project Overview

 
01:14
Breaking down the interface
2

Breaking down the interface

 
10:59
File management and project organization
3

File management and project organization

 
10:45
Creating prefabs
4

Creating prefabs

 
10:41
Creating materials
5

Creating materials

 
10:00
Assembling the level
6

Assembling the level

 
08:36
Set dressing the level
7

Set dressing the level

 
14:09
Adding lights
8

Adding lights

 
09:55
Baking lightmaps
9

Baking lightmaps

 
11:32
Creating particle systems
10

Creating particle systems

 
11:19
Working with physics
11

Working with physics

 
09:41
Getting started with scripting
12

Getting started with scripting

 
09:41
Creating the player spawn controller
13

Creating the player spawn controller

 
11:10
Finishing the player spawn controller
14

Finishing the player spawn controller

 
08:12
Creating the game state script
15

Creating the game state script

 
11:46
Scripting the HUD
16

Scripting the HUD

 
13:16
Creating items in Unity
17

Creating items in Unity

 
13:35
Creating the lantern functionality
18

Creating the lantern functionality

 
18:32
Loading levels
19

Loading levels

 
08:08
Publishing our game
20

Publishing our game

 
08:46