Course contentsShow
← Unity Game Development
Lesson 700 of 82810. VFX and Post-ProcessingFree lesson

Optimizing Lightmap Resolution and UV Layouts

You will learn to adjust lightmap padding and density settings to maximize texture memory efficiency while minimizing visual light bleeding.

In this lesson, you will learn how to fine-tune lightmap padding and texel density to achieve crisp lighting while preventing light bleeding between adjacent surfaces.

When baking static lightmaps, Unity packs UV islands into a shared texture atlas. If these islands are too close together, light information from one surface can "bleed" into its neighbor, creating unsightly seams or glowing edges where shadows should be. Conversely, if your texel density is too high across the entire scene, your lightmap files will explode in memory size, hurting load times and performance.

Controlling Padding and Spacing

The Lightmap Padding setting in the Mesh Renderer or the Lighting window defines the pixel gap between UV islands. Increasing this value is the primary defense against light bleeding. However, padding takes up valuable texture space. The secret to optimization is using the "Preview" mode in the Lighting window; set your Padding just high enough to eliminate bleeding, but no higher, so you can maximize the actual surface area used for light data.

Optimizing Texel Density

Texel density—the number of lightmap pixels assigned to a world-space unit—should be allocated based on object importance.

  • Scale in Lightmap: In the Mesh Renderer component, you can adjust Scale in Lightmap. For background objects or small props, set this below 1.0 to save memory. For hero objects or large structural walls, increase it to 2.0 or higher to improve shadow resolution.
  • Lightmap Resolution: Global settings in the Lighting window define your base density. Start with a lower global resolution and "up-sample" individual meshes via their Scale in Lightmap property to keep your VRAM footprint lean.

By balancing these, you ensure that high-fidelity detail is saved for where the player actually looks, while keeping your memory budget under control.

// Example of checking if an object is using too much memory
// High-detail objects should have high lightmap scale
float lightmapScale = meshRenderer.scaleInLightmap;
if (lightmapScale > 2.0f) {
    Debug.Log("High density allocation: Ensure this is a Hero object.");
}

Key Takeaway: Optimize your lightmaps by setting the minimum necessary padding to prevent bleeding, and use 'Scale in Lightmap' to prioritize high-resolution textures only for the most visually prominent objects in your scene.