How do you bake light maps in 2D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BrickBreaker

I am developing a 2D game for mobile/browser and want to add lights but they cause a significant amount of lag, is there any way to “bake” 2D lights or something similar?

Note that Godot 3.2.2 is no longer supported: Godot release policy — Godot Engine (stable) documentation in English

Calinou | 2021-11-12 23:05

:bust_in_silhouette: Reply From: Calinou

First, to improve 2D lighting performance, try increasing the Scissor Area Threshold project setting above its default value (0.0).

Unlike 3D, there is no built-in way to bake lightmaps in 2D. There would be two ways to approach this from an editor plugin side:

  • Bake a texture that is overlaid with a CanvasItemMaterial set to the Multiply Blend mode.
  • Use Sprites with Add blend mode to represent light. If you don’t need shadows, it’s all you have to do. If you need shadows, you could have a plugin that creates Polygon2Ds depending on surrounding light occluders and renders them to a viewport which is modulated with a black transparent color.

Both of those approaches involve a significant amount of work when you need shadows.

Godot 4.0 will use a single-pass approach to 2D lighting, which is much faster when you use several lights that affect the same sprite.