You are on page 1of 14

Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

Lighting for mobile games with


Unity 
Lighting is one of the most important aspects of a game. It can set the mood, lead the
player, identify threats or objectives, and more. Lighting can make or break the visuals of a
game. For example, good lighting can make a bad model look better in-game, while bad
light can make a great model look worse.

This guide provides information for better lighting performance in a mobile game. How you
decide to use lighting affects the performance of your mobile game. It's important to use
lighting e�ciently to ensure your game performs as smoothly as possible.

Portions of this article are based on work contributed and copyrighted by Arm Limited.
 (https://developer.arm.com/documentation/102109/latest)

Render pipeline options


Unity’s Legacy Render Pipeline includes the following render paths:

• Forward rendering

• Deferred shading

Forward rendering

With forward rendering, real-time lights are very expensive. If you reduce the number of
lights present per pixel, you can offset this cost.

Deferred shading

Deferred shading requires GPU support. On compatible hardware, deferred shading can
render a large number of real-time lights with a high level of lighting �delity. Unfortunately,
deferred shading doesn’t perform well on mobile GPUs because they have lower bandwidth.

When you make a mobile title, it's important that your game runs smoothly on as many
devices as possible.

1 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

Light modes
Different light modes are used based on how a light moves or is used in a Scene. Light
mode types have different performance characteristics. When you implement lights,
consider the following:

• Use baked for static lighting. This is best for objects that don't change their lighting
during runtime. Baking lights is the process of pre-computing and storing lighting data
in texture maps referred to as lightmaps
 (https://docs.unity3d.com/Manual/Lightmapping.html).

• Baked lighting can't be modi�ed at runtime. The light and shadows in the
lightmaps are static. Since all of the lighting was pre-processed in Unity, there
aren’t any runtime lighting calculations impacting performance.

• Dynamic shadows can’t be created with baked light. This might look odd with
dynamic or moving objects.

• Use mixed for stationary lights you intend to interact with moving objects. For
example, a torch that casts light on a player and generates a shadow as the player
moves by.

• Mixed lighting creates dynamic direct light and shadow.

• You can include mixed lighting in lightmap calculations for static objects.

• You can change the intensity at runtime. Only direct light is updated.

• Expensive.

• Use real time for dynamic or movable lights, such as light cast from a �reball that
rises from the ground and explodes.

• Dynamic light and shadow properties can be modi�ed at runtime.

• Real-time lights are not baked into lightmaps.

• Very expensive.

2 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

Lightmap baking
The pre-calculation of the effects of light is known as lightmap baking. The effect of the
light is stored in a separate texture, called a lightmap. The lightmap can be used to augment
the appearance of objects. Lightmap baking only needs to be done once per iteration of
your Scene. If you change the geometry of your Scene, or change the parameters of the
baked lights, you will need to rebake the lightmaps. Except for the overhead of the lightmap
texture, there aren’t any extra performance costs at runtime. This is the best initial approach
to lighting on a mobile platform.

Baked light isn’t affected by any dynamic, or moving, aspects of your Scene. Baked lighting
does include Baked Global Illumination
 (https://docs.unity3d.com/560/Documentation/Manual/GIIntro.html) for all of the static elements.
This means lightmap calculations include indirect light that has bounced off other static
objects as well as the baked lights that strike the object directly.

3 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

Figure 2. The light’s Mode setting in Unity.

Step 2. Make objects static

Make any objects that are affected by the baked lights Static. There are many optimizations
for an object marked as static, but usually it's best to select Everything in the Static drop-
down list. With the object marked as Static, Unity knows to include it in the light baking.

Note: If you have Batching Static enabled, you can’t move or animate objects marked as Static. Leave
this optimization on wherever possible.

4 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

Figure 4. An example of baked lightmaps.

Optimize lightmaps
After lights are set up to be baked, make sure that the baked maps are optimized.
Lightmaps vary in size based on their settings when they're baked. You must keep memory

5 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

Prioritize View is selected, areas in the Scene view are prioritized. This can decrease
the iteration time to set up your Scene’s light.

• Progressive GPU: This works the same as Progressive CPU, but generates the
lightmap on the GPU instead of the CPU. On supported hardware, this method can
greatly reduce baking time compared to using the CPU. There are additional
requirements to set up Progressive GPU. Learn more about the requirements on The

6 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

7 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

8 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

9 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

10 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

11 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

12 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

13 of 14 11/24/2021, 5:24 PM
Lighting for mobile games with Unity | Android Developers https://developer.android.com/games/optimize/lighting-for-mobile-gam...

14 of 14 11/24/2021, 5:24 PM

You might also like