Shadows in Unity
Manual     Reference     Scripting   
Unity Manual > Advanced > Shadows in Unity

This document is unofficially translated by users.Please see the original document here.

Please send e-mail to here, when you have any question about the translation.

Shadows in Unity

Unity 2.0 Pro makes it possible to use real-time shadows on any light. Objects can cast shadows onto each other and onto parts of themselves ("self shadowing"). All types of Lights - Directional, Spot and Point - support shadows.

Using shadows can be as simple as choosing Hard Shadows or Soft Shadows on a Light. However, if you want optimal shadow quality and performance, there are some additional things to consider.

The Shadow Troubleshooting page contains solutions to common shadowing problems.

Curiously enough, the best shadows are non-realtime ones! Whenever your game level geometry and lighting is static, just precompute lightmaps in your 3D application. Computing shadows offline will always result in better quality and performance than displaying them in real time. Now onto the realtime ones...

Tweaking shadow quality

Unity uses so called shadow maps to display shadows. Shadow mapping is a texture based approach, it's easiest to think of it as "shadow textures" projecting out from lights onto the scene. Thus much like regular texturing, quality of shadow mapping mostly depends on two factors:

Different Light types use different algorithms to calculate shadows.

Details on how shadow map sizes are computed are in Shadow Size Details page.

Shadow performance

Realtime shadows are quite performance hungry, so use them sparingly. For each light to render its shadows, first any potential shadow casters must be rendered into the shadow map, then all shadow receivers are rendered with the shadow map. This makes shadow casting lights even more expensive than Pixel lights, but hey, computers are getting faster as well!

Soft shadows are more expensive to render than Hard shadows. The cost is entirely on the graphics card though (it's only longer shaders), so Hard vs. Soft shadows don't make any impact on the CPU or memory.

Quality Settings contains a setting called Shadow Distance - this is how far from the camera shadows are drawn. Often it makes no sense to calculate and display shadows that are 500 meters away from the camera, so use as low shadow distance as possible for your game. This will help performance (and will improve quality of directional light shadows, see above).

Hardware support for shadows

Built-in shadows require a fragment program (pixel shader 2.0) capable graphics card. This is the list of supported cards: