Lighting

Shadows

Shadows can effectively enhance the three-dimensionality and realism of the rendered scene. To achieve this, the so-called ShadowMap technique is usually used. Simply put, it involves rendering the scene's depth from the light source as a virtual camera, and then when rendering the scene from the camera's perspective, if an object's depth is deeper than the previously saved depth information, it is considered to be occluded by other objects, and thus a shadow is rendered.

Scene Configuration

image-20240730114010025

There are some configurations in the scene that can affect global shadows:

ParameterApplication
Cast ShadowWhether to cast shadows. This is the main switch.
TransparentWhether to cast transparent shadows. When enabled, transparent objects can also cast shadows.
ResolutionThe resolution of the Shadowmap. The Low option uses a resolution of 512, the Medium option uses a resolution of 1024, the High option uses a resolution of 2048, and the VeryHigh option uses a resolution of 4096.
CascadesThe number of cascaded shadows. Generally used for large scenes to divide the shadowmap resolution, which can improve shadow aliasing at different distances. After enabling two-level cascaded shadows, you can configure it through ShadowTwoCascadeSplits, and after enabling four-level cascaded shadows, you can configure it through ShadowFourCascadeSplits.
DistanceThe farthest shadow distance (distance from the camera), beyond which shadows are not visible.
Fade BorderThe shadow fade distance, indicating the proportion of the shadow distance at which fading starts, ranging from [0~1]. A value of 0 means no fading.

Light Configuration

image-20240724183629537

To cast shadows, there needs to be a directional light in the scene. Currently, the engine can only enable shadows for one directional light DirectLight, mainly because shadow rendering doubles the DrawCall, which can severely impact rendering performance. In the absence of a specified main light(scene.sun), the engine will default to selecting the light with the highest intensity to cast shadows:

ParameterApplication
Shadow TypeThe type of shadow casting. Different types affect rendering performance and visual effects.
Shadow BiasThe offset of the shadow. Prevents shadow distortion.
Normal BiasThe normal offset of the shadow. Avoids shadow distortion.
Near PlaneThe near clipping plane when rendering the depth map. Affects the shadow clipping plane and precision.
StrengthThe strength of the shadow. Controls the transparency of the shadow.

Projectiles and Receivers

image-20240724184711014

In the Mesh Renderer Component, receiveShadows determines whether the object receives shadows, and castShadows determines whether the object casts shadows.

Transparent Shadows

Starting from version 1.3, the engine supports casting shadows for alpha cutoff (Alpha Cutoff) objects and transparent (Transparent) objects. For transparent objects to cast shadows, you need to enable the Transparent switch in the scene panel:

Was this page helpful?