Introduction to Unity 5 Lighting workshop - Part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I'm going to do a few examples of how lighting works in kind of a basic level so I'm going to make some 3d primitives and talk about how lighting works in that context and then in part two I'm going to discuss the the impact of creating light maps and other elements of assets so in unity and this is similar in most game engines but in unity there's a certain amount of pre-baking that goes into creating lighting most lighting by default is dynamic but you actually have to set up assets so that they can pretty baked lighting properties in order to get a more elaborate context for those assets so basically what we're going to do let's go ahead and I'm going to create a plane so I'm going to go to game object 3d object plane and then I'm going to go to game object 3d object and select cube so now that I've got a cube here in the environment it's just kind of a really basic setup I want to talk about how baking lighting works so we've got a directional light and that's that's totally cool it's currently set to baking real time it has soft shadows and there's a number of other properties that relate to that but for for right now the first thing that we want to do in order to be able to create some pre baked lighting effects is we need to mark the objects in the environment to static so there's this checkbox called static at the top here and if I mark these both to static and then I make sure I save my scene then what this does is it kind of pre bakes details of lighting into the environment so the main impact that that has is it creates a little bit of like a light bounce effect by default so let's try to do something so that we can more clearly illustrate that so I'm going to create a couple more objects so first of all we've got this lighting tab and if you haven't don't have it you can go to window lighting and the lighting tab we can break off or we can we can dock somewhere else that I'm going to just dock it here for right now but lighting has a bunch of different settings that we can control so one for example is setting up a skybox it will it does you don't actually have to set the Sun but if you want it to pick a Sun for the procedural skybox you can do that by slotting it in there there's a ambient GI settings here and then there's settings that apply generally which is like the general GI settings then there's bates GI and precomputed real-time GI I actually want to fought this over here because I think it's a little bit easier to read that way there's also things like fog which you can turn on which is usually kind of cool but so what happens is in unity unity uses a system called enlighten which is a way of propagating global illumination which is basically indirect light bounces that occur in a scene when light hits a surface it will bounce off that surface and also create a bounce lighting effect so I'm going to go ahead and create an area that has a little bit more concave surfaces or a little bit more surfaces to basically traverse for the light to traverse so I'm going to kind of like make some extended walls with these cubes so I'm going to actually going to make a scale ten because I know that'll be the exact same size as this this wall here I'm going to line it up with the with the floor there hit ctrl D and I'm going to hold down control so I can make a copy it's snapped then I'm going to select both of these hit ctrl D I apologize I'm actually a little bit sick right now so apologize if my voice sounds a little bit hoarse so then I'm also going to actually make this kind of an enclosed space so I'm going to grab one of these hear it on this one side and I'm going to actually rotate it a bit so that makes kind of like a cover on the environment and yeah so that'll but that'll be okay and so then what I want to do is I want to make sure that all of these cubes are marked static and then you'll notice because it's set to lighting Auto baked this will actually immediately start updating the scene and so what happens when you're done baking that is that you get kind of this dramatic light bounce effect where it looks like suddenly the the environment has a lot more character than it did before and so if I rotate the light around you'll notice how the indirect lighting gets affected by that so you'll see there's kind of a shading that happens here and so if I go to the inspector and just start like rotating the light around it's kind of a subtle effect but you can see how like so for example when the light is here it's actually bouncing light onto the walls and all this is actually real time the the actual light interaction fully real-time and it can work in pretty much any scenario the difference is that the objects that create these kind of light bounces have to be static so they can't move and essentially you have to create a pre-baked in order to make this work so let's let's modify a few properties here and then we'll be able to see how this affects things so for example under the lighting tab precomputed real time GI is what controls this effect so under the real time resolution we have two texels per world unit so the first thing i want to show you is what happens if we change this to be much lower so if I change it to 0.1 basically it becomes a less accurate solution and it's a little bit more generalized so you'll notice that you won't actually see all of the the kind of the shadow effects and things because it's basically using a lower resolution to calculate that and that can make it a little bit better for performance but it does reduce the visual quality it also takes a lot less time to bake but then we could go in the opposite direction and we could say okay we're going to make a resolution of four instead of two and I will say that in most video game environments the the resolution becomes a little bit untenable when you get past - I think - in most actual real time game environments is probably the highest you're going to want to go because past that you start seeing some real performance overhead but but you can see how this affects the quality of the lighting that you get so obviously now that we've got this at four we've got a lot more vivid shading so like you can see there's a shadow here or on the ground and all that kind of stuff so let me actually up this again to eight and then I'll go ahead and let it bake it rebake and then we'll just have an idea of what that what that does now the higher resolution you place this at the the more the environment will actually take to bake so you have to be a little bit careful with that it's like for example eight is probably way beyond a resolution that would ever be feasible for for making a full game environment like you can do it with with a seam like this because it's because it's reasonably small but once you start having anything of any particular size it'll it'll become a lot more difficult now one thing that's kind of interesting about how unity baking works is that everything that you bake is stored in what's called the GI cache which is a way of recalling baked data more quickly to increase the time or to reduce the time that a bake takes in subsequent tries so actually if you start by doing a lower resolution preview bake it will bake substantially faster and then that data can be used to make higher resolution bakes faster whereas if you do say for example if I jump down to a four resolution it'll rebake that in a few seconds and then if I wanted to make it an eighth resolution again I could go back and that could be done in only a few seconds whereas it might take 30 or 40 seconds with this scene just from from a standstill so I'm actually gonna switch back to four because I personally actually think the visual quality is a little more consistent for when you get up to 8 it starts having pretty high resolution artifacts that start popping in but okay so I want to talk a little bit about some of the features of this lighting and why you might want to use it and then I'll show you how the baked lighting works and then we'll talk about some more enhanced features so one thing that you can do is once the lighting is baked you can actually apply material properties that have an impact on the lighting environment to no additional cost so for example I'm going to go ahead and make a new folder called materials and I'm going to make three materials I'm going to call a right-click select create material make one called an underscore read credit new material M underscore green create a new material M underscore glow and then so basically what I'm going to do is under the red one I'm just going to change it to a red color green just change the albedo color to green and then for the glow I'm going to make it kind of a yellowy color and then under the emission I want to change that to kind of a yellow emission color and then I'm going to make it a little bit more intense increase the brightness in the settings here so so what I can do is it so for example if I take this green and apply it to this wall and then take the red and apply it to this wall then you'll notice how automatically this environment starts getting influenced from these these lights but are from the the impact of the light hitting the colored surface so you can see that when the light is really hitting this area here it creates this red glow and when it's hitting this area here it has this strong green hello and that's pretty neat but even more broadly than that I'm going to actually go ahead and take out the directional light for a second so that the environment is kind of dark and then I'm going to add the glow material to the box in the middle and what you'll notice is that the Box in the middle is now actually emitting light in addition to having a glowing surface on it so if I increase the intensity of the glow it actually affects the lighting of the entire environment and it does that in real time which is is pretty cool just as a as an effect and I think hopefully you can see how that might be incredibly useful for creating advanced lighting and then the other thing that's worth noting about this is that the performance of this is much much less expensive than using conventional lights now I want to make a couple of quick points about how how this system works I'm actually going to go ahead and undo that so that we don't have the the glowing box there but so the other thing that's worth noting so I'm going to turn off my directional light actually I'll leave it turned off is that if I place a dynamic object so if I go and I make like a a sphere here and I just kind of like stick this somewhere here you'll notice that it actually doesn't look very consistent with the lighting around it and basically that's because it's a it's a dynamic object it's not set to static and now the first thing that you might think is like well we might want to just set it to static so that it'll have the matching lighting so if I if I set this to static right here it'll rebake really quickly and then when it's all done getting rebate then that object will now have the proper lighting contributions just takes a second moon should be done now anytime you bring a new object into a scene it uh it takes longer to make but okay so then now this looks like it's a little bit more consistent with the environment here but there's a there's a big problem which is in some cases we actually need something to not be static and still be in the environment and obviously we don't want to have to make every object static in order for it to look consistent with the game world so what I'm going to do is I'm going to turn off static here and I'm going to set up what are called light probes which are basically a technique to light static or dynamic objects with the lighting contributions of the static scene without having to actually bake the lighting that way so Oh actually that was that was wrong oh yeah I made the wrong thing dynamic okay so there we go okay so what we'll do is like let's say we add a rigidbody to this this sphere and I'm going to move the camera in here so I'm going to go to main camera and I'm going to go to game object aligned with you so then if I play the scene we'll notice how that the rigidbody causes that ball to fall and in fact I shall move it over here a little bit so we can see it better and so we can tell that obviously that means it's a dynamic object so we can't make that static so let's go ahead and go to object good game object light and what we're going to do is we're going to create what's called a light probe group and what's cool is actually the moment I drop this in you'll notice that the lighting on that object massively improves and that's because it's now being influenced by the placement of these these light probes so what's cool is that you can like set up a light probe group like so for example here I'm kind of scaling this out so that I can roughly match the shape of the room and then I'm going to actually scale it on the y-axis as well and then you can add in more probes so there's a couple of ways of doing that one is to just like add probe so for example if I just add a probe here then I could like maybe add a probe in front of the box I could go to add a probe and it'll actually snap those probes to wherever it is that I'm looking so if I Center my view I can get more probes added into this group just by kind of like looking where I want them to go and so like for example if I wanted one on the middle of this wall I could just go to add probe and then I got to be careful that it doesn't think I want it somewhere else but then I can like position them there and the more probes you have the more accurate cool shooting the more accurate the lighting contribution will be so then for example if I turn my directional light back on then you'll notice that if I start moving this this dynamic object around it shows that it's getting influences from different sets of reflection probes based on which ones are basically the closest or most accurate contributions so if it's all the way over here it's going to be receiving influence from those probes and if it's over here it's gonna be receiving influence from those probes and the main idea is that this is not a hundred percent accurate with what you would get out of base lighting but it's probably the closest you can get in most cases without doing a like a really elaborate setup which would be basically limiting their options as far as utilizing these objects so basically it gives you an environment object cohesion which is really what you're what you're shooting for and light probes are really really useful we put them into every scene that we're doing in reflections and graves so that it has the maximum impact but there's also something else that we can do to make these these scenes look more accurate so for example maybe on my sphere I actually want to make a reflective material so I'm going to go ahead and create a new material then put all this em reflective I'm going to stick that on the sphere and then I'm going to make it like extra smooth and I'm going to make it kind of metallic II and actually what I'm going to do is I'm going to make it look like it's kind of got like a gold texture to it so you'll you'll notice that it looks like it's reflecting the sky but it doesn't really seem to be reflecting anything else that's accurate to the environment that's because we don't have a reflection probe so similar to light probes reflection probes are a way of getting information from the scene from the static scene and applying it to all objects including static and dynamic objects so I'm going to go to game object light and reflection probe now reflection probes have to be baked but you'll notice that they have a really awesome effect which is that they actually make it look like it's reflecting the entire environment and all I did was actually just drop it in and it already looked like it was kind of working but there's a couple of cool things we can do with reflection probes so for example we can change the resolution of a reflection probe so I can set it to 256 and this reflection probe is set to baked but you can also set it to custom or real-time and because we've got the lighting set to bake automatically we can just make changes and we'll see the updates pretty immediately but the main thing that I want to draw attention to is this option for box projection now in general reflection probes affect every object that are within their box but it's treated as kind of an infinitely far away reflection so it has no physical space so like moving this object over to this side has no material effect on the reflection versus it being all the way over here on this side you'll see that it basically looks like the same reflection but if I go to my reflection probe and I turn on box projection what it basically does is it projects the reflection on to the edges of this box so if I want it to be really really accurate I can I can match up the walls with the edges of the box so for example if I click on this button here for editing the bounds the box bounds of a reflection probe then I can basically grab the handles here and I can slide them until basically they're just just on the outside of the floor and walls but the floor ceiling in walls so and you can see that they if they are through the wall you'll actually see the inside of the box projection but so and then the last one is down here oops so I'm going to slide that up let's see there we go alright and I basically just want them to be right on the other side of the wall and then so you'll notice that like when this this kind of reflective gold object is right next to the red wall it actually looks like it's right next to the wall and so similarly if I slide it all the way over to the other side it looks like it's actually right next to that wall and to better illustrate this I'm actually going to make the floor more reflective as well so that you can see how it uses that box protection so I'm going to create a new material m400 drag that onto the floor then I'm going to set the smoothness two to one and I'm actually going to set the metallic to one as well and so what you'll see on this floor is you actually see like a near-perfect reflection of the environment and obviously as I reduce the smoothness it becomes a little bit less defined so like for example I think maybe that might be a slightly more accurate representation of what a reflection would look like in real life but what's cool is then if I switch the different types of reflection probe setting between box trijet projected and non box projected you can see what that looks like so if I turn off box projection you'll notice that it now doesn't have any specific details relating to where that projection is placed it's just kind of like out there infinitely far away but then I turn on box projection and then it basically snaps to the boundaries of the box so there's some good and some bad things about this the main thing that's bad about it is that you run some risks when you're working with a box projection of making a reflection that just doesn't look terribly effective because of a room or an environment that isn't particularly box shaped now I personally think that box projection works in a majority of the time in majority of cases but there are some times where box projection is less than optimal and you'll just have to get some experience with it to see which times you think that maybe you would want to use projection box production which times you wouldn't but in general I really like box projection I use it almost all the time because I think it actually creates a more accurate representation of an environment and it just looks really really cool so so one last thing that I wanted to say about this is that different lighting types all can be influencing your baked lighting so for example if I go to game object ly I can create a point light and this point light will also do light bounces I can do a spot light and this spot light will also have an impact on both the direct and indirect lighting at every light that you create has properties that that influence this result so number one you have like most lights have a rage they have an intensity so in addition to those kind of basic features obviously you've got things like color you can change the color of a light and you can see how actually the the red light is being reflected bounced into into the ceiling and actually let me go ahead and reduce the reflectiveness of this floor so I'm going to make it less metallic and I'm going to make it less smooth so you can see how having a bright red light here is actually causing light bounces all around the environment so if I turn off my directional light you can get a better idea of what that looks like but in general those those properties are pretty straightforward and you can add things like you can turn on shadows so if I turn on for example hard shadows or soft shadows you can see how then this will cast shadows but it still has a contribution to the light bounces so obviously you can see how that affects things and but what's really cool is there's also a setting for bounce intensity every light has a setting for bounce intensity and this is kind of like a custom tweaking option but like so for example if I wanted it to bounce at a greater value than what the default setting is I could pump up this light bounce intensity and I could make it that the light bounces to a really extreme amount and so some examples of when you might want to do that would be in situations where say you have a lot of light bouncing into an environment like an interior space and you're trying to light that space fairly effectively so like for example here if I turn on my directional light and I want the directional light to be having more of an impact I can increase the bounce intensity and then it'll it'll actually be brighter in the areas where the light is bouncing around so hopefully that makes sense but let's let's go ahead and talk about a few additional properties here so for one under the lighting tab we have the ability to increase or decrease the influence of various features in the environment tab you can change the contribution of the ambient source so for example this is using the skybox but you'll change it to a gradient or color and those are just kind of simplified versions I pretty much always use skybox and then you can plug in different sky boxes to get better results but you can also adjust the ambient intensity so for example if I wanted the ambient lighting from the skybox but to be more intense I could multiply the an't the general ambient intensity to be beyond what the default is or like if I were making like a horror game and I want it to be really dark and brooding I could actually reduce the contribution of the ambient so for example if I do it like at 0.25 here and then give it a second for the reflection probe to rebake then you'll notice that the environment inside here is much much much darker than it would have been if the Abbe the full ambient intensity had been used and that that's a good way of kind of like getting more custom effects um you can also do things like you can affect the reflection intensity so if for example we went back to our floor and made it like ultra reflective here we could then modulate the reflection intensity and also we could increase reflection bounces which allows us to pre-bake more information about reflection bounces and then once it reread bakes those reflections then we'll see those impacts take place but so I want to for a second talk about the alternate version of baking lighting which is baked instead of pre computed real time GI so a fully baked is a non dynamic lighting now the main difference between the two is it a non dynamic lighting environment cannot change but it has the benefit of basically having next to no overhead for lighting contributions so if we were to say take a let's let's go ahead and turn on our directional light here I'm going to make the floor kind of back to normal and then I'm going to go and probably increase the ambient intensity but I'll reduce the bounce intensity of the directional light to get kind of a look like I kind of expect I'll go ahead and actually I'm going to turn off precomputed real time so we're only going to be dealing with baked GI and there's a lot of different settings here and I think that some of these might be best for you to just experiment with but what's cool is all you have to do to take advantage of that is start switching your lights from real-time to baked and then basically when it goes through this process of baking the light you will have an environment that has fully calculated light Maps rather than using actual dynamic light and this is useful in a lot of video game scenarios because games have a hard time often rendering lighting in real time and if you don't actually need to move your lights it's better to bake the light down than it is to to leave it to leave it on dynamic so so you'll see for example here the lighting looks almost identical except that if you look closely you'll notice that it that those shadows are a little bit more pixelated now and so let's so that we can talk about this let's actually switch to the lighting off of auto for a second so it's good it's not going to update when we change it and so I'll show you that if I start rotating this this light around it actually doesn't make a difference and in fact the light being totally turned off will not matter because the lighting is now baked into the scene so that gives us the ability to make the most performance optimized scenes possible with the only downside being that the light can't change very drastically Oh Sunni and you'll also notice like so if I if I turn on emissive materials or something like that I would have to rebake it for this kind of thing to apply now this that this may seem like it's less featured which to some degree that it is but it has a lot of advantages as far as performance like it is way way more efficient to to do lighting in this fashion so do it if you can basically because it would definitely be worth it and then the only thing that you want to watch out for is you want to make sure that you have an appropriate resolution so that it creates a set of light Maps that is not too large but still has a good balance on detail and influence so and then you can also do things like you can add some additional features so for example there's ambient occlusion I'm actually going to I'm going to set ambient occlusion at one and then I'm going to turn on final gather and then I'm going to rebuild that so in this case I actually forgot I had turned off the directional light but what you can this probably illustrates pretty well you can see that with the ambient occlusion turned on it creates kind of like a darkening fade around the edges and corners of objects and then it also creates a little bit more elaborate like bouncing contribution from the final gather that we turn on so so yeah in general this is kind of an intro to how how lighting works in a system like this and one thing that I think is important to note on why you might want to bake lighting is that you can potentially get higher quality higher resolution lighting for lower cost by using baked GI so if you you can set this to a substantially higher texels per per world unit then you would be able to using the pre computed GI and so just to help you visualize how this stuff works under the you see where it says shaded here in the scene view you can actually change this to view some information about the global illumination process so for example if I go to UV charts this gives you a rough idea of how many pixels are being used for light bouncing contribution and then you can see if you go through each of these categories you can see different aspects of how the system works so most of these are for the dynamic global illumination but you'll notice that if I look at the UV charts this is actually showing what the the pixel resolution is for our current precomputed GI and then if I go down here to baked this shows how many pixels we have for the baked lighting and you'll notice that it's substantially substantially more than you what you would normally have if you're just doing the the pre-computer in real time so okay I think that's a that's a pretty good introduction to how this works hopefully this makes sense to you guys um one last thing I wanted to show you is when you're doing pre computed lighting and you're not actually doing the pre computed real time and you're doing actually the fully baked light if I create a spotlight like if for example and I turn on shadows I change it to a baked light and I extended the spotlight angle and I place this in a spot maybe like that and then I increase the the intensity a bit when I bake this it's actually going to bake the light entirely and all the lighting contributions so if I go ahead I'm going to turn off the ambient occlusion and I'm just going to bake this again now the one thing that you've got to keep in mind with baked lighting specifically and this is true in all of the lighting scenarios but it's particularly true in bakelite is that you really have to have reflection probes when you're baking the light in in an environment like this because objects that are not are not baked will not be able to receive proper lighting contributions at all from the scene unless you have light probes so just bear that in mind so for example like in my light probe group here what you're going to pull this light probe up because it looks like it's it's not getting calculated properly but so if I turned off my light probe group for a second so if I disable that completely this object cannot receive lighting even from the the object here so but if I turn on my light probes I can actually add additional probes to sample more of the lighting where this object is being lit and so I can add a couple more here and and then I want to make sure that I've got everything is baking properly so right now it's not receiving any contributions for that lighting but once we lose we bake everything together then we should see those light probes actually sampling from the baked lighting and so you'll see that like the light probes here like so for example this is a light probe that is inside this shaded area but this is a light probe that is directly on top of where this was being hit by a light directly so for example when the object is all the way over here it's going to be kind of in shadow and when it is up here in the the main environment it has a brighter lighting contribution and if you want to have an idea of how the light probes are affecting something you can see what the current contribution is by looking at that that probe that you see in the middle when it's being selected so for example if I changed this it's probably easier to see here if I change the metallic and albedo properties so for example this is what it looks like when it's in the light this is what it looks like when it's in shadow and it has kind of like a rapid natural transition between those states and then if you bring it down into the shadow here the only thing that you need to keep in mind with this is that it doesn't actually do direct shadowing anymore it just does the the light probe contribution so you've got to be a little bit careful with how you use this because if you need shadows on an object this may not be may not be the way to tackle it so just be aware of that and that's I'm going to go ahead and wrap up this lesson actually I think it went closer to the the full length of time than I expected so I'm going to go ahead and wrap this up thanks for watching and I hope you this gives you an idea of how lighting works in in unity 5
Info
Channel: Tristan Parrish Moore
Views: 79,869
Rating: 4.923913 out of 5
Keywords:
Id: 7fI3MBMSR5k
Channel Id: undefined
Length: 44min 29sec (2669 seconds)
Published: Mon Sep 19 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.