Language: English
Importing Objects From Blender
Directional Shadow Details

Shadows in Unity

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Unity 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”). Directional, Spot and Point lights 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 Unity. 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:

  • The resolution (size) of the shadow maps. The larger the shadow maps, the better the shadow quality.
  • The filtering of the shadows. Hard shadows take the nearest shadow map pixel. Soft shadows average several shadow map pixels, resulting in smoother looking shadows. However, soft shadows are more expensive to render.

Different Light types use different algorithms to calculate shadows.

  • For Directional lights, the crucial settings for shadow quality are Shadow Distance and Shadow Cascades, found in Quality Settings. Shadow Resolution is also taken into account, but the first thing to try when improving directional shadow quality is to reduce shadow distance. All the details about directional light shadows can be found in Directional Shadow Details.
  • For Spot and Point lights, Shadow Resolution determines shadow map size. Additionally, for lights that cover small area on the screen, smaller shadow map resolutions are used.

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. The following cards are supported:

  • On Windows:
    • ATI Radeon 9500 and up, Radeon X series, Radeon HD series.
    • NVIDIA GeForce 6xxx, 7xxx, 8xxx, 9xxx, GeForce GT, GTX series.
    • Intel GMA X3000 (965) and up.
  • On Mac OS X:
    • Mac OS X 10.6 (Snow Leopard) or later.
    • ATI Radeon 9500 and up, Radeon X, Radeon HD series.
    • NVIDIA GeForce FX, 6xxx, 7xxx, 8xxx, 9xxx, GT, GTX series.
    • Intel GMA 950 and later.
      • Soft shadows are disabled because of driver bugs (hard shadows will be used instead).
  • Mobile (iOS & Android):
    • OpenGL ES 2.0 or later
    • GL_OES_depth_texture support. Most notably, Tegra-based Android devices do not have it, so shadows are not supported there.

Notes

  • Forward rendering path supports only one directional shadow casting light. Vertex Lit rendering path does not support realtime shadows.
  • Vertex-lit lights don’t have shadows.
  • Vertex-lit materials won’t receive shadows (but do cast shadows).
  • Transparent objects don’t cast or receive shadows. Transparent Cutout objects do cast and receive shadows.
  • On mobile platforms (OpenGL ES 2.0/3.0) in deferred rendering path, all objects that are rendered using the forward rendering path do not receive realtime shadows.
Importing Objects From Blender
Directional Shadow Details