Unity VR Optimization : Lighting and Light Mapping

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
lights and shadows can make our VR experiences look great but they're incredibly expensive so let's learn how to optimize them there is a ton to go over in this video so we are just going to hop right into this project and if you haven't set up the universal render pipeline I'm going to suggest that you go over to my video where I covered that and watch that first before you go over this video now with that out of the way let's talk about optimizing our lights one thing you might notice if you just converted to the universal render pipeline is if you already had lights in the scene your lights might be broken and mine were and I did fix them so I'm going to show you how I fix them and there were two main methods that I was shown the first one is you select your Universal render pipeline asset you come over here you make sure that this is at least set to one because if we turn it to zero they'll all be turned off cast Shadow is set to true and then we want to make sure that per pixel is not disabled and it is also not disabled here and if that doesn't fix it there's another way that should fix it as well and that's going to be by going to edit preferences and then if we go to GI cache if we clean the cache then that should also fix it and that was actually what fixed it for me now that we've done some of that troubleshooting let us talk about the universal render pipeline asset settings so again we're going to come back here and we're going to go under lighting you'll see here again at Main light if we disable it the main light is actually going to be the directional light the x is kind of the sun here in the scene so this is going to be all the settings pertaining to that so any changes here you'll see that we have the Shadows from the Sun here if we disable it they're going to go away and then if I go to per pixel they come back cast Shadows again they go away if we're talking about optimization obviously if we lower the shadow resolution it's going to look a little rougher but that can improve it performance for you next let's talk about our additional lights and you'll see here in this scene I have three lights set up and if we come to the settings over in additional lights we have a few options here we can disable them which we don't want to do you have per vertex which you'll see that it just kind of leaves the light here but it doesn't have the back lighting and then we have per pixel and if we were doing real-time lights then this would actually be more expensive to use but the quality is obviously better and so here you also have the per object limit this determines how many lights can be used to illuminate objects in a scene so if I lower this you'll see it's going to slowly take them out and as I raise it it will put more in well if there's more in the scene that is of course we have the settings of casting Shadows we can turn that on and off we can increase or decrease the resolution and next we have shadows but before I hop down there I just want to mention if you're ever going to do real time Shadows really consider what the cost would be for that if you can avoid it you should so looking at the Shadows down here we have this max distance and what this is going to do is it's going to say well whatever the max distance from the camera that's when we'll start rendering Shadows so if I change it to one you'll notice that the shadows will disappear if I change it five you'll see the Shadows aren't there but if I go in they start to appear and that's how we change that so if you're having a scene where things are a little more compartmentalized in different rooms you might want to play with this and you might get a little more performance out of it unless we're baking our shadows which then well it shouldn't matter too much so I'm just gonna leave that at 10 for now I think the default's actually 50. yeah I'll just do that next we have the Cascade count and the Cascade count will help determine how detailed these Shadows are when our camera is near it but again that comes at the cost of performance we also have these sliders down here for depth bias and normal bias which Unity says if you're noticing weird artifacts with your shadows and your objects try playing with this and that might fix whatever weird Behavior you're noticing and finally we have soft Shadows soft shadows will help blend in here and make it look a little smooth a little more real it just kind of Blends in like you would see in real life but that is also a cost on our performance so you might want to turn that that off so now that we've explored the lighting and Shadow settings in the Universal render pipeline asset let's talk about our lights and baking lights so kicking things off I want to show you the light Explorer so if we go over to window rendering and light Explorer you'll see here this actually displays all our lights in the scene so it's a very convenient way that we can change our lights to do different things and try to optimize them instead of having to click through every single one in the scene and we can play with some of the different modes that these are in you'll see we can make them real time which that means while we're running it is going to be doing all the calculations for the shadows in our project but that is incredibly expensive so where we can we might want to bake them and that means we are going to do all the calculations up front and we're going to create a texture map that's going to lay over all of our static objects in the scene and we also have a mixed mode and the mixed mode is kind of like the best of both Both Worlds so if you have a light that needs to be both baked so we can reduce the calculations there but we still might want it to move around dynamically you might want to consider mixed mode but I'm not going to dive into mixed mode too much in this video here I want to just focus primarily on baked so with that in mind I am going to even change our sun which is this directional light from before I'm going to change that to baked as well we've set all our lights to baked let's get to baking and if we go to window rendering and lighting you're gonna get the lighting window and I'm going to drag it over here just because it's a little longer I'm going to go ahead and exit out of that for now and you're gonna see we are missing a lighting setting so we'll just create a new one I'm just going to name it ffos light settings so our first setting here is real-time Global illumination and what that does is when we are seeing things in real life light doesn't just hit a surface and stop it actually bounces all around and hits different surfaces on top of that in real-time Global illumination we'll do that in real time so that's going to be incredibly taxing and if we're aiming for something like the Quest 2 we don't want to use that so I'm going to go ahead and work that off next we have mixed lighting and in mixed lighting we have baked Global illumination we want to make sure we're checking that because that's going to allow us to do Global illumination but bake it into our light Maps which it's nice to have a little of that Global illumination going on with the forward rendering process that we're going to be using and then we have light mode and we have a few to pick from here and I'm gonna play with Shadow mask and baked and Direct in a different video for this one I'm going to just set it as subtractive so what subtractive does is it only allows Dynamic Shadows from our direct light source instead of our spotlights and our Direct light source so if I press play here you'll see since I have it as subtractive when I rotate this the Shadows are moving when the sun is moving but if I choose one of the spotlights if I move it the shadow on the wall just kind of stays where it is it's not moving like the sun was moving and so there you go that's subtractive now we've made it to the heavy lifting of the video the light mapping settings and starting off we have the light mapper this is going to determine how we produce our light map but what processes it and produces it and so we could go through the CPU GPU or this enlightened function and I'm going to choose GPU here just because it's a little quicker 4p and you're gonna have to determine if your CPU or GPU is better try the GPU out though so for the rest of these settings I'm not going to go into great detail on every single one if you want there will be a link below to my blog post that will describe everything for you if you want to go into the nitty-gritty of all these here I'm just going to give us a short introduction to some of the most important ones or the ones that I found to be the most helpful to change now the direct samples indirect samples and environment samples these all correlate with direct light indirect light and also calculations with the environment and how much we're sampling so the higher these numbers are the better our quality will be but it will also take a lot more time to bake our light maps and trust me if our scene's big enough this can actually take up to hours and hours if we keep these numbers big if you want to just do prototype typing you can just reduce these numbers down until you get kind of what you want in your scene and then raise them back up and you'll see here we also have a light probe sample multiplier that multiplier actually pertains to all these it just amplifies all these numbers and then next we have the minimum bounces and Max bounces so like before when we were doing Global illumination light hits of surface and bounces off it this is the bouncing so it's going to say minimum we want our Rays to bounce once uh maximum we want it to bounce twice and unity says for most scenes bouncing up to two times is good enough for light map resolution when you're still prototyping and building outs and baking light Maps constantly to get your scenes right you want to reduce this to 10 and that will allow you to rapidly bake your scenes and the higher the resolution you know the higher the memory is going to be for your light maps and the longer it will take to bake but again the quality will be a lot better so I say start off low and then when you're finalizing you know crank it back up to a higher resolution here again for Max light Map size we can you know have higher quality have higher settings or we can reduce it again and that is always kind of the trade-off again light map compression you know we can have a low quality compression but that will reduce our size again and I think you're kind of getting the understanding of this of what our trade-offs are with our light Maps we you know we can reduce things it'll make things big quicker and it will reduce file size but the quality will be less built with that let's try generate lighting if we generate lighting that is how we bake our maps and you'll see it did not generate lights at all it actually took them all away and what's going on is I don't actually have any objects in this scene set to static and we do need them set to static because again we're baking lights we're saying these objects aren't moving these Shadows should be permanent and so yeah it's not showing anything anymore so I'm gonna go over here I can click this clear the baking data get our lights back and let's mark some things as static so of course you know the one way we can Mark these is static is just clicking the object going up here and hitting static and so this will contribute to Global illumination and you can actually see that here that there's a setting in the mesh renderer to contribute to Global elimination so if you want to you could actually click on another object come down here and also click on this say yes to all the children and then that too will contribute to Global illumination just like a static object so I'm just going to select all these and start them off as static objects now another thing to mention is if we are importing models from outside we also might need to do a little extra work on them too if we were to bake a light map on top of them so an example would be I'm going to grab this hand model here that I have and I'm going to come over here and it says generate light map UVS all you do is click that box hit apply and if I were to add it to the scene and head off the light on it generate a light map on top of it it would work or hopefully it should work now let's go over and generate a light map so let's go ahead and generate this light map I'm going to click here and you'll notice that it changes it's made it a lot lighter again we have a lower resolution on this so it's not going to be high definition yeah if we come over here to bake lights you can actually see what the light map looks like that it's laying on top of all these static objects and to fully demonstrate what this light mapper is doing is if I take this directional light and turn it off you'll notice it hasn't affected anything in the scene because well we've already baked the lights onto this even if I press play and yeah nothing has changed but if I come back here go over the lighting and clear it you'll see that yes since I've removed the directional light obviously it should be dark and so there you have it a kind of short introduction to light Maps obviously this does not cover everything lights are very complex and you know I want to go over light probes in a different video but for now that is baking lights and so feel free to experiment see what you can do with this and I will see you in the next one bye
Info
Channel: Fist Full of Shrimp
Views: 14,229
Rating: undefined out of 5
Keywords: unity urp, xr interaction toolkit, unity xr, unity vr urp, vr unity optimization, unity vr beginners quest 2, unity xr toolkit optimization, vr tutorial optimization, unity vr light mapping, optimization, oculus unity optimization, vive optimization, quest unity vr, vr optimization, unity xr optimization, unity optimization tips, unity baking lights, quest 2, oculus quest 2, Unity vr quest 2, urp baking lights, unity optimization lighting, unity, Universal Render Pipeline
Id: f39WZcOZ1kw
Channel Id: undefined
Length: 12min 33sec (753 seconds)
Published: Mon Dec 19 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.