Version: Unity 6.0 (6000.0)
Language : English
Smooth hard edges in lightmaps
Optimize baking

Fix light bleeding in lightmaps

Each lightmapA pre-rendered texture that contains the effects of light sources on static objects in the scene. Lightmaps are overlaid on top of scene geometry to create the effect of lighting. More info
See in Glossary
texture contains a number of UV chartsIndividual unwrapped section within a UV layout. UV charts are contiguous islands of faces that share a continuous mapping. Their placement determines seams, distortion, and packing efficiency. Also known as a UV island.
See in Glossary
. At runtime, Unity maps these UV charts onto meshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary
faces, and uses the charts’ lighting data to calculate the final appearance. Because of the way GPU sampling works, data from one UV chart can bleed onto another if they are too close to each other. This usually leads to unintended artifacts such as aliasing, pixelation, and so on.

Example of graphical artifacts due to chart bleeding
Example of graphical artifacts due to chart bleeding

To avoid light bleeding, there must be a sufficient amount of margin between UV charts. When a GPU samples a lightmap texture, the lighting system calculates the final sample value from the four texels closest to the sampled point (assuming bilinear filtering is used). These four texels are called the bilinear “neighborhood” of the sampled point. UV charts are too close together if they overlap — that is, if the neighborhood of any point inside a chart overlaps with the neighborhood of any point in another chart. In the image below, the white pixelsThe smallest unit in a computer image. Pixel size depends on your screen resolution. Pixel lighting is calculated at every screen pixel. More info
See in Glossary
indicate chart neighborhoods, and red pixels indicate overlapping neighborhoods.

Red pixels indicate overlapping chart neighbourhoods
Red pixels indicate overlapping chart neighbourhoods

Determining optimal UV chart placement and spacing can be difficult, because it depends on several parameters (such as lightmap resolution, the mesh’s UV layout, and Model Importer settings). For this reason, Unity provides the ability to identify these issues easily, as outlined in the following section.

Identification

There are three ways to identify overlaps:

  • Keep an eye on Unity’s console. If Unity detects overlapping UVs, it prints a warning message with a list of affected GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
    See in Glossary
    .

  • Use the UV Overlap draw mode in the SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
    See in Glossary
    View (see GI visualizations in the Scene View for more information). When you have this mode enabled, Unity adds a red highlight to texels in UV charts that are too close to texels of other charts. This is especially useful if you discover an artifact in the Scene ViewAn interactive view into the world you are creating. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. More info
    See in Glossary
    , and want to quickly examine whether UV overlap is causing it.

Scene View using UV Overlap draw mode (see dropdown in top left)
Scene View using UV Overlap draw mode (see dropdown in top left)
  • Use Baked Lightmaps Preview. Select a GameObject and go to the Lighting window and then choose the Baked Lightmaps tab. Double-click the highlighted lightmap texture, navigate to the Preview window, and select Baked UV Overlap (see dropdown in upper right corner). The Preview window colors problematic texels red in this view.
The Baked Lightmaps Preview in the Lighting window’s Baked Lightmaps tab
The Baked Lightmaps Preview in the Lighting window’s Baked Lightmaps tab

Solutions

There is no one single solution for UV overlap, because there are so many things that can cause it. Here are the most common solutions to consider:

  • If you provide lightmap UVs yourself, add margin between UV charts using your modeling package.
  • If Unity automatically generates the lightmap UVs for a Model, you can tell Unity to increase the pack margin. The simplest way to do this is to set the Margin Method to Calculate, and set an appropriate Min Lightmap Resolution and Min Object Scale. If you prefer to set Margin Method to Manual, you can adjust the Pack Margin value directly. For more information on these settings, see documentation on Generating lightmapping UVs.
  • Increase the resolution of the entire lightmap texture. This increases the number of texels between UV charts, and therefore reduces the likelihood of bleeding. The downside is that your lightmap may become too large. You can do this in the Lighting tab under Lightmapper Settings.
  • Increase the resolution for a single GameObject. This allows you to increase lightmap resolution only for GameObjects that have overlapping UVs. Though less likely, this can also increase your lightmap size. You can change a GameObject’s lightmap resolution in its Mesh RendererA mesh component that takes the geometry from the Mesh Filter and renders it at the position defined by the object’s Transform component. More info
    See in Glossary
    under Lightmapping, for example by adjusting Scale in Lightmap.
Same mesh as before, but without bleeding artifacts
Same mesh as before, but without bleeding artifacts
Smooth hard edges in lightmaps
Optimize baking