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.
There are some configurations in the scene that can affect global shadows:
Parameter | Application |
---|---|
Cast Shadow | Whether to cast shadows. This is the main switch. |
Transparent | Whether to cast transparent shadows. When enabled, transparent objects can also cast shadows. |
Resolution | The 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. |
Cascades | The 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. |
Distance | The farthest shadow distance (distance from the camera), beyond which shadows are not visible. |
Fade Border | The 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. |
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:
Parameter | Application |
---|---|
Shadow Type | The type of shadow casting. Different types affect rendering performance and visual effects. |
Shadow Bias | The offset of the shadow. Prevents shadow distortion. |
Normal Bias | The normal offset of the shadow. Avoids shadow distortion. |
Near Plane | The near clipping plane when rendering the depth map. Affects the shadow clipping plane and precision. |
Strength | The strength of the shadow. Controls the transparency of the shadow. |
In the Mesh Renderer Component, receiveShadows
determines whether the object receives shadows, and castShadows
determines whether the object casts 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: