Tom Sirdevan, look developer and lighting artist, explores the different approaches to shadows for direct lights in Unreal 4. He looks at baking the shadows using Lightmass, as well as looking at dynamic shadow approaches like shadow maps for point and spotlights, as well as cascaded shadow maps for directional lights.
- [Voiceover] Let's look at shadows, which go a long way to adding realism and believability to your scene. From a performance context they are not trivial to produce, in fact calculating the shadows of a light are often more expensive than calculating the light contribution. Like the light contribution there are trade offs between making the shadows static, stationary, or dynamic. Let's go ahead and make a spotlight and place it in a part of our scene that allows us to cast some nice shadows.
I'm gonna position the spotlight behind these columns, I'm gonna rotate it so it's casting them in that direction. You're gonna wanna increase the attenuation radius. And if I switch to view mode lit we're definitely gonna have to increase the intensity. I'm gonna try something really high, 100,000, so that it's pretty obvious what the shadows are doing.
Might even go one higher. Now we've got nice, strong shadows. I wanna show you what happens if we bake these shadows, so I'm gonna change the light mobility to static and build lighting only. You notice when the lighting's built that the shadow quality is not very good, especially on the ground.
That's because the landscape is quite large and so it requires a lot of pixels to cover the entire landscape. In other words the texture memory has to be quite large. In order to get better shadows I'm gonna select the landscape and I'm gonna go to lighting, static lighting resolution. This value is a multiplier on the texture resolution for the light map. So currently it's set to one, if I set that to 16 and build the lighting again you should notice that the resolution increases and our shadows should look better.
As mentioned in an earlier video, when we bake our lights and subsequently the shadows we're actually doing a ray tracing algorithm to produce the results. You can see already that the shadows are looking better. I also wanna show you translucent shadows. In order to do that I'm going to quickly create a basic cube. We're gonna take that cube and turn it into a wall-like structure that we can then make translucent to cast a translucent shadow.
In order to make the cube more wall-like we're simply gonna scale it into a rectangle. I've gone ahead and determined some values that are gonna be useful for turning this into a more wall-like structure. Select the cube and go to the scale parameter, type in point one for X, 2.25 for Y, and 3.5 for Z. Now we just have to move this so that it's in between our pillars.
Once it's in its place I'm gonna go over to the content browser, select material, I'm gonna right-click and create a new material. I'll just call it trans mat. With the cube selected and materials open I'm going to drag trans mat into the material parameter. The cube now has the trans mat material. If I double-click on the grey sphere for that material the material editor will open and I'm gonna zoom in slightly and select the root node, trans mat.
Under material blend mode I'm gonna change it from opaque to translucent. Now our material is set up for translucency and in order to make it translucent and not opaque I'm going to right-click and select a constant node. In order to make it translucent we have to plug a value of less than one into opacity. At zero the material is completely clear and at one it's completely opaque, so we want something in between.
I'm gonna select point seven for now. And you can see that it's no longer completely black, it's translucent. Now black is not an ideal color, so I'm going to right-click and choose constant three vector, which is a way to select a color. I'm going to go down to constant and on the color swatch I'm gonna change that to something other than black. Feel free to pick your favorite color if you'd like. This isn't mine, but it's a nice one.
I'm gonna drag that to base color and now we have a translucent pink material. I'm gonna save that. And if we go back to the viewport we should see that it's now translucent. I'm gonna go ahead and rebake the lighting now. Now that the lighting build is finished you should see translucent shadows. You might have had your material not show up the color that you chose in the viewport.
This occasionally happens, but it's nothing to worry about. When you actually go to play the level the color should show up fine. The last thing I wanna show you is utilizing cascade shadow maps with directional lights. So I'm gonna go ahead and bring a directional light into this scene. And as long as our mobility type for the directional light is stationary or movable we can use cascade shadow maps to generate very detailed shadows for large number of objects over a fairly large scene.
Let me make the mobility type a little more visible. In order to show cascaded shadow maps in action we're gonna set the mobility type to movable. The first parameter I wanna look at is dynamic shadow distance movable light. It's a long name, but all it means is the max distance that we're going to sample shadows for. If I decrease this you'll notice that shadows start to disappear in the distance. And if you go right down to zero they're gonna disappear completely.
If I bring that back up shadows start to appear further and further from the camera. The next parameter I wanna look at is num dynamic shadow cascades. This controls the actual number of shadow maps that cascaded shadow maps generates. It generates multiple shadow maps because further away from the camera you are the less concerned you are about shadow resolution. Let's set this value to one to demonstrate this point. No matter where you are relative to the camera the shadow resolution is going to be the same.
It's gonna be rather blurry. If we increase this to two and move the camera around you'll notice that there's a popping happening. And that's the cascaded shadow maps choosing between the higher res version of the shadow map and the lower res version of the shadow map. Three or four are usually good values for a large scene. Shadows go a long way to making your scene look more realistic.
Choosing the right approach to shadows for each light is as important as the light contribution itself and essential for a believable scene.
- Direct lighting
- Indirect lighting
- Creating a sky with Blueprint
- Deferred shading
- Dynamic sky and sun