Unity 2D light with Universal render pipeline

Unity has been always been a 3D first game engine. Now they are trying very hard to make 2D game development as good as 3D. 2D lights in unity are definitely a step in the positive direction. Unity has introduced 2D lights as part of Universal Renderpipeline in 2021. In the earlier versions of Unity, 2D lights were a beta feature included in Lightweight Renderpipeline. In this post, we will see how to include 2D lights in your project and make the most of them.

What is 2D lighting

When you need a particular part of your 2D scene to be lit the only option available in the previous versions of Unity was shader. You have to edit or make a new shader to optimize your 2D lightings. Shaders are confusing for new developers and also artists trying to make a game.

So, Unity decided to bring in 2D lights that help you create different shapes of lights and shadows inside your 2D scene without coding. Let’s see how you can make your 2D game more beautiful with 2D lights.

How to make 2D lights in Unity

2D lights in Unity use Universal Renderpipeline. You need to enable URP before you can use 2D lights.

What is URP

Universal Render pipeline has been introduced by Unity to make common graphics that can be used for all devices. You can enable URP and make your game without worrying about the graphics performance in other platforms.

URP is not compatible with projects made with HDRP or build in Render pipeline. You need to decide which render pipeline you are going to use for your game.

URP is supported in Unity 2019.3.0f3 or higher versions only.

Setting up URP and 2D renderer

There are two ways to set up URP in Unity. You can select URP while starting a new project or you can go inside and add the URP package using package manager.

Method 1

new project with URP

Method 2:

Install URP using package manager

Create a 2D renderer and URP asset

After installing URP using any one of the methods above, you need to create a URP asset and a 2D rendered asset.

Create URP Asset

create URP asset in Unity

Create 2D renderer asset

Create a 2D renderer asset

Select the URP asset and click general settings in the inspector. Then drag and drop the 2D renderer asset into the Renderer list.

Go to Edit>Project settings

Select graphics from the left tab. Drag and drop the URP asset onto the Scriptable Render pipeline settings.

You need to upgrade all your materials to URP. Go can do that with a simple click as shown in the image below.

upgrade material to URP

That’s it you have configured your project for using URP.

Types of 2D lights in Unity

Once URP is enabled along with the 2D renderer. You must see four new types of lights in your light menu in the hierarchy window.

  1. Freeform Light2D- You can change the shape of light as you want it.
  2. Sprite Light2D- Light a particular sprite irrespective of the environment.
  3. Spot Light2D- Illuminate a particular spot.
  4. Global Light2D- Light up the whole area.

Adding 2D lights to Unity scene

Now that everything is setup, this part is very easy. Just go to Hierarchy and click on the add symbol.

Light>select any 2D light of your choice.

Important Properties of 2D lights in Unity

  1. Color
  2. Intensity
  3. Target sorting layer
  4. Normal map settings

While using the normal map settings you can set the distance of light from the object. Note that this setting does not transform the actual position of the light.

Play around with the other settings and have fun with 2D lights. If you have any other query on 2D lights, feel free to comment below.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.