LIGHTING in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Really nice tutorial! I was able to add it to my scene

👍︎︎ 3 👤︎︎ u/vlad_the_rad 📅︎︎ Jan 25 2018 🗫︎ replies

The docs are quite vague about this: can Enlighten still be used for realtime lighting and shadows over the baked one with the progressive lightmapper?

👍︎︎ 1 👤︎︎ u/FrontBackItaly 📅︎︎ Jan 25 2018 🗫︎ replies
Captions
so recently came across this awesome tutorial on lighting a simple scene in unity and I thought I would do the same using the new and improved progressive light matter so in this video we'll learn a bunch about lighting and use it to put together this scene also make sure to check out the guy who made the original tutorial LMH poli he has a bunch of really useful videos this video is sponsored by Dennis Pandita then this is an awesome udemy instructor and has just launched a new course the complete unity 3d game development course throughout the series you'll learn how to create six completely different games this includes pong six egg and farmville when you're done you should have a solid understanding of unity as well as programming in c-sharp you'll also learn how to create basic 3d assets using blender so to get started simply click the link in the description and get a discount alright let's get into the video so before we start setting up lighting there are a few things that we need to understand the first one is global illumination we all know that our eyes work by picking up rays of light unless we are looking directly into a light source these rays of light bounce around between objects before hitting our eyes every time the light hits an object it gets modified absorbed or is sent out in a new direction depending on the properties of the material on that object because of how powerful modern computers are this is something that we can now simulate and the results can be incredibly realistic in computer graphics we split up this act of light bouncing around into two categories direct and indirect lighting direct lighting is when light gets sent out from a light source bounces once and then reaches the eye here is an example of a scene with only direct lighting enabled as you can see objects not directly influenced by the light are completely dark indirect lighting is when light bounces off multiple surfaces before hitting the eye of course theoretically light will keep bouncing until it gets fully absorbed but we can often get away by only calculating a few bounces after which the remaining light waves will be so weak that they don't have much influence on the final image anyway now enlighten is a solution for delivering real-time global illumination this is great if you have a lot of moving lights or objects in your scene but often you want to calculate lighting beforehand both to get more detailed lighting but also to save on performance this is called baking when you bake your lighting unity calculates all the lighting values and turns them into large textures that are then overlaid on top of your objects while you can use enlighten to beg your lighting it's much preferred to use the new progressive light mapper the progressive light mapper is a path tracing based light mapper which means that it will realistically simulate lighting bouncing around the scene it does this by gradually sending out light rays from the camera towards the light sources this means that you can see the result as it renders in the editor and you can adjust light properties without having to re render the entire scene so with that explanation let's jump right in to unity sir is the symbol seen in unity I'm using completely default settings here the only thing I've done is gone ahead and import two 3d models we have the room here which is just a simple cubes where we can see through the back faces of the walls and a monkey it's cute right I've also taken my main camera and positioned it so it looks inside of the room now the first thing that we want to do is set up a few light sources by default every unity scene comes with a directional light I will simply go ahead and remove this that's because I want this to be an indoor scene so instead let's create our own lights of course we could go right click light and select one of the predefined lights or we could simply create an object with an emissive material and that's what we're going to be doing here so that's right click go 3d object and let's select a plane that's also disabled lighting in the scene view so we can clearly see what's going on let's set the scale of this plane to 0.2 by 1 by 0.2 let's also reset its position let's rotate it by negative 90 on the Z here it's not pointing out from the left wall I'm gonna hold down control in order to snap this plane it snap it into the wall let's move it down to stand right on top of our ground I'm also going to take it and move it out a tiny tiny bit we can use something like negative 2.49 just to make sure that it doesn't intersect with our wall so right now our plane has a default material applied instead we want to go ahead and create a material that will emit light on to the rest of our scene to do that let's right-click in the project go create let's create a material I'm gonna call this material or light and I'm then gonna drag it onto a plane on the right hand side here under emission let's enable that and here we can choose a color I've already found an orange color that I like so I'm simply going to paste it in here you can of course use the same one if you want I'm also going to set the amount of emission to 1.5 so down here we can see that it makes our material look brighter but in a scene it's currently not really doing anything first off we need to make sure to rename a lighting but still nothing is happening the reason why is that objects with emission won't actually emit light in real time now in order for this to show we have to bake a light map and to do this we have to let unity know that our light as well as the rest of the objects in our scene are all static in other words our objects aren't going to move so we can safely bake a light map for them to do that let's select our plane hold down shift and select the room and monkey as well let's go to the top right here and select static and now you can see in here in the bottom right corner that unity starts baking a light map and right away we can see the result this is by no means pretty yet but we definitely have lighting in the scene I'm gonna rename the plane here to orange light I'm gonna duplicate it and then going to go to the exposition here and remove the minus to snap it to the other side and I'm also going to rotate it around the y 180 degrees finally I'm going to duplicate the orange light material I'm gonna rename it to blue light and then gonna drag it on to the light on the right hand side here I'm gonna select the color and I have a blue color prepared as well and I'm also going to go and change the emission to two finally I'll select the new light and rename it to blue light so now in our game view we can see that we have two lights and this simple scene but it doesn't look too good yet one of the reasons why is whenever you import a 3d object you have to make sure that the object has light map URIs in some cases you can get away by simply selecting the object an enabling generate light map UVs this means that unity will automatically calculate the light map movies for this object if we apply on our room here you can see not much changed that's because when creating this room in my modeling software I've already made sure to create UVs for it as well but makes to use this option if you haven't but a scene still doesn't look that good let's try and change the lighting properties to do this we'll go window go and do lighting and choose settings this will bring up the lighting window first because this is an outdoor scene I'm going to go ahead and remove the skybox material so I'll simply set this to none right away you can see this darkens our scene and gives it kind of a bluish tint that's because the default ambient color in unity is a dark blue if your entire scene is indoors there really shouldn't be any ambient lighting all the lighting should come from light emitters within your scene so we'll go ahead and set this to a complete black we'll also make sure to disable real-time global illumination because again we want to only bake our light Maps and you can see right away our entire scene becomes dark that's because so far unity has been using real-time calculated lighting and now unity actually starts baking a light map again the result here is not too impressive that's because we want to configure our light mapping settings first we choose what light map we want to use we of course want to change this from enlighten to progressive sometimes when changing between the two options you have to go down and deselect Auto generate then go to the drop down arrow and hit clear bake data and then we can once again enable it you'll notice how the entire scene again turns black and it might say it's backing down here but the result is also completely dark the reason why is when using the progressive light mapper we have to make sure to go into our emissive materials so here's the blue light and under emission change it from real-time global illumination to baked go ahead and do the same thing for the orange light and right away you can see the light mapper working in our scene you can also see that it looks very noisy and after while everything suddenly looks smooth and the result is already much better if you now go ahead and make a change to a scene say let's move our monkey we can again see this noise reappearing what we're seeing is actual light rays getting sent out and as more and more gets sent out the noise gets reduced and finally when the light mapper has sent out all of its samples it simply takes the result and blurs it you can also see that because I have prioritized view enabled the light mapper will actually render the part that we looking at in the scene view first this is super cool if you want to focus on a specific part of your scene so now it's time to play around with some settings and the first most noticeable problem that we want to get rid of is this weird theme running down the monkey's head now this seam is here because I've gone ahead and manually uvd monkey and this is one of the places that I decided to put a seam but of course we want to make this as hard to notice as possible and one of the really cool tools that we have here is what is called seam stitching this is something you enable per object so if we go ahead and select our monkey switch to the inspector and go under the mesh renderer under lighting here we have a separate category for light map settings and here is a property called stitch themes if we now enable it you can see that immediately the seam gets blurred out and becomes way less noticeable I definitely recommend turning that on for most complex objects and our lighting actually already looks okay one of the things that we can do is easily decrease the light map size this is simply the end resolution of our texture because our scene is very small we can definitely decrease this to 512 as you can see the end result is pretty much the same and we've just more than half the size of a light map we can also choose whether or not to compress the light map this will heavily reduce the file size but it can also add a lot of weird artifacting to the lighting in fact we can see an example of that right here these weird pants are because of compression on the light map so let's try and disable it you can see right away our light map increases in size but the banding is now gone we can also see on the side of the monkey here on the ear we're getting these weird purple colors now these are definitely not supposed to be here this is what we call bleeding it's when data from one part of the light map leads into data from another part of the light map if we switch to the global maps tab here we can actually see the two textures that were generated for a scene notice how we can recognize different parts of the scene in these maps we have different walls from the room we have different parts of the monkey if some of these elements start to bleed into each other we get this weird result so to try and get rid of this I would start by increasing the light map patting let's try and set this to eight right away we can see that the problem still occurs let's now try and increase the light map resolution let's try and increase it to a hundred now that definitely helped but we can still see a tiny bit of bleeding so let's try increasing them a tiny bit more and there we go with the problem is now gone keep in mind that every time you increase the light map resolution it will also take longer for your light map to bake so some of these settings you might want to leave fairly low while adjusting and then when it's time to bake the final result you can bump them up this also applies to the number of direct and indirect samples sambal is basically just another word for Ray so this here is the number of briefs that we send out per Texel in order to determine the direct lighting in our scene and this here is the same but for indirect lighting in other words if we go ahead and increase these we should get greater detail in the result we can also adjust the number of bounces that we want to calculate we could say set this to 3 and this could take a while so you might want to go off and do something else and you can see the result is a much smoother less noisy light map and the lighting will definitely be more precise this is always one of those settings that I just leave by default when I'm setting up the scene and then crank all the way up when it's time for a final render especially because the number of direct samples and bounces don't have any influence on the size of our light map they just increase the time it takes so I'm gonna set these back and finally I'm going to enable something that will make everything look much much better I think this is everyone's favorite setting to enable I'm of course talking about ambient occlusion ambient occlusion is the shattering that occurs between two nearby objects as you can see in the corners of a room here in the crevices on a monkey and where our monkey sits on the ground so right now it's maybe a bit too much I'm going to decrease it to 0.1 and also decrease the max distance to 0.7 finally if you find errors in your light map that you just can't get rid of by adjusting these settings it might be because it happens during unities filtering stage this is why unity takes the fairly noisy light map and applies some post-processing in order to smooth it out luckily we can adjust how unity filters the light map to do this we go to filtering and you can see what happens if I disable this this is the finished light map in its raw form from here we can go under advanced and we can add different types of filtering I find that in 90% of cases I use caution and here you have the possibility to dial down the amount of filtering both for the direct and indirect lighting as well as the ambient occlusion for indoor scenes I often have to go in here and decrease the filtering on the indirect radius as you can see the scene still doesn't look noisy and it often removes weird lighting glitches but for this scene we can simply keep it add Auto finally if your scene is overall too dark you can increase the indirect intensity or give your entire seen a boost using the albedo boost one of the questions that I get asked the most is how do you add glow to your lights there currently is shining on to the environment and that's fine but most of the time when you look directly at lights in real life or through a camera they will have this sort of glowing halo effect the answer is we don't actually add this through the lighting system instead we use post-processing effects to do that we'll go to the asset store will search for post-processing select it hit import and import again then we want to select our camera go to the inspector and here we want to add a component called the post-processing behavior this will enable post-processing on our camera we can then switch to the game you to see the result right click in the project panel go create and we'll create a post-processing profile which will store all of our settings we called it CC for color correction select our main camera and drag in our CC object and now when we select our CC object we have all these different post-processing effects the one that creates glow for our lights is the one called bloom and this might be a bit too much so let's open up our bloom let's decrease the intensity to 0.3 and let's also decrease the radius to something along 2.8 and while we added we can also add a tiny bit of color grading let's enable that open it up and we'll change the tone mapper to filmic will also increase the exposure a bit and maybe we want to decrease our bloom even more and finally we can go in and add a vignette and we probably want to decrease the intensity on this one as well so there you go that's the basics of lighting a scene in unity that's pretty much it for this video if you want to learn more about lighting such as how to set up real-time lighting in unity definitely let me know in the comments also make sure to check out the complete unity 3d game development course simply click the link in the description to get started and get a discount along the way on that thanks for watching and I will see you in the next video thanks to of the awesome patreon supporters who donated in December and a special thanks to German beefy O infinity PBR euro Omer and soft tune sighs mummy Derek M skirt myrrh free Samara Peter died double-tap 45 James Pete and Evans Thomas Wally Superman the great John Burkhart coke approaches Lotito Alex for kid ski Suniya Hobson James Rogers Robert pond rock fan and Erasmus
Info
Channel: Brackeys
Views: 1,207,199
Rating: undefined out of 5
Keywords: brackeys, unity, unity3d, beginner, easy, how, to, howto, learn, course, tutorial, tutorials, game, development, games, light, lighting, progressive lightmap, lightmap, progressive, lightmapper, map, global, illumination, gi, baked, bake, baking, static, shadow, shadows, sample, samples, path, tracing, backwards
Id: VnG2gOKV9dw
Channel Id: undefined
Length: 16min 13sec (973 seconds)
Published: Wed Jan 24 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.