Contiguous UVs and Padding
One approach to setting up lightmapping UVs is by having contiguous (or connected) groupings of the geometry. To generate a smooth lighting result, it’s ideal to connect faces in ways that make sense to represent the geometry.
For example, the UV charts below have connected all the front and side faces of the geometry into a single UV chart and the top has been separated as its own island.
- UV Charts for the Static Mesh geometry.
Once unwrapped, it’s necessary to include a minimum amount of padding between UV charts to prevent light and shadow bleed artifacts. A minimum of four texels is usually required to avoid all bleeding artifacts since DXT texture compression operates on 4x4 texel blocks.
If you are setting up a custom lightmap for padding, use the following equation to determine the proper texel spacing for your grid:
1 / Target Lightmap Texture Resolution = Texel Grid Spacing
Example of the formula above using a resolution of 64:
1 / 62 = 0.0161290323
UE4 uses a pixel for padding meaning that we need to subtract one from each side when trying to find out snapping grid to manually snap UV charts to the grid. Using the auto-generated lightmap UVs will pack them with the appropriate padding.
- Wasted UV Padding
- Necessary UV Padding
The edges of the lightmap UV do not need additional padding because Lightmass already pads around the edges of the lightmap to prevent any sort of light and shadow bleeding when combining the lightmap texture atlas for the level. This leads to unnecessary padding and wasted UV space.
Using the UV space efficiently can require you to force some UVs together with brute force and scaling to fit them within the UV space.
(From left to right) Lighting only view in Unreal Engine; Static Mesh with Texture; Texture UV Layout, Lightmap UV Layout.
It’s more important that we have a clean contiguous surface without interruption for the lighting result than to worry about 1:1 scaling. A lightmap that has a 1:7 scaled ratio whereby it has twice the coverage will produce a better result even if the islands are non-uniformly scaled. Areas that are too thin but maintain a 1:1 ratio will not light correctly because it can’t capture a good result.
Another key takeaway from this example is that the negative interior cuts have been separated (highlighted red) to prevent them from sharing light and shadow information for the contiguous UV charts where a smooth lighting result is important.