Skip to main content

2D lights

Sprites and tilemaps normally show their pictures as they are. Add a Light 2D to a scene and they are lit instead, as with Unity's 2D renderer:

  • a dark cave lit by torches;
  • a night street under lamps;
  • a spotlight sweeping a prison yard.

A cave room: a dim blue Global light, two torches and a cone from the ceiling, with shadows

Add a light​

+ Add → Lights:

  • Global Light 2D lights everything the same. Use one, dim and a little blue, so the dark parts of a level stay visible.
  • Spot Light 2D lights a circle round itself, or a cone. Put one on each torch, lamp or window.
  • Freeform Light 2D lights a shape you draw: a shaft of light from a window, a lit doorway, a pool of light on a floor.
  • Sprite Light 2D lights with a picture: the panes of a window, a stained-glass pattern, a flashlight's ring.

As soon as a scene has a Light 2D, its sprites and tilemaps show only the light of its 2D lights: where no light reaches is black. Lights add up, so two torches side by side make a brighter patch.

3D meshes, particles and UI are not affected: 3D meshes keep using the 3D lights.

Light 2D settings​

SettingWhat it does
Light TypeGlobal: the whole scene. Spot: round the object (Unity's name for the round light). Freeform: a shape. Sprite: a picture.
Color, IntensityThe light's colour and how strong it is. Above 1 makes things brighter than their picture.
Inner RadiusFull light out to here (metres).
Outer RadiusNo light from here on. Between the two, the light fades out.
Inner Angle, Outer Angle360 = all round. Lower makes a cone: full light inside the inner angle, fading out to the outer one. The cone points along the object's up: turn the object (rotation Z) to aim it, 180 points down.
Falloff StrengthHow quickly the light fades between the radii: 0 stays bright to the edge, 1 fades fast.
Shadows, Shadow StrengthShadow Caster 2D objects block the light (see below). At 1 none of this light gets into the shadow; at 0.5 half does.
Shadow Softness0 = sharp shadow edges. Higher makes the light act as if it had a size, so shadow edges blur, more the farther they are from what casts them.
Normal Maps, DistanceShade sprites, tilemaps and Sprite Shapes that have a normal map by which way their bumps face (see below). Distance is how high above them the light is: low lights show bumps more.
Volumetric IntensityThe light also shows in the air, over everything: the haze round a torch, the beam of a lamp, a shaft of moonlight (Freeform) or a window's glow (Sprite). 0 = off. Not for Global lights.

The Ceiling light selected: its cone (outer and inner) is drawn in the 2D view

Freeform lights​

The Moon shaft selected: its four points and the end of its soft rim, drawn in the 2D view

A Freeform light is a shape of full light with a soft rim round it. Select it to see its points in the 2D view: drag a point to move it, double-tap the outline to add one, select a point and press Delete to remove it. The numbers are in the Light 2D card too (+ Point adds one).

  • Falloff is how wide the soft rim is, in metres.
  • Falloff Strength is how quickly the light fades across the rim.

Sprite lights​

A Sprite light is a picture of light: pick its Sprite (any picture) and its Size (the longer side, in metres). Its colours tint the light and its transparent parts give none. Turn the object to turn the picture.

In the scene view each Spot light shows its outer reach (and its inner one, fainter) as a circle or a cone. The view draws the lights while you edit, so you see the scene as it will look.

Shadows​

  1. Add a Shadow Caster 2D component to the objects that block light: walls, pillars, crates, the level's tilemap.
  2. Switch on Shadows on the lights that should cast them.

A caster's shape is its collider's shape. For a tilemap that is its solid tiles; for a sprite, its collision polygon; for a shape, its box, circle or capsule. It doesn't need a collider, though: without one, the shape is what the collider would be.

Self Shadows (off by default): off, the light still reaches the caster itself and only what is behind it is dark, so a wall stays lit on the side facing the torch. On, the caster is in its own shadow too.

Shadows are sharp by default. Shadow Softness blurs their edges: the light is drawn several times, each casting its shadows from a different point of a small disc, so the edges fade the farther they are from the caster. Each of those draws costs a little, so keep softness for the lights that need it.

Freeform and Sprite lights cast shadows from their object's position.

Normal maps​

Bricks with a normal map lit from the low left: their edges catch the lamp, the pillars cast soft shadows, a Freeform shaft and a Sprite light window

A normal map is a second picture that tells, for each pixel, which way the surface faces. With one, a flat sprite of bricks shows its bevels lit on the side facing the lamp and dark on the other side, and the light moves over them as the lamp moves.

  1. Give the picture a Normal map: a second picture laid out like it, in the usual colours (blue-ish: red = right, green = up, blue = out of the picture). Paint tools and normal-map makers export these.
    • Sprite: Normal map in its card, under Render texture (the same frames as the sprite).
    • Tilemap: Normal map in its card, laid out like the tile sheet (the same tiles in the same places).
    • Sprite Shape: Fill normal map for the fill picture, and a Normal map in each edge range. The edges bend along the outline, and so do their bumps.
  2. Switch on Normal Maps on the lights that should use them. Distance is how high above the pictures the light is.

Pictures without a normal map, Unlit ones, and lights with Normal Maps off are lit as before. Global lights don't use normal maps.

The Ember Crypt showcase is a whole game lit this way: a lantern with Normal Maps over brick, stone and a rubble Sprite Shape.

A cave wall and stone pillars (one tilemap) and a grassy Sprite Shape hill, each with a normal map, lit low by a torch; a Freeform moonlight shaft with Volumetric glow

Unlit sprites and tilemaps​

Some things should show as they are whatever the light: a glowing coin, a lit window, a sky backdrop. Set the Sprite's or Tilemap's Material to Unlit (Unity's Sprite-Unlit-Default). Lit is the default.

In events and scripts​

The settings can change while the game runs: a flickering torch, a lamp that switches off, a light that follows the hero.

  • Events: Set component setting on the light's object (for example light2d → intensity). Moving the object moves its light.
  • Scripts: entity.component("light2d").intensity = 0.8 + Math.random() * 0.4. An object's Enabled switch turns its light on and off.

Good to know​

  • 2D lights work in the X–Y plane, which is how a side-on or top-down 2D game is laid out (see 2D games).
  • The light is worked out per pixel of the screen. Anything drawn where a shadow falls is darkened, even a sprite standing in front of the wall that casts it. Set things that must stay bright to Unlit.
  • Each light with shadows is one more drawing pass a frame. A dozen torches are fine on a phone; hundreds are not.
  • Exported games, the Android app and desktop builds draw 2D lights the same way.