Version: Unity 6.1 Alpha (6000.1)
Language : English
Real-time shadows
Set shadow distance in a scene

Shadow mapping

Unity uses a technique called shadow mapping to render real-time shadows.

How shadow mapping works

Shadow mapping uses textures called shadow maps. Shadow maps are similar to depth textures. A Light generates a shadow map in a similar way to how a CameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary
generates a depth texture. If you imagine a Camera at the same location as the Light, the areas of the SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
that the Camera cannot see are the same areas of the Scene that rays from the Light cannot reach; therefore, they are in shadow.

Unity populates the shadow map with information about how far rays from the Light travel before they hit a surface, and then samples the shadow map to calculate real-time shadows for GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
that the Light hits.

For more information on shadow mapping, see the Wikipedia Page on shadow mapping.

Shadow map resolution

The resolution of a Light’s shadow map determines the size of its shadow maps. The larger the shadow map, the more precise the shadows can be, and the better Unity can capture small details in the shadow casting geometry. Rendering shadow maps at higher resolutions make them look sharper.

The number of shadow maps Unity renders per Light depends on the Type of the Light:

  • A Spot Light renders one shadow map.
  • A Point Light renders six shadow maps (the number of faces in a cubemap).
  • A Directional Light renders one shadow map per cascade.

Unity will try to use the best resolution according to the number of shadow maps that are needed in the scene, and the size of the shadow atlases.

Point lights have a lower limit on size than the other types because they use cubemaps for shadows. This means that six cubemapA collection of six square textures that can represent the reflections in an environment or the skybox drawn behind your geometry. The six squares form the faces of an imaginary cube that surrounds an object; each face represents the view along the directions of the world axes (up, down, left, right, forward and back). More info
See in Glossary
faces at this resolution must be kept in video memory at once. They are also quite expensive to render, as potential shadow casters might need to be rendered into all six cubemap faces.

Additional resources

Real-time shadows
Set shadow distance in a scene