Master Unity Lighting Techniques
Unlock the Secrets of Unity Lighting! 💡Master Realtime, Baked, and Mixed Lighting
Estimated read time: 1:20
Summary
Explore the intricacies of Unity 3D lighting in this insightful tutorial. Gain a deep understanding of different lighting types available in Unity - real-time, baked, and mixed lighting - and how to optimize their use to enhance the visual fidelity of a game. Learn about light probes and how they can be utilized to improve lighting for dynamic objects, alongside practical demonstrations of various lighting settings and configurations. This video is a comprehensive guide for mastering Unity’s lighting system, perfect for game developers looking to elevate their game’s graphics.
Highlights
- Learn about setting up basic scenes and manipulating object materials in Unity. 🎨
- Discover how directional lights affect a scene and how changes in position and color alter the final output. 🌈
- Understand the importance of environment lighting and how it influences scene aesthetics. 🌅
Key Takeaways
- Master the art of lighting in Unity by using real-time, baked, and mixed lighting modes to optimize game visuals. 🌟
- Understand how to use light probes for enhancing lighting on dynamic objects in 3D scenes. 🧐
- Discover the differences between types of lighting – directional, point, and spotlights – and their applications. 🔦
Overview
Dive into the world of Unity lighting with this comprehensive guide that breaks down the concepts of real-time, baked, and mixed lighting. This tutorial takes you step-by-step as you learn how to create visually stunning scenes using Unity's lighting systems. The process starts with setting up a basic scene and familiarizing with object and material creation, ensuring your foundation is rock solid before delving deeper into more advanced techniques.
Explore how directional lights work and how they impact your scenes based on rotation and color choices. Learn the significance of initial settings and how a simple directional light can shape scenes in profound ways. This segment also covers environment lighting, explaining its role in adding depth and realism even in shadowed areas – a must-know for every Unity user.
From setting the mood with point lights to casting realistic shadows with mixed lighting modes, this guide leaves no stone unturned. It thoroughly examines how baked lighting can transform static scenes, and how mixing lighting modes can cater to dynamic environments. You’ll also gain insights into optimizing lighting for performance, ensuring your game looks good and runs smoothly.
Chapters
- 00:00 - 00:30: Introduction to Unity Lighting In this chapter, the focus is on understanding 3D lighting in Unity and its impact on enhancing game visuals. The discussion includes an overview of various lighting modes and types available in Unity. Furthermore, the chapter elucidates the concepts of real-time, baked, and mixed lighting approaches. Additionally, the use of light probes to enhance the lighting on dynamic objects within a game is explored. The chapter begins with the practical step of creating a new 3D URP project in Unity Hub.
- 00:30 - 03:00: Creating a Basic Scene The chapter discusses creating a basic scene in a project to demonstrate lighting. It involves adding a 3D object (plane) to the hierarchy, enlarging it by adjusting its scale, and creating a material for it.
- 03:30 - 06:30: Understanding Directional Lights The chapter titled 'Understanding Directional Lights' discusses how to manipulate materials in a project panel, focusing on setting the base map to a green color. However, the material is adjusted to not be entirely green by including some red and blue components. The material is then applied to a plane by dragging it onto the surface. The chapter also briefly mentions adding walls by using the plus button in the hierarchy panel.
- 07:00 - 08:30: Exploring Point and Spot Lights In this chapter, the process of adjusting a 3D object's position and scale is discussed, specifically using a cube. The cube's position is set on the Y-axis to 2 and scaled to 10 on the X-axis and 4 on the Y-axis. Additionally, the chapter covers adding a new material to the object, changing its base map color to blue, and applying the material to a wall.
- 09:00 - 16:30: Baked Lighting Basics In this chapter, we focused on duplicating an existing wall in our hierarchy and making modifications to it. We began by right-clicking the blue wall and selecting 'Duplicate'. Next, we adjusted the new wall's position by setting it to minus 10 on the X-axis. We also created a new material for the wall, choosing a yellow color for the base map. Finally, we applied this new material to the wall by dragging it onto the wall element to complete the assignment.
- 16:30 - 23:00: Mixed Lighting Modes In this chapter, the process of duplicating an object within a virtual environment is discussed. Specifically, a blue wall is duplicated, and its position is adjusted on the X axis. A new material, colored red, is then created and applied to this wall. Finally, a capsule is introduced to represent a player within the environment.
- 28:00 - 33:30: Using Light Probes for Indirect Lighting This chapter explains how to set up a basic scene using light probes for indirect lighting. It involves positioning a scene element at specific coordinates, creating a new material with a white base map, and applying it to a capsule within the scene. These steps form the foundational setup required for the demonstration of light probes.
- 35:00 - 45:30: Real-time Global Illumination The chapter discusses how Unity's default scene starts with directional lighting, which is important for representing distant light sources like the sun or moon. It explains that directional lighting in Unity is influenced solely by the direction of the light, not its position. When the position of the directional light is changed, it does not affect the lighting of the scene.
Unlock the Secrets of Unity Lighting! 💡Master Realtime, Baked, and Mixed Lighting Transcription
- 00:00 - 00:30 hi guys today we're going to look at how 3D lighting Works in unity and how we can use the various lighting modes to improve the appearance of a game we'll go through some of the different types of Lights available in unity then we'll look at how real time baked and mixed lighting works we'll also explain how we can use light probes to improve the lighting of dynamic objects in our game okay we'll start by creating a new 3D urp project in unity hub
- 00:30 - 01:00 once the project is loaded we'll create a basic scene to demonstrate how lighting works we'll click the plus button on the hierarchy and select 3D object plane we'll make this a bit bigger by setting the scale to 10 on the x and z axis then we'll create a material for this by clicking the plus button on the
- 01:00 - 01:30 project panel and selecting material we'll set the base map to a green color we need to make sure that it's not 100% green though we'll come back to Y shortly but for now we'll just make sure the color has some red and blue components we'll drag this material onto the plane to assign it next we'll add some walls we'll click the plus button on the higher Archy and
- 01:30 - 02:00 select 3D object Cube we'll set the position to two on the Y AIS and we'll set the scale to 10 on the x- AIS and four on the Y AIS then we'll add another material for this one we'll set the base map to a blue color then we'll drag the material onto the wall
- 02:00 - 02:30 next we'll create another wall we'll right click the blue wall in the hierarchy and select duplicate we'll change the position of this one to minus 10 on the X AIS then we'll create a new material for this wall we'll set the base map to a yellow color then we'll drag this onto the wall to assign it
- 02:30 - 03:00 next we'll duplicate the blue wall one more time we'll change the position of this one to 10 on the X AIS then we'll create another material and we'll set the base map of this one to a red color then we'll drag the material onto the wall the final thing we'll add is a the capsule to represent a player in our
- 03:00 - 03:30 scene we'll set the position of this to one on the Y AIS a minus 2.5 on the Z AIS then we'll create another material for this one we'll leave the base map as white and drag it onto the capsule to assign it now we've got everything we need for our basic scene
- 03:30 - 04:00 we can see that the scene is already lit without us having to do anything that's because the default scene in unity starts with the directional light directional lights are used to represent light sources a long distance away such as the sun or moon the influence of a directional light on a scene is purely determined by its direction the position has no effect let's select the directional light in the hierarchy if we change the position we can see that nothing
- 04:00 - 04:30 changes let's try changing the rotation now we can see the light in the scene changing the intensity of the light on a surface is determined by how close the direction of the light matches the direction of the surface let's point the light directly at the front of the walls we can see that this surface is now bright as it's getting the full intensity of the light the top and other side of the wall darker as the light
- 04:30 - 05:00 isn't pointing towards them let's put the light at more of an angle now the front is a bit darker as the light is Less Direct the top is brighter though as it's now receiving more light the color of the light also has an effect let's try changing it in the inspector to see what happens we can see that it tints the scene based on the color we choose
- 05:00 - 05:30 use at a high level the final color of the object in the scene is calculated by multiplying the original color by the light color and then multiplying this by the intensity of the light as determined by the direction of the light towards the surface let's set the color back to White if we look on the other side of the wall we can see that there are also Shadows cast By the Light we're not going to go into too much detail on how this works but basically Unity renders the scene from the perspective of the
- 05:30 - 06:00 lights it then uses this to work out which areas aren't visible to the lights and should be in Shadow you may notice that the areas in Shadow aren't completely black though that's because of something called environment lighting let's turn off the directional light to get a better view of what this looks like Unity is calculating this lighting from the Sky Box in the scene and it ensures there's a small amount of light even in the shadows we can change the intensity of
- 06:00 - 06:30 this in the lighting settings we'll go to the main menu and select window rendering lighting we'll drag this over and dock it on the right we'll go to the environment Tab and change the intensity of the environment lighting to see the effect if we set this to zero we can see that the scene is now really dark let's turn back on the directional light to see what it looks like with no environment lighting
- 06:30 - 07:00 where the light's hitting the scene it looks pretty much the same as before on the other side of the wall though it looks really dark it looks much better with the environment lighting so we'll set the intensity back to one before we look at some more advanced lighting techniques we'll have a quick look at some of the other lights we can use we'll click the plus button on the hierarchy and select light Point
- 07:00 - 07:30 light this differs from directional light in that the position matters let's position this one on the dark side of the wall we can see that it's lit the wall at this point light is emitted in all directions from the position and we can change the intensity and the the
- 07:30 - 08:00 range this could be used for things like an indoor light or a campfire let's disable this and look at another light we'll click the plus button on the hierarchy and select light spotlight this light has a position and a direction we'll point this at the dark side of the wall
- 08:00 - 08:30 if we increase the intensity we can see it lights up a spot on the wall like a torch beam we can also change the angle of the light and the range
- 08:30 - 09:00 this could be used for things like street lights and headlights on cars okay next we're going to look at baked lighting let's start by disabling all the lights in the scene the environment lighting we're looking at now is currently being calculated in real time this looks okay but it isn't a very accurate representation of how light actually works in the real world light bounces off objects onto surrounding objects
- 09:00 - 09:30 this is often referred to as indirect lighting or Global illumination so for example light would bounce off this yellow wall causing a small amount of yellow light to tint the floor this is where baked lighting comes in baked lighting allows more complex lighting calculations to be done up front and stored in a texture to be used at runtime we can bake the environment lighting by going to the scene t on the lighting
- 09:30 - 10:00 settings in here we can see various settings for how the lighting will be calculated we'll be changing some of these values later on to allow us to do this we need to create a new lighting settings asset by clicking the new button we'll leave everything as it is for now and click generate lighting looking at the scene it seems like nothing has changed that's because baked lighting only
- 10:00 - 10:30 affects objects marked as static we'll select all the scenery objects in the hierarchy and we'll take the static checkbox in the inspector then we'll go back to the lighting settings and generate the lighting again this time it will take much longer so we'll fast forward until it's done
- 10:30 - 11:00 now if we look closely we can see some subtle changes there's some yellow light that has bounced from the yellow wall onto the ground we can also see a small amount of red around the red wall and the capsule has a blue tint from the blue wall to make the effect of baking more obvious let's add some more light to the scene to do this we'll add some emission
- 11:00 - 11:30 to the red wall we'll select the red material in the project panel then we'll go to the inspector and turn on the emission we'll set the emission color to red and set the intensity to two now we have this glowing wall but it isn't affecting the surrounding scenery let's click the button to generate the lighting again
- 11:30 - 12:00 now we can see that there's more red on the ground and a red tint on the side of the capsule let's temporarily disable the red wall in the inspector now we can clearly see the red tint baked into the ground that's why when we created the green material it was important to make sure the red component wasn't zero remember remember the effect of a light
- 12:00 - 12:30 is determined by multiplying the light color with the object color in this case the light bouncing off this wall is red so it will only affect the red color of the object if the red component of the green material was Zero then it would be multiplying by zero and have no effect okay next we'll look at how to bake the directional light let's enable the wall and the directional light in the hierarchy
- 12:30 - 13:00 if we look at the settings for the directional light we can see that there's a mode setting this is currently set to real time which means all the calculations for this light are done at runtime every frame by doing the calculations every frame it allows the scene to adapt to changes for example if we move the capsule around the lighting and shadows are updated to match this mode doesn't contribute to the bait lighting though to have it contribute we'll change the mode of the light to
- 13:00 - 13:30 baked let's generate the lighting again now we can see the effect of the light bounces we can see more yellow on the ground here let's take a closer look at the capsule we can see some green bouncing off the ground
- 13:30 - 14:00 and we can see some blue on the side from the wall the lighting in the scene is now completely baked we can even disable the directional light and the scene stays lit this works really well for static scenery but we can't use it for objects that we intend to move let's try moving the capsule to see what happens the lighting no longer updates and the shadow is Left Behind let's untick the static checkbox for the
- 14:00 - 14:30 capsule to tell Unity we intended to move then we'll generate the lighting again now the capsule is no longer receiving any lighting from the directional light and there's no Shadow at all that's because baked lighting only affects static objects let's look at another lighting mode that will improve this we'll select the directional light in the hierarchy
- 14:30 - 15:00 and set the mode to mixed this combines elements of real time and baked lighting how it does this depends on the settings let's go to the lighting settings to look at the mix lighting options we have baked indirect subtractive and Shadow mask let's try subtractive first subtractive uses bait lighting for both both direct and indirect lighting
- 15:00 - 15:30 but it provides realtime Shadows for one directional light only before we try this out let's add in another light that casts a shadow we'll enable the point light we created earlier we'll set the mode of this light to mixed as well we'll also turn on the Shadows okay let's generate the lighting
- 15:30 - 16:00 now the capsule is lit again and we have a shadow from the directional light we also still have the indirect Lighting on the static scenery if we move the capsule over to the point light though we can see that the shadow is unaffected and if we move the capsule into the shadow of the wall we can see that it's still lit
- 16:00 - 16:30 subtractive has the lowest performance cost of the mixed light options but it doesn't create very realistic lighting you would only really consider using this if you were targeting low-end Hardware next we'll look at the baked indirect mode in this mode mixed lights will act like realtime lights providing realtime lighting and shadows it then mixes this with baked indirect lighting let's generate the lighting in this
- 16:30 - 17:00 mode we still get the indirect lighting and the shadow from the directional light if we move the capsule to the other side of the wall though we now get lighting and shadows from the point light and if we move away from the light the capsule is now in Shadow this gives much more realistic lighting one limitation with this mode is that the Shadows are only visible up
- 17:00 - 17:30 to a certain distance if we zoom out we can see that the Shadows eventually disappear this can be fixed by using the shadow mask mode Shadow mask does everything that baked indirect does but it also mixes in baked Shadows for Far Away objects let's generate the lighting in this mode
- 17:30 - 18:00 if we zoom out the Shadows don't disappear this mode is the most expensive but works well if you're creating a game where distant objects are visible that covers all the mix lighting modes in general mixed lighting is going to give better lighting than real time or baked but there is a a performance cost it will always have more runtime
- 18:00 - 18:30 calculations than fully baked lighting and it will use more memory than fully realtime lighting we now know how to get direct and indirect Lighting on the static objects in the scene but currently the moving objects are only getting direct light let's look at how to fix this first of all we'll change the camera so that it has a good view of the whole scene we'll position the scene view until we can see everything then we'll click on the camera in the
- 18:30 - 19:00 hierarchy and select game object align with view now let's switch to the game view we'll move the capsule along in front of the wall what we want to see is some of the color from the walls appearing on the side of the capsule especially from the glowing red wall at the moment it just stays completely white for indirect light to be added to moving object objects we need to use something called light
- 19:00 - 19:30 probes these probes are positioned at various points all over the scene then when the lighting is baked the probes store information about the light passing through them at runtime the indirect light for moving objects is then calculated from the nearest light probes let's have a look at how this works we'll click the plus button in the hierarchy and select light light probe group if we switch to the scene view we can now see these eight yellow spheres each of these is a light probe
- 19:30 - 20:00 we can click edit light probe positions in the inspector to add more or to move existing ones we'll quickly Place some probes in front of the wall these probes need to be above the ground they also need to not all be at the same height we can also duplicate selected probes to
- 20:00 - 20:30 speed up the process generally you would spread light probes over the whole scene there is a performance cost though so you want to minimize the number by having them condensed only in areas with complex
- 20:30 - 21:00 lighting then you can have fewer in areas where the light doesn't change much okay let's generate the lighting again now we can see some of the indirect light on the
- 21:00 - 21:30 capsule there's some green on the bottom and some blue on the side if we select the capsule in the hierarchy we can see which light probes are affecting it let's switch to the game View and move the capsule along the wall we can see the indirect light on the capsule change depending on the wall it's next to now we have direct and indirect lighting
- 21:30 - 22:00 for static and moving objects in our scene there is still one final scenario we haven't covered though many games have lighting that changes at runtime for example you may want to have a day night cycle in your game Let's simulate this by turning down the intensity of the directional light we can see that the indirect lighting is now too bright because it was baked when the light was
- 22:00 - 22:30 bright it doesn't change as the light intensity changes for this reason if you want your lights to change baking is not really an option fortunately Unity has another option that allows indirect lighting to be calculated in real time let's go back to the lighting settings we'll tick this box to turn on real time Global alumination and we'll turn off the baked Global illumination the other thing we need to change is on
- 22:30 - 23:00 the red material we need to change the global illumination on the emission from bait to real time then we'll generate the lighting if we move the capsule we can still see the indirect lighting affecting it but now if we change the intensity of
- 23:00 - 23:30 the directional light we can see it adjusts to lighting changes this method still requires light probes for dynamic objects and it doesn't look quite as good as the bait lighting but it's a good option if you need it okay that covers everything for this video hope you found it useful a big thank you to all our patrons we really appreciate you helping to support the channel if you'd like to help and also get access to the source code you can find details in the description if
- 23:30 - 24:00 you have any questions or feedback on this video let us know in the comments thanks guys