Shadows

Tutorial

·

intermediate

·

+0XP

·

5 mins

·

(60)

Unity Technologies

Shadows

In this tutorial, we discuss alternate ways of implementing and optimizing shadows.

Languages available:

1. Implementing Fake Shadows

Real shadows are computationally expensive to render. We recommend that you implement fake shadows on dynamic objects instead of resorting to dynamic lights.

Real-time shadows are most often generated using a technique known as a shadow map. The cost of Scene geometry being rendered to the shadow map is comparable to the number of vertices that are drawn to it. Because of this cost, it’s important to limit the amount of shadow-casting geometry, as well as the amount of real-time shadow-casting lights, in your Scene.

Here are some ways to implement fake shadows:

  • Use a 3D Mesh, plane, or quad that is placed under the character and apply a blurred Texture to it.
  • Write custom Shaders to create more sophisticated blob shadows.

The following screenshot shows shadow implementation using shadow Meshes.

It’s a good practice to paint lighting information directly to Textures. Doing this reduces the extra computation that real-time lights require. Painted lighting also saves memory when baking the lights in your Scene, because the Scene needs less Texture memory for lightmaps.

Use Shaders or Materials to simulate lighting when possible. You can use custom Materials to simulate different kinds of light effects. For example, you might want your character to have rim lighting to improve her visibility and visual look. Instead of using lights to create this effect, you can use a Shader to create the illusion of lights.

Shaders can be used to create a large variety of useful visual effects and styles. More information on Shaders and Materials can be found in a previous project of this course.

2. Mesh Renderer Settings

Regardless of what kind of lighting your Scene uses, it’s important to make sure your Mesh Renderer settings are correct.

A good principle is to turn off anything that you’re not going to use. Settings like Cast Shadows can add extra cost to rendering the Scene, even if the object is unlit. The following screenshot shows an example of the Mesh Renderer settings:

The options shown in the screenshot are set to receive lighting, but not reflections, by blending the lighting information from the nearest probes. Cast Shadows is turned off because we are using the blob method. Receive Shadows is also unticked because the Scene is baked and nothing is casting a real-time shadow.

3. Conclusion

Shadows add realism to a 3D environment, but can be costly to calculate at runtime. On mobile devices, it’s best to try to fake shadows using Shaders, Textures, or other methods that don’t rely on shadow-casting lights. In the next tutorial, we’ll take a deep dive into a lighting demo that shows off the potential performance gains of baked lights.

Complete this tutorial