A tool for the most efficient lightmap packing in Unity.
It generates unique uv2 per mesh, instead of using lightmap UV offsets, which when combined with static batching doesn't create any extra cost. Additional vertex streams are used to set uv2 in editor, which requires modifications to bakery scripts. Lightmap Scale is also calculated differently which allows it to have perfectly uniform texel density when lightmap scale is set to 1.
- Add package with git
https://github.com/z3y/XatlasLightmap.git
- Patch Bakery
Tools > XatlasLightmap > PatchBakery
(only once) - Add a
XatlasLightmapPacker
script on a GameObject - Select a BakeryLightmapGroup asset with Packing Mode set to Original UV
- Generate Lightmap UVs on the model importer or create custom UV2
- Enable mesh Read/Write on the model importer
- Pack
- Nested lightmap groups arent supported yet
- Doesn't work with GPU instancing, since every mesh ends up being unique. Only use with static batching.
- Model reimports will break the mesh until packed again.
- Since the packing is so efficient and the padding gets applied correctly most shaders will have slight bleeding at 2px, it is recommended to use a centroid interpolator for the lightmap UV.
- Using bicubic sampling requires more padding
- Lightmaps might fail to bake properly first time
- Only works with Bakery
- Sometimes on build it can fail to get UV2 because Read/Write is disabled, even tho its not needed for an editor script. This also doesn't affect the build size. The original mesh is never referenced, only the combined static mesh gets included.
Sponza:
Checker preview:
Sponza 2: