Planar Shadows

Overview

  • This solution implements planar shadows based on the URP framework.

  • Supports batching with extremely low shader cost, suitable for mobile platforms.

  • Even if expensive ShadowMap technology is desired for shadow effects, this solution can be used in low-quality settings so that low-end configurations can still have shadows.

Key Features

  • Supports fade gradient β€” the farther the shadow is from the origin, the lighter its color becomes.

  • Supports non-stacking shadows β€” shadows will not overlap each other (fade gradient not supported in this mode).

  • Supports stylization β€” customize shadow styles using textures.

  • Supports configurable shadow color and transparency.

  • Supports complex objects (multiple parts, multiple submeshes).

  • Supports Volume β€” configure via Volume to suit different scene requirements.

  • Supports SRP Batcher β€” SRP-compatible batching.

Supported Shadow Types

  • StaticHeightShadow

    • Renders all shadows at a fixed height, suitable for objects on the same horizontal plane.

  • OriginHeightShadow

    • Renders shadows at the model’s origin position, suitable for objects placed at different heights.

  • RootHeightShadow

    • Renders shadows at the root position of a composite object, suitable for complex objects at varying heights.

  • RaycastGroundShadow

    • Detects ground height via raycast and renders shadows on the ground, suitable for characters jumping between platforms.

Usage

  • Use "Tools/GraphicsCat/Graphics/PlanarShadows Setup" menu to automatically set up planar shadows.

  • The auto-setup tool will:

    • Add PlanarShadowsRendererFeature to the Renderer used by the main camera.

    • Create a GlobalVolume in the scene and add PlanarShadowsVolume to it.

  • If the menu tool fails to set up correctly, please set it up manually.

  • Configure PlanarShadowsVolume parameters.

  • Add the RootHeightShadow component to composite objects.

  • Add the RaycastGroundShadow component to objects that jump between platforms.

Parameter Reference

  • Base

    • Shadow Color β€” Shadow color, supports both color and transparency adjustment.

    • Shadow Offset β€” Height offset for shadows, fine-tune to prevent Z-fighting between shadows and ground.

  • Distance Fade

    • Distance β€” The distance from the object’s origin at which the shadow fades to nearly invisible.

  • Stylized

    • Texture β€” Stylized texture, the image content defines the stylized pattern.

    • Scale β€” Display size of the stylized texture; smaller values result in denser patterns.

    • Flow Speed β€” Scrolling speed of the stylized effect.

  • StaticHeightShadow

    • Caster β€” Assign objects that use StaticHeightShadow.

    • Height β€” The shadow rendering height for StaticHeightShadow.

  • OriginHeightShadow

    • Caster β€” Assign objects that use OriginHeightShadow.

  • RaycastGroundShadow

    • Receiver β€” Define which ground layers RaycastGroundShadow will render on.

Performance Recommendations

  • Prefer StaticHeightShadow and OriginHeightShadow for batching support.

  • OriginHeightShadow does not support batching β€” only use for complex objects at different heights.

  • RaycastGroundShadow does not support batching β€” only use for characters jumping between platforms.

  • Merge meshes where possible to reduce draw calls for OriginHeightShadow and RaycastGroundShadow.

OriginHeightShadow Model Requirements

  • OriginHeightShadow renders shadows at the model’s origin.

  • For static models, the bottom of the visible model should align with the origin (this is usually the case in modeling).

  • For animated models, the origin is usually not at the visual bottom, so avoid using OriginHeightShadow; use RootHeightShadow or RaycastGroundShadow instead.

Limitations

  • Shadows are rendered horizontally, so this method is not suitable for sloped surfaces.

  • If the object is outside the camera view, its shadow will also not be visible, even if the shadow itself is within view.

  • In the Editor, if the mouse hovers over the Material Inspector, Raycast shadows may flicker.

  • Transparent materials and cutout materials are not supported for shadow rendering:

    • The transparent areas are usually customized and cannot produce accurate shadow shapes.

    • Due to inconsistent cutout implementations across materials, accurate cutout shadows cannot be guaranteed.

Shadows Not Visible in SceneView

  • SceneView uses the default Renderer, so you must also add PlanarShadowsRendererFeature to the default Renderer to see shadows in SceneView.

  • The auto-setup menu already does this for you; if not, please add it manually.

Enjoying this package?

  • Give it a quick rating or leave a short review on the Unity Asset Store.

  • Your feedback helps us improve and add even more features!

Last updated