Overview

Unity’s Universal Render Pipeline (URP) has a separate lighting system for 2D games. Instead of the Directional, Point and Spot Light components used in 3D, you add Light 2D components, and the 2D Renderer uses them to light sprites, tilemaps and Sprite Shapes. Unity’s manual describes the aim as letting you “add 2D lights to scenes to light 2D GameObjects such as sprites, tilemaps, and sprite shapes”, and states plainly that “2D lighting is not physically-based, unlike 3D lighting” (Unity Technologies, Unity Manual 6000.3: Introduction to 2D lighting in URP).

In outline, Unity renders 2D lighting in three stages: it draws shadow shapes into textures, draws the light shapes and colours into light textures, and then draws the lit sprites by combining each sprite’s colour with those light textures (Unity Technologies, Introduction to 2D lighting in URP). Three consequences of this design explain most beginner problems:

  • lighting is organised by sorting layer, not by distance or depth;
  • a sprite only reacts to lights if its material samples the light textures;
  • light quality and cost depend on the size and number of those light textures, not on the number of polygons.

This page covers set-up, the four light types, materials, blend styles, normal maps, shadows, performance, pixel-art considerations and common problems. For lighting as a design tool (mood, contrast, guiding the player) see lighting-for-mood-and-guidance; for 3D projects see unity-lighting-for-3d-scenes.


Setup

Start from the Universal 2D template (simplest)

Create a new project from the Universal 2D template in the Unity Hub. In Unity 6000.3 this template already contains a URP Asset whose renderer is a Renderer 2D asset (Assets/Settings/Renderer2D.asset), and its SampleScene already contains a Global Light 2D at intensity 1 (checked against the template package shipped with Unity 6000.3.11f1). New sprites use the Sprite-Lit-Default material, so they are ready to be lit.

Adding the 2D Renderer to an existing URP project

  1. In the Project window choose Create > Rendering > URP Asset (with 2D Renderer). This creates a URP Asset and a matching Renderer 2D asset. (Create > Rendering > URP 2D Renderer creates the renderer asset on its own.) These menu names are taken from the URP 17.3 package source.
  2. Assign the new URP Asset in Edit > Project Settings > Graphics and in each quality level under Project Settings > Quality, or add the Renderer 2D asset to your existing URP Asset’s Renderer List and select it on the camera.
  3. If a Light 2D’s Inspector shows “2D renderer data must be assigned to your universal render pipeline asset or camera”, the camera is still using a 3D (Universal) renderer.

Projects that started on the Built-in Render Pipeline may have sprites still using the old Sprites-Default material, which 2D lights ignore. Reassign Sprite-Lit-Default, or try the URP 2D converters under Window > Rendering > Render Pipeline Converter (the converter path is named in the Light 2D Inspector’s own upgrade message; its coverage of materials is not checked here).

The Renderer 2D asset

The Renderer 2D asset holds the project-wide 2D lighting settings (Unity Technologies, Unity Manual 6000.3: Renderer 2D asset reference for URP):

SettingWhat it doesNotes
Transparency Sort ModeHow sprites on the same sorting layer and order are sortedDefault, Perspective (suits isometric), Orthographic (suits top-down) or Custom Axis, which sorts along the Transparency Sort Axis
HDR Emulation ScaleLets lights exceed full brightness on platforms without HDRSet roughly to the combined maximum brightness of your lights; lower it if colour banding appears
Default Material TypeLit (Sprite-Lit-Default), Unlit (Sprite-Unlit-Default) or CustomApplies to new objects only; it does not change existing sprites
Light Blend StylesUp to four named ways of applying light (see below)Every new light uses the first style
Render ScaleResolution of the light textures as a fraction of the screenDefault 0.5
Max Light Render TexturesHow many light textures can exist at onceThe manual lists a default of 4; the 6000.3 Universal 2D template ships with 16
Max Shadow Render TexturesHow many shadow textures can exist at onceDefault 1
Depth/Stencil BufferNeeded for features such as Sprite MasksTurning it off can help mobile performance if you do not need them

Usage

The four Light 2D types

Add lights from GameObject > Light (the menu items are Spot Light 2D, Freeform Light 2D, Sprite Light 2D and Global Light 2D) or add the Light 2D component and set Light Type (Unity Technologies, Unity Manual 6000.3: Light 2D component reference for URP):

Inspector nameWhat it doesTypical use
SpotEmits light from a point, full strength inside the inner Radius and fading to zero at the outer one; inner/outer Spot Angle narrow it to a cone. At the full 360° it acts as a point lightTorches, lamps, the player’s lantern, cones of vision
FreeformEmits light in an editable polygon, with a Falloff distance around the edgeLight from a window, a glowing pool, light filling a room shape
SpriteUses a sprite as the light’s shape (a “cookie”)Stylised god rays, patterned light, glows that match the art style
GlobalLights all 2D objects on its target sorting layers equally, with no falloffAmbient light, time of day, overall mood

Name change: the type shown as Spot in the Inspector was called Point in earlier URP versions, and the scripting API still calls it Light2D.LightType.Point; its radius is set through pointLightOuterRadius and pointLightInnerRadius. An older Parametric type is deprecated and should be upgraded to Freeform (URP 17.3 package source, Light2D.cs and Light2DEditor.cs).

One Global Light per blend style per sorting layer. Unity only allows one Global Light 2D per blend style and sorting layer (Unity Technologies, Introduction to 2D lighting in URP); a second one logs an error in the Console. To change ambient light over time, animate the one Global Light instead of adding more.

Key properties shared by all types: Color, Intensity, Target Sorting Layers, Blend Style, Light Order, Overlap Operation, plus foldouts for Shadows, Volumetric (an extra additive glow drawn on top of the light) and Normal Maps.

Materials: lit or unlit

Only materials whose shader reads the 2D light textures react to Light 2D. Sprites and tiles use Sprite-Lit-Default by default, “which is already compatible with 2D lights” (Unity Technologies, Unity Manual 6000.3: Make a GameObject compatible with 2D lights in URP). Sprite-Unlit-Default ignores 2D lights entirely, which is useful for UI-like world elements, glowing pickups or anything that must stay readable in the dark (Unity Technologies, Renderer 2D asset reference for URP).

For custom looks, a Sprite Lit Shader Graph (Shader Graph’s URP targets) can also respond to 2D lights, and Visual Effect Graph particles can be lit by using an Output Particle Shader Graph Quad with the VFXSpriteLit shader (Unity Technologies, Make a GameObject compatible with 2D lights in URP). See shader-graph-overview.

Target Sorting Layers

Each light has Target Sorting Layers, which decide which sorting layers it affects. This is the 2D equivalent of light layers, and it is the main tool for artistic control: you can let a torch light the walls and characters but not the far background, or give the background its own dimmer Global Light. Unity’s tooltip advises keeping this list short: “To optimize performance, minimize the number of layers this light affects” (URP 17.3 package source, Light2DEditor.cs). Shadow Caster 2D components have their own Target Sorting Layers too.

Light blend styles

A blend style controls how a light’s colour is combined with the sprites it touches. The Renderer 2D asset defines up to four; a new asset names them Multiply, Additive, Multiply with Mask and Additive with Mask (URP 17.3 package source, Renderer2DDataAuthoring.cs). Each style has a Blend Mode (Additive, Multiply or Subtractive) and an optional Mask Texture Channel that restricts the light to pixels where a sprite’s mask texture has a value in that channel (Unity Technologies, Renderer 2D asset reference for URP).

  • Multiply darkens or tints: sprite colour × light colour. Unlit areas become dark. This is the normal choice.
  • Additive adds light on top, which can push colours brighter and suits glows, magic and emissive effects.
  • Mask styles, used with a _MaskTex secondary texture (below), let you light only parts of a sprite, such as the metal of a sword but not the handle.

When lights overlap they add together by default; set Overlap Operation to Alpha Blend to let one light cover another, with Light Order deciding which is in front (Unity Technologies, Unity Manual 6000.3: Blend 2D lights). Each blend style in use creates its own light texture, so Unity recommends using “only one or two different blend styles in a scene” (Unity Technologies, Unity Manual 6000.3: Optimize 2D lights with batching in URP).

Normal maps and mask maps (secondary textures)

Flat sprites can respond to the direction of a light if you give them a normal map. Sprites carry extra textures as secondary textures (Unity Technologies, Unity Manual 6000.3: Add a normal map or a mask map to a sprite in URP):

  1. Keep the sprite on a material that supports these maps, such as Sprite-Lit-Default.
  2. Select the sprite’s texture, open the Sprite Editor, and choose Secondary Textures from the drop-down.
  3. Click +, set Name to _NormalMap (or _MaskTex for a mask), assign the texture and click Apply.
  4. On each light that should use it, open Normal Maps and set Quality to Fast or Accurate (the default is Disabled). Without this the normal map has no effect. Distance sets the distance between the light and the lit sprite for the calculation, without moving the light (Unity Technologies, Light 2D component reference for URP).

Normal maps for pixel art are usually hand-painted or generated from the sprite with a separate tool; they must match the sprite’s dimensions and slicing exactly. Mask maps only take effect with a “with Mask” blend style.

Shadows

  1. Tick the Shadows checkbox on the light and set Strength (0 to 1) for how much light casters block; Softness and Falloff Strength shape the edge (Unity Technologies, Light 2D component reference for URP).
  2. Add Component > Rendering > 2D > Shadow Caster 2D to each object that should block light (Unity Technologies, Unity Manual 6000.3: Add shadows from 2D lights in URP).

The Shadow Caster 2D’s Casting Source decides the shape (Unity Technologies, Unity Manual 6000.3: Shadow Caster 2D component reference):

Casting SourceShape used
Sprite RendererThe sprite’s outline from the Sprite Editor (Custom Outline, or the Skinning Editor shape if a Sprite Skin is present). Trim Edge (default 0.2) shrinks it and Alpha Cutoff (default 0.1) sets which pixels count as solid
Collider 2DThe shape of a 2D collider on the same object; only offered when one is present
Shape EditorA polygon you draw with Edit Shape
Sprite SkinThe bounding box of the bones in a Sprite Skin component; only offered when one is present
NoneNo shadow

Casting Option sets where the shadow falls: Cast Shadow (onto other objects, the default), Self Shadow, Cast and Self Shadow, or None.

To merge many casters into one shadow (for example a wall built from separate blocks), add a Composite Shadow Caster 2D to an empty parent and make the casters its children: “If the child GameObjects have Shadow Caster 2D components, their shadows are merged” (Unity Technologies, Add shadows from 2D lights in URP).

Tilemaps (tentative). Unity’s 2D shadow pages do not describe tilemap shadows. In URP 17.3 the Collider 2D casting source reads the collider’s physics shapes through Collider2D.GetShapes, which works for any collider type, so a Tilemap with a Tilemap Collider 2D (optionally merged by a Composite Collider 2D) and a Shadow Caster 2D set to Collider 2D should cast shadows from its collision shape. This is inferred from the package source rather than documented, so test it in your Unity version before relying on it. Older tutorials that generate one Shadow Caster 2D per tile from a script date from before this option existed.

Driving lights from code

Light2D lives in the URP package, so scripts need using UnityEngine.Rendering.Universal;. A smooth torch flicker samples Perlin noise each frame:

using UnityEngine;
using UnityEngine.Rendering.Universal;
 
[RequireComponent(typeof(Light2D))]
public class SimpleFlicker2D : MonoBehaviour
{
    [SerializeField] private float baseIntensity = 1.2f;
    [SerializeField] private float variation = 0.3f;
    [SerializeField] private float speed = 4f;
    private Light2D light2D;
    private float offset;
 
    private void Awake()
    {
        light2D = GetComponent<Light2D>();
        offset = Random.Range(0f, 1000f); // each torch flickers differently
    }
 
    private void Update()
    {
        float n = Mathf.PerlinNoise(Time.time * speed + offset, 0f) * 2f - 1f;
        light2D.intensity = Mathf.Max(0f, baseIntensity + n * variation);
    }
}

Mathf.PerlinNoise changes smoothly, so the flame wavers; Random.Range every frame strobes instead. A day-night cycle works the same way on the Global Light 2D, setting color from a Gradient and intensity from an AnimationCurve.

Runnable versions with set-up notes are in code/unity-csharp/2d-lighting/: TorchFlicker2D.cs also varies pointLightOuterRadius, and DayNightCycle2D.cs drives the Global Light and switches night lights on after dusk. The folder’s README gives the scene set-up.

Pixel-art considerations

Pixel art adds two concerns: lights should not look smoother than the art, and the art’s palette should survive lighting.

  • Resolution of the lighting. Light textures are drawn at the Renderer 2D asset’s Render Scale (0.5 by default) of the camera target. When a unity-pixel-perfect-camera uses Upscale Render Texture, URP 17.3 sizes that camera target to the Pixel Perfect Camera’s low-resolution render texture, so lighting is calculated at roughly the game’s reference resolution and its gradients come out as visible pixel steps (URP 17.3 package source, Renderer2DRendergraph.cs). With Pixel Snapping, lights are drawn at screen resolution, so falloffs are smooth gradients across chunky sprites. Which looks better is a style decision; this suggests choosing Upscale Render Texture if you want light to read as part of the pixel art.
  • Keep falloffs short or stepped. Long soft falloffs across a 16-pixel tile can look out of place. Some pixel-art games use Sprite lights drawn in the same style as the art, or a custom Shader Graph that posterises the light into a few bands; both are artistic options rather than Unity defaults.
  • Palette. Multiply lighting tints every colour, so a carefully limited palette will gain in-between colours. Arguably this is acceptable for mood lighting but worth testing on key sprites; pixel-art-fundamentals covers why palette control matters.
  • Import settings still apply. Normal maps and mask maps for pixel sprites need the same Point filtering, no compression and Pixels Per Unit as the sprite itself (unity-pixel-art-pipeline).

How 2D lighting differs from 3D URP lighting

2D lighting (2D Renderer)3D lighting (Universal Renderer)
ComponentsLight 2D: Spot, Freeform, Sprite, GlobalLight: Directional, Point, Spot, Area
ModelNot physically based; light textures blended with sprite colourPhysically based shading with the URP Lit shader
What it affectsObjects on the light’s Target Sorting Layers with a 2D-lit materialObjects within range and on the light’s rendering layers
Ambient lightOne Global Light 2D per blend style and sorting layerEnvironment lighting, light probes, reflection probes
BakingNo lightmaps; all 2D lights are real-timeReal-time, mixed or baked (lightmaps, probes)
ShadowsShadow Caster 2D shapes projected in 2DShadow maps from 3D geometry

The 2D Renderer only gathers Light 2D components; ordinary 3D Light components do not light sprites under it (URP 17.3 package source). 3D meshes can appear in a 2D Renderer scene and receive 2D light “by using a compatible shader” (Unity Technologies, Unity Manual 6000.3: 3D GameObjects in 2D URP scenes). For the 3D workflow see unity-lighting-for-3d-scenes and unity-urp-lighting-and-render-features.


Performance

Unity’s guidance focuses on light textures and batching (Unity Technologies, Optimize 2D lights with batching in URP):

  • Use one or two blend styles. Each blend style in use creates another light texture.
  • Keep Target Sorting Layers consistent. Sorting layers can only be batched together when they receive exactly the same lights. Open Window > 2D > Light Batching Debugger to see the batches and which lights split them, then align the lights’ (and shadow casters’) Target Sorting Layers.
  • Lower Render Scale to shrink light textures if lighting is soft anyway; raise Max Light Render Textures if many sorting layers each have their own lights, at the cost of memory.
  • Shadows cost extra passes. Enable shadows only on lights that need them, and merge neighbouring casters with a Composite Shadow Caster 2D.
  • Measure, do not guess. Check frame time in the unity-profiler before and after adding lights.

Gotchas

  • Everything went black when I added a light. With no Light 2D in the scene, lit sprites draw at their full colour. Once any Light 2D exists, a lit sprite that receives no light is multiplied by black (URP 17.3 package source, DrawRenderer2DPass.cs and CombinedShapeLightShared.hlsl). Add a Global Light 2D (intensity around 0.2 to 0.5 for night scenes) as base light.
  • One layer is black, the rest are fine. No light targets that sorting layer. Add the layer to a light’s Target Sorting Layers, usually the Global Light’s.
  • A sprite ignores every light. Its material is Sprite-Unlit-Default, a Built-in Sprites-Default, or a custom unlit shader. Switch it to Sprite-Lit-Default. Remember that changing Default Material Type on the Renderer 2D asset only affects new objects.
  • Lights have no effect at all. The camera is not using the 2D Renderer; the Light 2D Inspector shows a warning when this is the case.
  • Lit in the Game view but flat in the Scene view. The Scene view’s lighting toggle is off.
  • “More than one global light” error. Two Global Light 2Ds share a blend style and sorting layer.
  • Normal map does nothing. The light’s Normal Maps > Quality is still Disabled, or the secondary texture is not named exactly _NormalMap.
  • Shadows do not appear. Shadows are off on the light, or the receiving sprite’s sorting layer is not in the Shadow Caster 2D’s Target Sorting Layers.
  • Script will not compile. Light2D needs using UnityEngine.Rendering.Universal;, and the light type in code is Light2D.LightType.Point even though the Inspector says Spot.

Practice

Light a small night scene. Start from the Universal 2D template, or a scene already on the 2D Renderer, with a few sprites or a Tilemap on at least two sorting layers (for example Background and Default).

  • set the Global Light 2D to a dark blue at about 0.25 intensity
  • add a Spot Light 2D torch with a warm colour and make it flicker using Perlin noise (write your own or use TorchFlicker2D.cs from the code folder)
  • give one crate or wall sprite a Shadow Caster 2D and enable shadows on the torch
  • make one pickup sprite use Sprite-Unlit-Default so it stays readable in the dark

Success test:

  • the scene is dark but nothing is pure black, on every sorting layer
  • the torch brightens nearby sprites and its flicker wavers smoothly rather than strobing
  • the crate casts a visible shadow away from the torch
  • the unlit pickup keeps its full colour wherever it is placed
  • the Light Batching Debugger shows which sorting layers are batched together, and you can explain why

Extension:

  • add DayNightCycle2D.cs so the Global Light cycles over 60 seconds and the torch switches on only at night; then try the scene behind a Pixel Perfect Camera with Upscale Render Texture and compare the look of the torch falloff

Self-test

  1. Which two things must be true for a sprite to react to a Light 2D?
  2. Why can adding your first Spot Light 2D make the rest of the scene go black, and what is the usual fix?
  3. What does a light’s Target Sorting Layers setting control?
  4. What is the Inspector’s Spot light called in the scripting API?
  5. Name the two steps needed before a normal map changes how a sprite is lit.
  6. Give one performance reason to use only one or two light blend styles.

Answers

  1. The camera must use the 2D Renderer, and the sprite’s material must use a 2D-light-compatible shader such as Sprite-Lit-Default (not Sprite-Unlit-Default).
  2. Once any Light 2D exists, lit sprites that receive no light are multiplied by black. Add a Global Light 2D, at low intensity if you want a dark scene, so every layer has base light.
  3. Which sorting layers the light affects; sprites on other layers ignore it.
  4. Light2D.LightType.Point, with its size set through pointLightOuterRadius and pointLightInnerRadius.
  5. Add the normal map to the sprite as a secondary texture named _NormalMap in the Sprite Editor, and set the light’s Normal Maps > Quality to Fast or Accurate.
  6. Each blend style in use creates its own light render texture, so more styles mean more textures to draw and more memory.