Version: 2019.1 (switch to 2018.3 or 2017.4)
Cookies
Shadows
Other Versions

Shadows

Unity’s lights can cast Shadows from an object onto other parts of itself or onto other nearby objects. Shadows add a degree of depth and realism to a scene since they bring out the scale and position of objects that can otherwise look “flat”.

Scene with objects casting shadows
Scene with objects casting shadows

How do shadows work?

Consider the simplest case of a 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
with a single light source. Light rays travel in straight lines from that source and may eventually hit objects in the scene. Once a ray has hit an object, it can’t travel any further to illuminate anything else (ie, it “bounces” off the first object and doesn’t pass through). The shadows cast by the object are simply the areas that are not illuminated because the light couldn’t reach them.

Another way to look at this is to imagine 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
at the same position as the light. The areas of the scene that are in shadow are precisely those areas that the camera can’t see.

A lights eye view of the same scene
A “light’s eye view” of the same scene

In fact, this is exactly how Unity determines the positions of shadows from a light. The light uses the same principle as a camera to “render” the scene internally from its point of view. A depth bufferA memory store that holds the z-value depth of each pixel in an image, where the z-value is the depth for each rendered pixel from the projection plane. More info
See in Glossary
system, as used by scene cameras, keeps track of the surfaces that are closest to the light; surfaces in a direct line of sight receive illumination but all the others are in shadow. The depth map in this case is known as a Shadow Map (you may find the Wikipedia Page on shadow mapping useful for further information).

The sections below give details on casting shadows from Unity’s Light objects.

Did you find this page useful? Please give it a rating:

Cookies
Shadows