Course contentsShow
← Unity Game Development
Lesson 586 of 8289. Rendering and VisualsFree lesson

Optimizing Lightmap UV Unwrapping and Resolution

You will learn to create efficient lightmap UV layouts and set appropriate texel densities to minimize light leaking and texture memory usage.

In this lesson, you will learn how to structure your lightmap UVs and adjust texel density to achieve high-quality lighting without ballooning your texture memory or causing light leakage.

The Anatomy of Lightmap UVs

Lightmapping relies on a secondary set of UV coordinates, distinct from your texture (diffuse) UVs. While texture UVs often overlap to save space, lightmap UVs must be unique and non-overlapping to ensure each face receives its own baked lighting data. If UV shells are too close together, light "bleeds" from one side of an object to another, creating unsightly artifacts called light leaking.

To optimize, ensure your lightmap UVs follow these rules:

  1. Padding: Use the Pack Margin setting in the Model Import Settings. A margin of at least 2–4 pixels is recommended to prevent texture filtering from bleeding light between islands.
  2. Minimize Distortion: Keep UV shells uniform in scale. If one face is stretched in the UV layout, the baked light will look warped.

Balancing Texel Density

Texel density refers to the amount of "pixels" assigned to a specific area of your mesh. If your resolution is too low, lighting looks blurry; if too high, your VRAM usage spikes.

Instead of setting a global resolution, use the Lightmap Resolution setting in your scene to define texels per unit, then fine-tune individual objects using the Scale In Lightmap property on the Mesh Renderer.

// Conceptually, you reduce memory by lowering the scale 
// for background objects that don't need high-detail lighting:
renderer.scaleInLightmap = 0.5f; 

Preventing Light Leaks

Light leaks often occur at the seams of geometry where light can "sneak" through thin meshes. You can mitigate this by:

  • Thickening Geometry: Use closed, manifold meshes rather than single-sided planes.
  • Stitching UVs: Keep connected faces together in your UV layout to avoid light seams at mesh edges.
  • Check the UV Map: Use the Lightmap view mode in the Scene window to visualize your layout and ensure there are no overlapping islands or wasted space.

Key Takeaway: Efficient lightmapping requires non-overlapping UV islands with adequate padding and strategic distribution of texel density to maintain visual fidelity while minimizing memory overhead.