Optimize light maps

After you have configured lights to be baked, you should also make sure that the baked maps are optimized

Light maps vary in size depending on the settings they are baked with. We must minimize memory usage on mobile platforms, so lightmap size needs monitoring. In the example image, you can see that there are seven 1024x1024 pixel lightmaps.

Baked lightmaps

In the preview of the map, you can see meshes laid on it, and selected meshes are highlighted.

Some settings in Lightmapping, and the size of the actual maps, determine how much space is used.

The most important settings are described in the following sections.

Light mappers

Light mappers in Unity offer three different methods to bake the lights in your scene:

  • Enlighten
  • Progressive CPU
  • Progressive GPU

The following image shows this option.

Prioritise view

In Unity, you should use one of the progressive options for any new work. The progressive light mappers offer a large time saving benefit because they incrementally create light maps. If the Prioritize View option is selected, areas that are in the scene view are prioritized. Prioritize view speeds up iteration times setting up your lighting for your scene.

The major difference between the CPU and GPU progressive light mappers is whether lightmap generation is in the CPU or in the GPU. The results of the two options are the same, but if you have a powerful GPU that option is much faster. More requirements and set up steps for the GPU option, which can be found here

Texels 

A texel, or texture element, is the individual pixel in a texture map. Texels are used, for example, to store lighting information at each point where a light hits an object in a lightmap. We can measure the amount of work that is needed to bake in a light by counting the number of texels that are used. It is important to understand what a texel is, and how your control over them can influence the quality of your lighting, computation time for the bake, disk storage costs, and the VRAM cost of your lightmaps.

For the biggest impact on the amount of lightmap data that is required, you must adjust the number of texels for each unit of the bake. This can be done in the Lightmapping Settings. These settings give you control over the lightmaps, including how many texels each object uses in the bake as shown in the example image. 

Scene settings

Lightmapping Settings includes an option called Lightmap Resolution. This option sets how many texels are used for each unit in the lightmaps.

You can see how texels are laid out in your scene in the following ways:

  • Click the draw mode drop down on the Scene view.
  • Find and then click Lightmap Indices.

Bake objects will now be covered in a checkerboard overlay. This is how your texels are distributed when you bake the lights.

In the following screenshot, you can see an example of a cube with different Lightmap Resolution settings. The left-hand image has a setting of one, the middle image has a setting of two, and the right-hand image has a setting of five.

Cubes

You can see how a higher resolution quickly increases the amount of work that is needed. We recommend that you start with a low Lightmap Resolution, between five and ten, and scale up or down based on what your scene needs. Increasing the lightmap resolution causes the size to go up massively with each iteration.

For example, reducing the Lightmap Resolution from 15 to 12 in the example demo reduces the number of lightmaps that are needed from seven to four as shown in the proceeding image.

Features of cubes

Texel usage 

In the Lightmapping Settings, you set the number of texels that your scene uses per unit, but there are some objects that you do not want to use that many texels on.

Unity allows you to control how many texels each object can use. The Inspector>Mesh Renderer for an object includes a parameter called Scale In Lightmap. You can adjust Scale In Lightmap to change the amount of texels that this object uses in your lightmap.

In the following screenshot, on the left-hand side is an average object getting five texels of lighting information for each baking unit, because Lightmap Resolution is set to five. On the right-hand side is a box with Scale In Lightmap set to 0.5:

Cube difference

The right-hand box will use much less space in the lightmap than the left-hand box. In the proceeding screenshot you can see the settings for lightmaps.

Lightmap static

Try to avoid spending texels on the following elements: 

  • Surfaces and objects that a player will not see. This avoids wasting memory on a larger lightmap for detail that is not seen on screen.
  • Surfaces with little light variation on them, for example an object in a shadow, or an object that is only touched by a single light. 
  • Small or thin objects. The amount of lighting that small or thin objects receive does not add much to the final render of the scene. 
Previous Next