This page describes optimization techniques that help you make shadow rendering faster in your project.
Factors that affect the shadow rendering time include:
The number of visible objects that cast shadows. This number depends on the Max Distance property.
The number of visible objects that receive shadows.
The number of shadow-casting lights.
The Cascade Count property value and the sizes of the cascade splits.
The shadow resolution of the main light and additional lights.
The Soft ShadowsA shadow property that produces shadows with a soft edge. Soft shadows are more realistic compared to Hard Shadows and tend to reduce the “blocky” aliasing effect from the shadow map, but they require more processing.
See in Glossary property.
The following sections describe how to use those and other settings to optimize shadow rendering performance.
Use one of the following techniques to optimize shadows cast by the main light.
Use the shadow cascades feature to improve the visual fidelity of shadows without increasing the shadow map resolution.
Consider the performance impact of shadow cascades when selecting the Cascade Count value.
Using the Soft Shadows property lets you achieve higher visual fidelity with lower shadow resolution values.
The Soft Shadows property might have a significant performance impact on platforms that use tile-based rendering, such as mobile platforms and untethered XRAn umbrella term encompassing Virtual Reality (VR), Augmented Reality (AR) and Mixed Reality (MR) applications. Devices supporting these forms of interactive applications can be referred to as XR devices. More info
See in Glossary platforms. If your target platform uses tile-based rendering, profile your application to determine the performance impact of this setting.
You can use a combination of a lower shadow resolution and the Soft Shadows option as an artistic technique. While high shadow resolution makes shadows more detailed, it also makes the shadows look sharp, which might not suit all artistic styles.
For example, in the following illustration, the image on the left has a shadow resolution of 4096 pixelsThe smallest unit in a computer image. Pixel size depends on your screen resolution. Pixel lighting is calculated at every screen pixel. More info
See in Glossary, while the image on the right has a shadow resolution of 1024 pixels with the Soft Shadows option enabled.
Lower shadow resolution provides a softer shadow look, which might benefit some scenes. Left: resolution 4096 pixels, right: resolution 1024 pixels.
For more information about optimizing the resolution and the maximum distance of shadows from the main light, refer to Configure shadow resolution in URP.
Use one of the following techniques to optimize shadows cast by additional lights.
To create a shadow map for a point light, Unity captures 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 in six directions. The performance impact of this operation is comparable with rendering shadows from six spot lights. On mobile platforms, this uses a significant amount of the available resources per frame.
Reduce the number of shadow-casting point lights on mobile platforms, or avoid them completely.
For more information, refer to the following pages:
To improve performance, you can use scripting to turn shadow-casting real-time lights off depending on the distance to the 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 or other conditions. To do this, use the Light.enabled property.
To avoid light popping, you can fade in and out the intensity
property of a light.
For an example of this technique, refer to the DynamicLightController.cs
script which is attached to point lights in outdoor lanterns in the Garden scene in the Universal 3D sample project.
In areas where objects are mostly static, point or spot lights with light cookies can serve as a substitute for lights that cast real-time shadows.
To configure a light cookie, use the Cookie property of a Light component.
For more information, refer to Introduction to cookies.
The Light Explorer window provides a convenient overview of all lights, reflection and light probesLight probes store information about how light passes through space in your scene. A collection of light probes arranged within a given space can improve lighting on moving objects and static LOD scenery within that space. More info
See in Glossary, and objects with emissive materials in the scene. Use this tool to quickly find lights with certain properties in the Scene.
This section contains general optimization techniques that are not specific to the main or additional lights.
The number of real-time shadow-casting objects has a significant impact on shadow rendering performance.
To exclude an object from casting shadows completely (both baked and real-time shadows), do the following:
On a GameObject, go to Mesh Renderer > Lighting.
Set the Cast Shadows property Off.
To configure a GameObjectThe 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 to cast only baked shadows, use the Shadowmask lighting mode.
The ShadowmaskA Texture that shares the same UV layout and resolution with its corresponding lightmap. More info
See in Glossary lighting mode lets you improve shadow rendering performance by combining baked and real-time shadows at runtime.
For general information about the Shadowmask lighting mode, refer the page Lighting Mode: Shadowmask
Unity uses the following conditions to determine whether a light or a GameObject contributes to the Shadowmask:
The light modeA Light property that defines the use of the Light. Can be set to Realtime, Baked and Mixed. More info
See in Glossary of a light must be Mixed.
The light must be configured to cast shadows (the Shadow Type property of a light must not be No Shadows).
A GameObject must be static.
To view the existing Shadowmask in the Scene viewAn interactive view into the world you are creating. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. More info
See in Glossary:
Maximum four lights can have an overlap in a Shadowmask since it uses four channels (r,g,b,a). If an area has more than four overlapping mixed lights, Unity switches additional lights from mixed to baked mode.
To see how many lights affect a certain area, use the Lighting Complexity view in the Rendering Debugger.
To achieve the best combination of visual fidelity and performance, use the Shadowmask mode in combination with Light Probes.
On medium and lower tier mobile platforms, the Shadowmask mode might be a good choice from a performance perspective.
On higher tier mobile platforms or PC and console platforms, consider using the Distance ShadowmaskA version of the Shadowmask lighting mode that includes high quality shadows cast from static GameObjects onto dynamic GameObjects. More info
See in Glossary mode to achieve higher visual fidelity.
For more information, refer to the page Lighting Mode: Shadowmask.
When using the Shadowmask lighting mode, you can configure certain GameObjects to contribute to the baked shadows and not cast real-time shadows. Follow these steps:
Go the Project Settings > Quality and set the Shadowmask Mode property to Shadowmask.
In this mode, Unity uses baked shadows for every GameObject that has the Contribute Global IlluminationA group of techniques that model both direct and indirect lighting to provide realistic lighting results.
See in Glossary property enabled.
On a GameObject, in the MeshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary Renderer component, set the Cast Shadows property to On.
In the Mesh RendererA mesh component that takes the geometry from the Mesh Filter and renders it at the position defined by the object’s Transform component. More info
See in Glossary component, enable Contribute Global Illumination.
Generate lighting for the changes to take effect.
Now Unity renders this GameObject with the baked shadow at runtime regardless of the distance to the camera.
To cast a simple shadow from an object with a complex mesh, follow these steps:
Create a simplified version of the mesh with fewer polygons.
Assign any material to the simplified mesh. The material doesn’t matter because Unity doesn’t render the simplified mesh.
On the original mesh, set the Cast Shadows property to Off.
Place the simplified mesh in the same position as the original mesh.
On the simplified mesh, set the Cast Shadows property to Shadows Only.
With this configuration, Unity renders the original mesh but uses simplified mesh to render the shadow.
Use the following Unity tools to profile lighting and shadow rendering:
If you need more detail, use the platform-specific profilersA window that helps you to optimize your game. It shows how much time is spent in the various areas of your game. For example, it can report the percentage of time spent rendering, animating, or in your game logic. More info
See in Glossary and debugging tools available for your target platform. Refer to Profiling tools for more information.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.