From the course: Unity 3D: Lunchtime Lessons

Realistic skies in Unity - Unity 3D Tutorial

From the course: Unity 3D: Lunchtime Lessons

Start my 1-month free trial

Realistic skies in Unity

- [Instructor] Hi, I'm George Maestri. If you've ever wanted to do environmental and realistic lighting in Unity, you may want to use image-based lighting as your light source. So let's take a look at how to do HDR lighting using a cubemap in Unity. Now, before we get started, I do want to make sure that we have all the packages installed that we need to have installed. And in this case, I want to make sure I have a high definition RP for render pipeline, and this basically makes sure that HDRI images can be used as a light source. Now, the image we're going to be using as our light source is here in Photoshop, and I've saved it out as an EXR file, and it's called Cubemap_Field, and let me go ahead and just clear these guides. See, this is just one image that wraps around and creates a cube. So we have the left, the front, the right, the back, side of that cube, as well as top and bottom. Now, if you already have cubemaps, that's great. You can use this one, certainly, but you also can find them in the Asset Store. So if you go to the Asset Dtore and search for Unity HDRI Pack, you'll see there's a free pack full of all sorts of great HDRI maps that you can use in your projects. So let's go ahead and take this map and drag it into the scene. So I've got it here under my Exercise Files folder, under a folder called External Assets. Now, I want to drag this in from scratch, so we can see how to set this up. So let's go ahead into our External Assets folder and just left-click and drag that into the Textures folder of your assets. So now that we have it in here, we can click on this cubemap. And right now, it's just a default type of texture, and that's what we want, but we want the texture shape to be cube. And when we do that, it will turn it into a cubemap and recognize it as such. And another thing that I like to check is this Fix Up Edge Seams, and that'll make sure that things kind of flow across the edges if we need to. So let's go ahead and apply that. And now, notice how this change changes to a cubemap. So let's go ahead and bring this into the scene. Now, the first thing we want to do is we want to make sure that our lighting under Rendering, Lighting Settings, we want to see the static lighting for the sky and we want to do an HDRI sky. And when we do that, it will go ahead and turn on the lighting. You can see I'm already getting the lighting here, and that lighting is controlled by a sky and fog volume. So if I close this and click on this Sky and Fog Volume, you'll see that here we have HDRI Sky, and this is where we can input the cubemap that we want. So I'm going to go ahead and turn this on, click here, and you'll see that this cubemap actually shows up. It recognizes that that cubemap's out there, and as soon as I click on it, notice how everything changes, and now I've got my clouds and my more realistic sky. Now, this is a little bit blown out, and so we can certainly change a number of values. So I'm just going to check all of these on, and let's go through them one by one. Now, the first one is Intensity Mode. How do we determine the intensity of this light source? By default, it's Exposure. We can also do a Multiplier or we also can give it a Lux, which is a very specific value. I tend to just go with the default Exposure, and that allows us to kind of just use whatever number we want. Right now, it's a 10. If I put it down to nine, it should be a little bit better. Now, another thing we can do is we can rotate that sky. So if you notice here that light source right now is kind of behind the building, and we want it in front of the building, so let's go ahead and rotate this, somewhere between 120 to 180 degrees, something like that, and you can see how the sky is also reflecting. So as it goes this way, the sky reflects, and so just to get basically the angle of the lighting that we want. Now, the Update Mode, we can change it to anything from On Change, so only when I let go of a value will it change, or On Demand, which is only when it needs to be. If we do it in real time, it will take a little bit more processing power. Now, this is going to affect gameplay. So typically, you want to keep that On Change, and once it bakes in, it should be good. So there you have it. That's a very simple way to create realistic environmental lighting in Unity.

Contents