shown in other instead.
Light sources in the scene are resource-consuming (especially, if there are a lot of them). For example, depending on the light source type, calculation of shadows cast by the lit objects may require up to 6 rendering passes. Some type-specific settings of light sources can affect the performance, as well.
The article describes basic light optimization techniques.
Common Lighting Optimizations#
Some optimization approaches differ depending on the type of the light source. However, there are several common optimizations that can be applied to all light sources in the scene.
Disabling Shadows for Surfaces#
You can disable shadow rendering for some surfaces or materials. For example, it can be done for the farthest LOD surface (when the shadows don't matter).
To disable shadow rendering for a surface:
- In the World Hierarchy window, choose the node and go to the Surfaces section in the Node tab of the Parameters window.
- Select the required surfaces and toggle the Cast Proj and Omni Shadows parameter off. To disable shadows from the world light, toggle the Cast World Shadows parameter off.
To disable shadow rendering for a material:
- In the Materials Hierarchy window, choose the material and go to the Common tab of the Parameters window.
- Toggle the Cast Proj and Omni Shadow parameter off. To disable shadows from the World Light, toggle the Cast World Shadow parameter off.
Enabling Static Lighting and Shadows#
Dynamic lighting ensures that all shadows from moving light sources cast by moving objects are rendered correctly. This approach implies that geometry of your scene is rendered one more time each frame to calculate shadows for each Projected Light (or six more times — for each Omni). Using multiple dynamic lights in the scene and calculating shadows for them on the fly may cause a performance drop, especially when the scene contains complex geometry with lots of polygons. It can be a terrible waste of resources, when most objects and lights are static.
It’s better to avoid dynamic shadows and use baked ones for everything static wherever possible. You can replace dynamic Omni and Projected Light sources with static ones (shadows for them are precomputed and stored in depth textures).
Types of shadows to be rendered are defined by the light’s mode and shadow modes set for both lights and object surfaces.
Depending on your needs, you can choose to render baked shadows only, or combine rendering of both baked and dynamic ones. The table below shows all possible variants of shadow settings.
Thus, for a Dynamic light, shadows from all lit objects are rendered as dynamic.
For a Static light in Static shadow mode, only baked shadows from objects with Mixed shadow mode are rendered; dynamic shadows are not rendered at all.
For a Static light in Mixed shadow mode, both types of shadows are rendered: baked (from surfaces with Mixed shadow mode) and dynamic (from surfaces with Dynamic shadow mode).
Mixed mode implies that the dynamic shadow map is copied into the static depth texture and the result is rendered. If you select a higher resolution, the process of copying the shadow map can take time and affect performance. Therefore, 4K resolution in the Mixed shadow mode makes sense if the scene has more than 1.5 million triangles, otherwise Dynamic mode may be faster. Moreover, pay attention to video memory consumption, as a single 4K resolution depth texture for an omni light takes about 400 MB.
The World Light source works in a similar way, but it uses shadow cascades. In Dynamic mode, shadow cascades are built dynamically relative to the camera's position, while in Static, they are baked and have their area defined by the light source's position. Static mode of the World Light is suitable as a performance optimization technique for small-area ArchViz projects where shadow cascades can be divided into two sections: walkable area with high-resolution shadows (as they're observed closely) and non-walkable area with low-resolution shadows (as they're observed from a distance). Note that changing the time of day is not available in Static mode, as shadow cascades are baked.
Using Shadow Masks#
A shadow mask allows you to control rendering of shadows. You can specify which surfaces lit by a light source should cast shadows:
- For a light source, specify the shadow mask: open the World Hierarchy window and select your light source. In the Shadow Mask section of the Node tab in the Parameters window, specify the shadow mask.
- For all surfaces that are lit by the light source and should cast shadows, specify the shadow mask that matches the light source's shadow mask (one bit at least).
- For all materials applied to such surfaces, specify the matching shadow mask as well.
Using Screen Space Shadows#
For all types of light sources, screen space shadows can be rendered instead of the shadow maps at large distances. It improves the performance, as such shadows don't depend on complexity of the geometry.
You can enable screen space shadows in one of the following ways:
- In the Menu Bar, choose Rendering -> Shadows -> Screen Space Shadows.
- In the Menu Bar, choose Windows -> Settings and then go to the Shadows section. Here you can toggle the Screen Space Shadows parameter on.
You can also set up per-light screen space shadows in the type-specific tabs (Light World, Light Omni, etc.) of the Parameters window.
Reducing Size of Light Source#
All Omni and Projected light sources are subject to a common deferred optimization technique - the Scissor Test: for each light source a scissor rectangle is found to define its bounds and, therefore, the area of its influence. The scissor rectangle defines the size of the render target for the current light source, since everything that falls outside that region is not affected by the light at the current moment.
Therefore, the size of a light source significantly affects the performance: the larger the screen area where the illuminated surface is rendered, the lower the light performance is. So, keep the size as small as possible.
Engaging Interleaved Lights Rendering#
In this mode lighting is rendered during the Deferred pass in half resolution (1/4 of all pixels) with subsequent reconstruction of neighboring pixels using the data from previous frames, making it possible to reduce rendering load.
For more details refer to the Interleaved Lights Rendering article.
Setting Up Visibility Distances#
You can control rendering of light sources and cast shadows by specifying the visibility distances.
Setting Limits For Transparent Objects#
Non-opaque geometry is shaded on the Forward pass of the Rendering Sequence. Since all light sources are applied to each transparent surface in a cycle, it is highly recommended to keep the number of lights affecting transparent objects as low as possible for optimal performance.
Global Lights Settings include Forward Per-Object Limits where you can limit the number of certain light sources that affect each transparent object at a time.
Rendering Lights on Water#
If your scene contains water object(s), you can disable rendering the light from the light source on them. It will significantly increase the performance.
- Select a light source in the World Hierarchy.
- In the Parameters window, go to the Render section and toggle the Water parameter off.
The World Light source illuminates all objects that are positioned along the shadows visibility distance thus increasing the number of calculations of shadows. So it is recommended to keep the number of World Light objects in the scene as low as possible. For most purposes, other light sources (Projected Light, etc.) are more suitable in terms of project performance.
For the World Light, the Engine creates cascaded shadow maps (maximum 4 cascades). Each cascade requires a separate rendering pass.
You can affect the performance by decreasing the number of the rendered cascades in the Parameters window (the Number of Cascades parameter). However, changing the number of cascades also affects the rendered image quality, so try to find a balance.
Omni Light sources emit light in all directions, which allows reproducing realistic shadow casting.
The Omni Light source uses 6 cameras that generate shadow maps, so shadowing by this light source requires 6 rendering passes and can sufficiently decrease the performance. So, keep the number of such light sources as low as possible. For better performance, you can disable rendering of shadows created by the omni light in certain directions or use Projected Light sources instead of the omni ones.
However, there is a way to use a lot of Omni Light sources in the scene without negative impact on the performance: you should disable shadows for them (not screen space shadows). As the Engine uses tile rendering for the omni lights with the Point shape and shadows disabled, they will be grouped and rendered in batches, decreasing the number of DIP calls and making omni lights the fastest light sources in the scene.
The related settings are available in the Batching options:
This optimization enables you to engage big numbers of omni lights with no significant performance drop.
You can also control rendering of omni lights and cast shadows by specifying visibility distances for the light sources. When the camera is located at a given distance from the light source, it is turned off. The same can be specified for the cast shadows:
Projected Light sources cast light from a single point forming a light pyramid. Such light sources produces shadows that require only 1 rendering pass, so they are performance-cheap.
However, the influence of these light sources on performance can be also reduced by specifying visibility distances for the light sources and the cast shadows:
Voxel and Environment Probes#
The Voxel Probe light source provides static voxel lighting and shading on an object inside the probe by using a prebaked 3D lighting map. Voxel Probe is a required object for baking indirect lighting from light sources in static mode.
Using voxel probes as insets inside other voxel probes significantly decreases the performance. Moreover, if you add several nested voxel probes with coinciding size, the visual result will be the same as if you add a single voxel probe. However, the performance will drop. So, if possible, try to avoid such situations.
The main setting of the voxel probe that significantly decreases performance is Cubic Filtering. Disable it, if the linear filtering for ambient lighting is enough.
One more setting that affects the performance is Reflections. When toggled on, the voxel probe is used for both ambient lighting and reflections. We recommend you to use Environment Probes for reflections simulation.
The Environment Probe light source provides ambient lighting and reflections on an object inside the probe by using a cubemap. However, the main purpose of the environment probe is reflections rendering. For lighting, we recommend using Voxel Probes: just toggle the Ambient lighting off in the Parameters window.
This approach allows improving the application performance without loss of visual quality: using both the environment and voxel probes for ambient lighting and reflections rarely gives notable visual improvement.
When you need only the visualization of a light source without illumination, you can use one of the tricks described below.
Billboards can be used to simulate small light sources observed from large distances. In such cases, only visualization of light sources matters. For example, you can use billboards for takeoff runway lights. They don't produce any light, but look like real lights.
To create a billboard that replaces the real light source, perform the following:
- Add a billboard object to the scene by choosing Create -> Billboards -> Base in the Menu Bar and place it somewhere in the world.
- Assign a material inherited from the billboards_base material.
- Specify the following settings for this material:
- In the Common tab, set the blending Preset to Additive and toggle the Depth Write parameter off to avoid obstructing objects behind the billboard.
- In the States tab, disable writing into the Deferred Buffers and enable the following states:
- Emission to provide the emission effect by using the corresponding texture.
- Geometry Inflation to limit the minimum billboard screen size to a fixed value and, therefore, to provide visibility from far distances.
- Soft Interaction to make interaction of the billboard with other objects in the scene softer and avoid artifacts.
- In the Textures tab, specify the Diffuse and Emission textures.
- In the Parameters window, specify the following values:
- Set the Diffuse color multiplier to black, so that the billboard become fully transparent.
- Increase the Emission Scale to make the billboard brighter.
- Increase the Geometry Parameters to scale the size of the billboard and limit the minimum size of the billboard.
- Correct the Soft Interaction value, if necessary.
- In the Common tab, set the blending Preset to Additive and toggle the Depth Write parameter off to avoid obstructing objects behind the billboard.
As a result, you get the billboard that can be used to simulate a small light source at far distances. You can add any required number of billboards to the existing billboard object: in the Parameters window, select the created billboard in the list and click Add.
Using Volumetric Objects#
Volumetric objects can be used to simulate visible light volumes instead of using real light sources. Such objects should be used when you don't need illumination. For example, by using volumetric objects, you can create light spheres, beams, or volumes, imitate sun beams falling into a room through openings, and so on.
To create such light volumes, perform the following:
- Add a volume sphere object by choosing Create -> Volume -> Sphere Light in the Menu Bar and make it a child of the node that should emit the light.
- In the Volume Sphere section of the Parameters window, change the size of the sphere to 0.15.
- In the Node tab of the Parameters window, set coordinates of the volume sphere to the parent node and then slightly correct the sphere position, so that it looks realistic.
- Assign a material inherited from the volume_light_base base material and specify the required values in the Parameters tab. For example, you can set the color of the light sphere and scale the density of the light.
- Add a volume projected object by choosing Create -> Volume -> Projected in the Menu Bar and make it a child of the node that should emit the light.
- In the Node tab of the Parameters window, set the position and rotation of the volume projected to the parent node.
- In the Volume Projected section of the Parameters window, specify the required parameters of the light beam. For example, change its size, radius, field of view, and step.
- Assign a material inherited from the volume_proj_base base material.
- In the Parameters window of the material, set the color of the light beam the same as for the volume sphere and decrease the diffuse scale to 0.5 to make the color less bright.
As a result, you get a light sphere and a beam imitating the real light source.