Skip to content

Better lightmap packing for Unity

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

z3y/XatlasLightmap

Repository files navigation

XatlasLightmap

A tool for the most efficient lightmap packing in Unity.

How it works

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.

How to use

  • 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

Limitations

  • 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.

  • 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.

Examples

Sponza:

Screenshot 2023-03-18 164316

Checker preview:

image

Sponza 2:

image

About

Better lightmap packing for Unity

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published