Can you make baked lighting with URP 2D lights?

Hello, as you know when creating 2D games unity now uses new lights called Light2D, however the main difference is that it does not have the function of baker/realtime lighting. So I was wondering is there a way to bake 2D lights in URP? (see the image below). If so how?

8254548--1080339--image_2022-07-05_112313007.png

There’s no way to do this at the moment and I haven’t seen it proposed/discussed as a future feature.

But you could do something similar manually. Ultimately 2D lights output into a texture. Your shaders/materials make use of this texture (or textures).

To replicate, I can imagine a few approaches.

  1. Copy the Light Texture(s) - which are a RenderTexture - using Texture2D.ReadPixels into Texture2D and save as an asset. Repeat for all areas of the scene. Your materials would need to be supplied with the visible baked lighting textures and sample them in such a way to correctly show the correct one without seams.
  2. Create a tool to paint onto a texture and shaders to sample at the correct position for the object’s position within the scene. If you look at the Asset Store, there may even be an asset that already does something this… Light Painter 2D? Not a 100% match but seemingly similar.
  3. If your lights are static within a scene and your camera doesn’t move or moves infrequently, perhaps you could modify the 2D Renderer to only generate the light texture when dirty. That way, most of the time you’re reusing the same texture.

None of these sound a walk in the park, so unless you’re having serious performance problems and are relatively sure this would improve things I wouldn’t bother looking into it.

This is a lot to proccess… But thank you for the answer! I will most probably skip as the issues are not that bad to require this much, however still I will try this in my time, to get to know 2D lights.

If you search your Project “In Packages” for “Renderer2D.cs” and look at the stuff in that file’s folder that should get you started.