You can generate your own lightmap UVs for a Mesh, or Unity can automatically generate them.
You can author your own lightmap UVs in the content creation software of your choice. You must place lightmap UVs in the second UV channel of your mesh.
A good UV set for lightmaps should adhere to the following rules:
You can tell Unity to automatically generate lightmap UVs for a Model, using the Model Import Settings.
These are the settings that appear in the Model tab of the Model Import Settings, when you enable Generate Lightmap UVs.
Property: | Function: | |
---|---|---|
Hard Angle | The angle between neighboring triangles (in degrees) after which Unity considers it a hard edge and creates a seam. You can set this to a value between 0 and 180. This is set to 88 degrees by default. If you set this to 180 degrees, Unity considers all edges smooth, which is realistic for organic models. The default value (88 degrees) is realistic for mechanical models. |
|
Angle Error | The maximum possible deviation of UV angles from the angles in the source geometry (as a percentage from 0–100). This is set to 8% by default. This controls how different the triangles in UV space can be to the triangles in the original geometry. Usually this should be fairly low, to avoid artifacts when applying the lightmap. |
|
Area Error | The maximum possible deviation of UV areas from the areas in the source geometry (as a percentage from 0–100). This is set to 15% by default. This controls how well Unity preserves the relative triangle areas. Increasing the value allows you to create fewer charts. However, increasing the value can change the resolution of the triangles, so make sure the resulting distortion does not deteriorate the lightmap quality. |
|
Margin Method | Whether you specify the Pack Margin manually, or whether Unity automatically calculates it. | |
Manual | You specify the Pack Margin manually. | |
Calculate | Based on expected lightmap resolution and object scale, Unity calculates a Pack Margin just large enough to avoid UV overlaps. | |
Pack Margin | The margin between neighboring charts (in pixels), assuming the Mesh takes up the entire 1024x1024 lightmap. You can set this to a value between 1 and 64. A larger value increases the margin, but also increases the amount of space the chart needs. This is set to 4 pixels by default. For more information, see Pack Margin. This property is only visible when Margin Method is set to Manual. |
|
Min Lightmap Resolution | The minimum lightmap resolution (in texels per unit) of the MeshRenderers that use this Mesh, across all Scenes. The lightmap resolution of a MeshRenderer is a combination of the MeshRenderer’s Scale in Lightmap property, and the Lightmap Resolution property of the Lighting Settings Asset of the Scene it appears in.For more information, see Min Lightmap Resolution and Min Object Scale. Unity uses this information to calculate pack margin. This property is only visible when Margin Method is set to Calculate. |
|
Min Object Scale | The minimum transform scale that of the GameObjects that use this Mesh, across all Scenes. For more information, see Min Lightmap Resolution and Min Object Scale. Unity uses this information to calculate pack margin. This property is only visible when Margin Method is set to Calculate. |
To allow filtering, the lightmap contains lighting information in texels near the chart border, so always include some margin between charts to avoid light bleeding when applying the lightmap.
The lightmap resolution defines the texel resolution of your lightmaps. Lightmappers dilate some chart texels in the lightmap to avoid black edges, so the UV charts of your Mesh need to be at least two full texels apart from each other to avoid light bleeding. Use the Pack Margin setting to ensure you have enough margin between the UV charts of your geometry.
In lightmap UV space, the padding between charts need to be at least two full texels in order to avoid UV overlapping and accidental light bleeding. In this image, the black space represents the space between charts.
Placing UV charts too close together may cause cross-chart texel bleeding in the final lightmap. Placing charts too far away from each other wastes memory. The ideal packing margin of an object depends on how many lightmap texels are allotted to it.
The number of texels that Unity uses for a MeshRenderer depends on the MeshRenderer’s lightmap resolution and transform scale. To calculate a good margin, Unity needs to know the expected minimum values for these properties.
A MeshRenderer’s lightmap resolution is a combination of the Lightmap Resolution
property of the Lighting Settings Asset for the Scene that the MeshRenderer appears in, and the Scale in Lightmap
property of the MeshRenderer. Note that this means that the same MeshRenderer can have a different lightmap resolution in different Scenes.
You can use the Inspector to view the lightmap resolution of a MeshRenderer in a given Scene:
The following screenshots demonstrate equal resolution, but with different UVs. The first image has a high Angle Error, and the result contains unintended artifacts. The second image has the default Angle Error (8%). In Meshes with more triangles, angle distortion can significantly distort the shape.
In the image below, two spotlights with the same parameters light the sides of a cylinder. The right-hand side of the cylinder has a higher Area Error value, which distorts the triangles and leads to a lower resolution, creating artifacts in the light.
Progressive Lightmapper added in 2018.1 NewIn20181
Calculate Pack Margin added in 2020.1 NewIn20201