Lighting for 2D projects

Tutorial

Beginner

+0XP

15 mins

Unity Technologies

Lighting for 2D projects

This tutorial guides you through applying your 3D lighting knowledge to 2D Unity projects.

1. Overview

You’ve made lighting for 3D projects, including configuring Directional Lights and skyboxes, adding various Point Lights and Spot Lights, configuring shadows, using Light probes and Reflection probes, and creating emissive materials.

In this tutorial, you’ll explore a 2D scene with similar functionality, and learn how implementing those features would be the same or different.

Indoor 2D lighting scene with a variety of exhibits around the room, including 3 different colored lights shining on images of robots, a trophy, a shining gem, and a table with fruit on top of it.

2. Experience the 2D_Lighting scene

In this step, you'll open the CreativeCore_2D project and then explore the 2D Lighting demo scene within it.

Instructions

To test out and explore the 2D Lighting scene, follow these instructions:

1. Download and open the CreativeCore_2D project:

  • If you’ve already downloaded the CreativeCore_2D project in a previous unit, open it now using the Unity Hub.
  • If you haven’t downloaded it yet, you can download the project here and then open it using the Unity Hub.
  • When the project is open in the Unity Editor, verify you see a CreativeCore_2D folder within your Project window, containing several subfolders.

2. Open the CC_Lighting_2D scene:

  • Go to Assets > CreativeCore_2D > Scenes, then open CC_Lighting_2D_Scene.

3. Enter Play mode and take note of the Lighting elements:

  • Enter Play mode.
  • Notice the following:
    • Dynamic lighting that affects moving objects in the scene.
    • Multiple types, shapes, and colors of light sources.
    • Shadows cast by the player robot.
    • Emissive lighting
  • Exit Play mode when you are done.

3. Explore the 2D vs 3D implementation

When implementing lighting in Unity 2D projects, you'll find both similarities and key differences compared to 3D projects.

For each of the similarities and differences listed below, explore the project to make sure you understand how each of the features were implemented in 2D.

What's the same?

Global and local lighting:

In 3D, a Directional Light provides broad scene illumination, while Point, Spot, and Area Lights affect localized regions. In just the same way, in 2D, a Global Light 2D can set uniform, scene-wide illumination, while localized Light 2D types (Spot, Freeform, and Sprite) are placed to light specific areas.

1. In the Hierarchy window, use the fallout (triangle) to expand the Lighting GameObject, then select the Global Light 2D child GameObject.

2. In the Light 2D component, open the Light Type property dropdown and browse the different light types available.

3. For the Global Light 2D GameObject, adjust the Intensity and Color properties to see the effect these properties have on the overall scene, similar to a Directional Light in a 3D scene.

Global Light 2D GameObject selected, showing its Light 2D component in the Inspector. Its Color is set to blue and its Intensity set to 1.03, making everything in Scene view very bright and blue.

What's different?

Unlit vs Lit shaders:

Lighting in 2D projects is not as common or universally necessary as in 3D projects; it often serves a specific artistic style. Since many 2D projects don’t require lighting, they would use an unlit shader. A sprite with an unlit shader will appear the same brightness regardless of lighting conditions. You need to use a lit shader (such as Sprite-Lit-Default) for lighting to even work.

1. Select the Ground GameObject, and in its Sprite Renderer component, set the Material property to Sprite-Unlit-Default.

2. Try this with other sprites to see the huge impact lighting has on the sprites in this scene.

The Ground GameObject is selected, and in its Sprite Renderer component, its Material is set to Sprite-Unlit-Default. The Ground in the Scene view appears a flat white color.

Light 2D component:

There’s a specific Light 2D component that’s distinct from the 3D Light component. The Light 2D component is designed for 2D lighting calculations.

1. Select any GameObject, and at the bottom of the Inspector window, select Add Component, and search for “Light”.

2. Notice how there’s a Light 2D component, distinct from the normal 3D Light component.

Different light types:

3D projects primarily use Directional, Point, Spot, and Area lights. 2D projects use Global, Spot, Sprite, and Freeform Light 2D types. You can learn more about each of these in Unity's 2D lighting documentation.

1. In the Hierarchy window, use the foldout (triangle) to expand the Lighting GameObject.

2. Select one of the 2D Lights shining along the art along the back wall — these are all Spot lights.

3. In the Light 2D Component, experiment with the following properties:

  • Radius
  • Inner / Outer Spot Angle
  • Falloff Strength

You’ll see that these values allow you to make your 2D lights behave like Point lights or Spot lights you used in the 3D scene.

4. Select the Light 2D_Fruit, which is a Freeform light. Select Edit Shape to configure the shape of the light in the Scene view.

Two different light types selected in the Scene view, showing controls that allow you to edit the radius, inner and outer spot angles, and shape of the lights.

Normal maps disabled by default in lights

While normal maps in 3D appear by default with standard lights, 2D Lights have normal maps disabled by default. You need to change the Quality property from Disabled to either Fast or Accurate within the Light 2D component for normal maps to render.

1. In the Hierarchy window, select the Light 2D_Trophy GameObject.

2. In the Light 2D component, in the Normal Maps section, open the Quality dropdown and explore the options.

The Quality property is set Disabled by default, but you must use either Fast or Accurate for normal maps to render under a 2D light.

3. Try temporarily setting this property to Disabled to see the impact of not having normal maps enabled for the trophy.

Light 2D_Trophy GameObject selected. In the Inspector window, in the Normal Maps section of the Light 2D component, the Quality property is set to Fast.

Shadows

In 3D, objects cast shadows by default if lights are configured correctly. In 2D projects, objects don’t cast a shadow by default. To enable shadows in 2D, you need to add a Shadow Caster 2D component to your GameObjects and then configure the component’s properties to your liking.

1. Select the PlayerRobot GameObject, then locate the Shadow Caster 2D component.

2. Try disabling and enabling this component to see the impact it has on the scene.

PlayerRobot GameObject selected with the Shadow Caster 2D component highlighted in the Inspector window.

No baked lighting:

In 3D, lighting is computationally intensive because of complex geometry, shadows, reflections, and material interactions on 3D surfaces. When you bake lights in 3D scenes, lighting information is precomputed into lightmap textures, which dramatically improves performance with static lighting.

In 2D, rendering is simpler and sprite-based, without complex 3D light interactions. 2D lighting works primarily through sprite color/alpha adjustments. There wouldn’t be as much of a benefit to 3D-style baking in 2D, since real-time 2D lighting is already relatively efficient.

Indoor environment showing baked lighting in the Scene view.

No Light probes or Reflection probes:

Similar to the concept of baked lighting, in 2D, the detailed capture of indirect light and reflections is not as applicable, therefore these probes don’t make as much sense in a 2D context.

Light probe group shown in a 3D scene.


4. Next steps

You now understand how to implement lighting in 3D projects and how that translates to, or differs from, 2D projects. You’re ready to apply these concepts to your own personal projects, be they 3D or 2D.

Complete this Tutorial