Skip to main content

Lighting

Welcome back to the 4th lesson in this tutorial series where we will create proper lighting for our room!

Something I should have mentioned last episode was finding reference photos to influence your choice of textures. As a beginner you shouldn’t be trying to create your own styles but instead try to replicate styles that already work. For example, in my world Room at Sea, I looked at beach houses and found elements from the references that I liked that I wanted to incorporate into my own scene, those being: color pallet; a lot of whites and grays, some poignant blacks and a light blue and beige color combination.

When making your own room, try not to clash styles and stick with just one, at least for now; for example, instead of clashing New York interior brick with Floridian spanish-influenced architecture, just stick with one or the other, and focus on the elements of that style which really work and give you the feeling or vibe you want to have when being in that space. For this tutorial series I am going to go with a minimalistic Scandinavian apartment style since it makes sense for the small room we are creating and it's relatively easy to make in 3D because of its simplicity.

In summary, look at reference images and have them influence your modelling, your choice of textures, and your lighting, which we will get into at the end of this lesson.

 

When looking for references I would recommend image based browsing sites like Pinterest or Houzz; both make it easy to search for similar looking interiors and save images you like. The great thing about Houzz is that there will typically be multiple images of each residence. And as you should notice by looking at Scandinavian apartments there are a few things that should jump out to you that makes the style: minimalism, in geometry of the interior structure and objects, and limited color, with most of the scene having no color at all. This analysis is only scratching the surface of visual composition; if you want to learn more about it I would recommend watching Blender Guru’s videos on topics like color, composition, and lighting.

 

https://youtu.be/Qj1FK8n7WgY

https://youtu.be/O8i7OKbWmRM

https://youtube.com/playlist?list=PLjEaoINr3zgH9vCr47kSS5W8PEJBNIiwK

 

Additional software like PureRef and Allusion can be used for viewing and browsing through reference images saved to your computer.

 

There’s also some special techniques you can use to easily modify materials more to your liking. I found a plain plaster texture on textures.com (which requires an account) but it was a little dark for my liking. For this material, since there was little detail in the albedo texture and I didn’t really care for it anyway, I can remove the albedo texture from its slot and instead choose whatever color for the paint I want while still retaining the detail from all the other PBR maps. If you don’t want the material to look as bumpy, you can decrease the strength of the normal map. And one last thing, you actually don’t need to open a separate calculator to get the correct tiling because you can just do the math inside the box.

 

Now onto lighting. This in combination with our material choice is what visually makes our scene. What we’re going to do is create baked lighting; this means that lighting will be precalculated on your computer so it doesn’t have to be calculated on the player’s, drastically increasing performance and lighting quality. It does this by calculating the lighting for all the static objects and “baking” the shading into a lightmap. Dynamic objects (like avatars) are lit by using light probes.

 

First, make sure that all the static objects in the scene are marked as “static” in the inspector tab (or specifically, at least lightmap static in the dropdown; this tells Unity that we want that object to use baked lighting).

 

Set all the lights in the scene to Baked.

 

Next, open the lighting tab by clicking on auto-generate lighting in the bottom right corner or by going to Window>Rendering>Lighting. It might pop up as an undocked tab, but you can dock it wherever you like. Personally, I like to put it in the same space as the inspector on the right and then switch between the two.

 

Under Realtime Lighting, turn realtime global illumination off. I won’t get into it here since this is supposed to be a beginner tutorial series but unless you know what you’re doing with it you should have it disabled.

 

Under Mixed Lighting, with Baked Global Illumination on, set the Lighting Mode to Baked Indirect. This means we won’t have realtime lighting for our dynamic objects but this is what we want because realtime lighting has a heavy performance cost.

 

Now we get to the lightmapping settings. The first option is the lightmapper, change it to Progressive GPU. As of recording the GPU lightmapper is still in Preview which means it is not production ready; if it gives you errors or glitches you can switch to Progressive CPU but for quick iteration GPU lightmappers are much faster than CPU ones.

 

For the lightmap resolution, rather than simply explaining everything it would be best to get a visualization of it in your own scene. In the Scene view, at the top right, click the dropdown where it says Shaded and go down to Baked Lightmap. Here you will see a visualization of the lightmap texels in your scene. What the lightmapper does is calculate the lighting for each texel and then puts that into a pixel in the lightmap. Don’t worry, we’ll get to see the lightmap once it’s baked so you can get a better visualization.

 

The Lightmap Resolution is in texels per unit. If you drag left and right to decrease and increase the value, you can see that the amount of texels in the scene changes. This value essentially means how much lighting resolution we want to give to our objects, where higher resolution means higher quality and less pixelation, but also means that our lightmaps will take up more storage and take longer to bake. Right now, let’s set it to 20 so that it will bake faster, and we can increase it before our final bake.

 

In the rendering component of an object you can adjust its lightmap scale.

 

Other important settings include:

  • Prioritize view: if enabled it will prioritize baking in the view of the scene tab first.
  • Light bounces: the more bounces, the more realistic. Outdoor scenes may not need as many bounces, indoor scenes will greatly benefit from them. Noticeably increases bake times so probably best to keep it around 2 until the final bake where you can increase the bounces to the maximum.
  • Lightmap size: this is just the max lightmap size, set this to the largest (it will increase performance because there will be fewer lightmaps)
  • Ambient Occlusion: turn this on for realistic ambient shadows

 

With it all set up, click generate lighting at the bottom, and wait. For larger scenes this can take a while but since our scene is so small and we set the lightmapper to use the GPU it shouldn’t take too long. If you switch between Baked Lightmap and Shaded views in the scene view, you should now be able to get a better idea of how baked lighting works.

From here you can tweak the lighting as you like before the next bake. And with the Progressive lightmapper’s prioritize view, you get a noisy preview of how the result will look as it is baking.

 

In a room, it would make sense to have a light in it. If you right click in the Hierarchy, go under Lighting, you will see the 4 different types of lighting in Unity:

  1. Directional light: essentially the sun. The rays have infinite distance, so shadows cast with this light will always be parallel, and its position is irrelevant, only its rotation matters. It comes by default with every new scene and there should be a maximum of one per scene.
  2. Point light: a light source with a finite range in all directions
  3. Spot light: has a finite range within a cone shape with an angle defined in degrees between 0-180
  4. Area light: a flat 2D light source over an area. Baked only, no realtime.

 

Point light seems to make the most sense for our scene. Add a new point light and put it near the ceiling. DO NOT put it in the ceiling! The light is simulated from the point where it is placed, so if it is inside the ceiling it won’t work properly!

 

Click on bake. We should now see the reflection in the wood. But if we move the camera, the reflection doesn’t move. This is because by default the cubemap is projected as if it is from an infinite distance away, which is great for outdoor areas where there won’t be visible parallax. But for indoor areas this means the reflection will look off if the camera or player view is not at the origin of the reflection probe. Let’s turn on box projection for the reflection probe. What box projection does is project the cubemap to the bounds of the reflection probe, which simulates parallax but also makes clear seams in the projection. This is the ideal setting for indoor spaces.

 

OK, we now have lighting for the static objects, but what about the dynamic ones? Right click on the Hierarchy, Lighting>Light Probe Group. It should now appear in your scene as a web of 8 spheres. Each of these spheres is a probe, and for each probe, Unity calculates how it would be shaded at that point in space. As dynamic objects move through the light probes, they blend the lighting data of the nearest ones.

 

If you click on the light probe group, you should see in the inspector that you can press a button to toggle probe editing mode. From here you can click on and move individual probes, shift click them to add them to the selection, and ctrl+d to duplicate them. Now the objective is to fill our room with light probes. But how should we fill it? The easiest way would be to fill our room with probes like a 3D grid, but then we wouldn’t get the most accurate lighting. The optimal way to place light probes is to place one wherever there is a change in lighting! 

 

Let’s go place them in the obvious spots, like wherever there is a clear light cutoff, like sunlight hitting the floor. Just above the floor, place light probes in the four corners of the sunlight, and then in the four corners just out of the sunlight. Do the same but at the window. Now place light probes around other lights in the scene, and at the edges of any shadows.

 

At the top of the lighting window you’ll notice environment lighting, where it says Skybox. This is what will determine the cubemap that gets used for the fallback reflections of the scene, or when an object is outside the bounds of a reflection probe. Right now Unity will bake a cubemap of our skybox, which is not what we want because the skybox won’t be a proper reflection of our scene if everything is going to be inside our room. Click “Skybox” and set it to custom. Then in the project tab navigate to the reflection probe (which should be under Scenes>Scene name) and drag it into the slot.

 

If you look at the Scandinavian apartments again, you’ll notice that a lot of them have no artificial lights. Their lighting is coming from outside, but it’s not from a direct light source which creates sharp shadows. 

Let me ask you a question: when you are outside during the day, where does light come from? The obvious answer is the sun, which is the most intense light source, but the full truth is that light comes from everywhere. That’s why surfaces in the shade outside during a clear day have a blue tint, because that environmental lighting is coming from the sky.

Since Scandinavia is quite cloudy, it’s safe to say that many of these photos were taken on a cloudy day, and that (and possibly curtains) is why the lighting is diffused. We can actually replicate this cloudy day lighting in Unity; this is when the environment lighting in the lighting tab becomes really important.

By default, the source of environmental lighting is the skybox. I’ll show you how to import external assets in the next lesson, including an overcast skybox, but for now we can just make our own gray skybox by right clicking in the project tab and going to Create > Material. Then change the shader to Skybox > 6-sided and the color to a slightly bright gray. Now disable all other light sources, hit bake, and you now have beautiful diffused interior lighting. If you think it’s a bit dim you can increase the indirect intensity, which will brighten the skybox. This is physically incorrect, but we are artists, not scientists; we do not need to obey the laws of physics, we can bend them to our will!

 

One last important optimization to mention is Occlusion Culling, which will increase the performance of your world by not rendering objects that aren’t in the player’s view. Go to Window>Rendering>Occlusion Culling and click Bake. If you click Visualization at the top of the tab, select your camera, move it around and you can see how Unity will now draw the scene.

 

To get better occlusion culling right click in the hierarchy>lighting>occlusion area and then fit this volume to the places in the scene where it is possible for the player to be.

 

It’s best to clear occlusion culling data while you are still editing static objects in the scene and then bake before uploading. If it’s not working correctly (objects are disappearing when they should still be in view) either re-bake or tweak the settings under Bake in the Occlusion tab. Note that occlusion culling only affects the visual rendering of objects, so processing of them will still occur even when out of view!

 

Tweak the settings of the lights, bake again at higher settings, and your room should now have beautiful and performant baked lighting! Next lesson will go over how to add external models to the scene.