Light2D

What it does

Light2D is a dynamic mesh-based 2D lighting solution, casting shadows from any Collider2D in a scene. Light2D also allows for easy implementation of occulusion effects to obscure 'unlit' objects and can even be used for visibility detection with trigger events all objects for entering and exiting the lit area. Use the standard light texture, or any other texture as a light cookie to achieve multiple lighting effects easily.

How to use:
Light2D can be easily added using the GameObject menu under "GameObject->Light2D->Light2D".  Alternatively this can be done by dragging the included Light2D prefab into the Scene view, or by adding a the Light2D.cs script any GameObject. Ensure that any intended shadow-casting object has a Collider2D attached.

Event System:

For advanced applications the light trigger events can be used. These send events to both the light and a GameObject upon it entering or exiting the lit area. For example, Light2D can be used as a vision cone with visibility detection achieved using trigger events.

events
promolargecrop_light2D

Limitations and Notes:

  • Only works in x-y plane.
  • CircleCollider2D must maintain circularity,
  • CircleCollider2D must be above (closer to the camera) the light mesh to ensure no overlap,
  • Overlapping colliders will cause visual artifacting,
  • If shadow casting object has an attached Rigidbody2D, ensure Interpolate is set to None.

Demo Scenes

Overview:

  • Dynamic 2D lighting system
  • Point and Spot light
  • Trigger events
  • Light Cookies
  • Per light optimisation
  • Occlusion effects
  • Visibility algorithm