From the course: Cert Prep: Unity Certified Associate Game Developer Materials and Lighting

Shadows and quality - Unity Tutorial

From the course: Cert Prep: Unity Certified Associate Game Developer Materials and Lighting

Start my 1-month free trial

Shadows and quality

- [Narrator] In this chapter of the course, we're going to focus on a range of different light settings, additional light settings that can help us optimize the rendering of our scenes and improve the running of our projects. To demonstrate the first set of settings that I want to review are the shadow settings that apply to pretty much any light type you can create inside unity. To take a look at these, I've opened up this project here that you can find inside the course exercise files. And inside this scene, you will see the familiar lightbox, the Cornell box that we've been working with here. There really isn't very much to this scene apart from walls, floor, cube at the center. And most importantly, we have this point light that has been added to the scene. Now to update the lighting settings automatically, I'm going to make sure that I go to the lighting tab, moved down to the bottom and activate the auto-generate checkbox. If you're not familiar with the lighting tab, do check out the preceding chapter of this calls, where we cover this in a bit more detail, we're going to be reviewing some of these light mapping settings shortly. But here I want to focus on shadows particularly. When I select the point light inside the scene here, you can check out the shadows section. Now here the shadows are enabled, they have this tick box to say they're enabled. And you can also check out inside the scene here that we have some shadows being cast around the floor area. Of course, if I move this light to a different location for example, if I bring this light forward, you will see that the shadows update the lighting rebates. It might take a little while for it to do that, but when it's done that the shadows will update. And you can see inside the scene, we have the shadows here. But you'll see that from the shadows rollout. There are actually quite a few more settings that I want to review and explain how they work. So you can set up shadows to work the best they can for your projects. The first setting here that you'll notice is the update mode. And by default, for every light this will be set to every frame. This simply means that the shadows, their angle, their intensity are always going to be calculated by the light on every frame quite literally. Now, this is a great option to select particularly if you're going to have objects moving around in the scene frequently. But if you have objects that don't move around very much or infrequently, you might want to check out some of these other two settings. We have the all enable option. This will allow us to dramatically reduce the amount of times shadows calculated in our scene. It will simply calculate the shadows whenever the light is activated. That is when the on enable event happens. Now, this is great if we are activating the light and you're turning it on and turning it off and you just want to activate and reactivate the shadows every time a light switches on and off, such as when somebody presses the light switch on a wall. The other setting here on demand, simply means that when we run a particular functioning code, when we tell the light explicitly to update it will update. And otherwise it will make no change. This is quite useful if you have a particular very customized type of light. In most cases, you'll want this option to be every frame to get the most accurate kinds of shadows for your scene. The other setting we have is the resolution setting. And again, by default it's sent to the custom value of 512 here. This simply refers to the size in memory in pixels of an image file that's being used to shave the shadow information for this light. So currently we have a square texture of 512 by 512 pixels. And for this scenario, it looks okay. If I wanted to improve the shadow quality, I can change this for example to ultra. And when I do you check out the shadow here inside the scene, I'll change this to ultra, and you can see we get this super sharp edge to our shadow because now this shadow is using a ton of pixels to store its lighting information. The lower we take this setting. For example, if I take this pretty low, the lower we take it, the less accurate the shutter becomes and also the blurrier the edges. Now take care because in some scenes having this kind of blurry gradiation inside your shadows for various kinds of aesthetics can really work quite nicely. So sometimes you can have an advantage by setting these settings pretty low. I'm going to set them back to custom here, to reconfigure back to the default. So these are some major settings that we have for the shadows panel. We also have the contact shadows option which we can enable. This gives us a kind of ambient occlusion effect. But be careful if your light has multiple scenes, there is only one light in the scene at any one time that these contact shadows can apply to. Now, we're looking here at some shadows that are on the light object itself. So these shadow settings are per light settings. Meaning that you can set them to different values for different lights. But if you want to tweak global settings to control shadows scene wide, then here's how you do that. You need to access the render pipeline settings. You can do that by choosing edit and then choosing project settings and then select product settings to display the project settings dialogue. When you get access to the project settings dialogue, just go over here and check the graphics option. And you'll see we've got a ton of different options here but way up at the top you will see the HD render pipeline asset. I can just left-click that asset. And here in signed the project panel right at the bottom I can just select the render pipeline asset to get access to all of its settings here. And there are quite a few settings. The settings that I want to access the shadow settings are under the lighting rollout. So I can click on the lighting rollout to reveal these settings. Slightly further down you will see shadows here so I can expand those settings to get access to these here. You'll notice that there is the setting maximum shadows and it's currently set to 128. That means that there can be up to, and not more than 128 shadows on the screen at once. Which is actually a ton of shadows. But if you have a scene with a lot of objects, it might not be enough. In which case you can increase this. But keep in mind that the higher you take this value the more computationally expensive your scene will be. So you can significantly damage the performance of your games or visualizations by increasing this above 128. So be very careful about doing that. We then have some more global settings that we can apply. For example, to directional lines to set those shadows in particular, I can change the default sizes for the shadow maps here, the maximum resolution that they can go to. And these refer to the shadow map sizes that we saw on each of the lights but I'm going to leave these exactly how they are. So these are some global parameter tweaks that you can apply to all the shadows in your scene. By using this combination of these global parameters and the per light parameters, you have a lot of flexibility for how shadows work. Of course, in an ideal world if you really don't shadows for a particular light at all, then just make sure that you switch them off and you don't use them. Only make sure this setting is enabled for lights when you rarely need those shadows because shadows are very, very expensive.

Contents