Sub topic 11
Packing Islands and Setting Margins
This chapter covers how to arrange UV islands inside the 0-1 UV square so the texture space is used well and neighboring islands do not bleed into each other. It assumes you can mark seams, unwrap a mesh, and read the UV Editor. It also assumes you have met texel density in the previous chapter. You should also know how to select islands in the UV Editor with sync selection turned off.
What packing does
Packing is the step that moves, rotates, and scales islands so they fit together in UV space. UV space is the square from 0 to 1 on both axes, and an image texture is stretched over that square. After an unwrap, the islands usually overlap or sit in a pile. Packing lays them out so that:
- No island overlaps another, unless you want it to.
- Little of the square is left empty.
- Each island has a gap around it, called the margin.
Empty space is wasted resolution. If islands cover only 50% of the square, half of the pixels in the texture store nothing. Better packing gives the same model a sharper texture at the same image size.
Margins and why they matter
A margin is the gap between two islands, measured as a fraction of the UV square. A margin of 0.02 means a gap of 2% of the width of the texture. On a 2048 pixel texture that is about 41 pixels.
Gaps are needed because of three effects:
- Filtering. When the renderer samples a texture at a distance, it blends neighboring pixels. Pixels from a nearby island leak into the edge of your island.
- Mipmaps. A mipmap is a smaller copy of the texture used for distant surfaces. Each level halves the resolution, so a gap of 4 pixels becomes 2, then 1, then nothing. Islands that were separate at full size touch at the lower levels.
- Baking and painting. Bakers and paint tools extend color a few pixels past each island edge (often called padding or bleed) so seams do not show. That extension needs room.
A rule of thumb is to keep the margin at least as large as the padding you plan to bake, and to increase it when the texture will be mipmapped heavily.
| Texture size | Margin 0.005 | Margin 0.01 | Margin 0.02 |
|---|---|---|---|
| 1024 px | about 5 px | about 10 px | about 20 px |
| 2048 px | about 10 px | about 20 px | about 41 px |
| 4096 px | about 20 px | about 41 px | about 82 px |
A larger margin protects against bleeding but wastes area. Pick the smallest value that survives your lowest mipmap level.
The Pack Islands operator
In the UV Editor, choose UV > Pack Islands. The operator works on the selected islands, so press A in the UV Editor first (with UV sync selection off, the faces must also be selected in Edit Mode so they appear in the editor). The operator panel in the lower left corner lists the options. Names vary a little between Blender versions, so check your own panel. The common ones are:
- Rotate: allows islands to turn so they fit tighter. This improves coverage but changes the direction of textures with a visible grain, such as wood or brushed metal.
- Margin: the gap between islands.
- Margin Method: how the margin is measured. Scaled scales the margin with the UV space. Add places a fixed distance between islands. Fraction treats the margin as a fraction of the island size.
- Scale: lets the operator resize islands to fill the square. Turn it off if you have already set texel density by hand.
- Lock Pinned Islands: leaves islands that contain pinned vertices where they are.
- Shape Method: Concave follows the real outline of each island. Convex uses a simpler outline. Bounding Box is fastest and least efficient.
Packing with Scale enabled changes the relative sizes of islands in some configurations. If you spent time matching texel density, disable scaling or check the density again after packing.
Packing from a script
Packing is also available from Python. The script below unwraps the active mesh along its seams, then packs with a margin. Run it from the Scripting workspace with a mesh object active.
import bpy
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.02)
bpy.ops.uv.pack_islands(margin=0.02)
bpy.ops.object.mode_set(mode='OBJECT')The unwrap call already applies a margin while it separates islands. The pack_islands call then arranges them with the same gap. Using the same value in both keeps the result predictable. Other keyword arguments such as rotate exist on pack_islands, but they have changed between Blender versions, so check the Python tooltips in your build before relying on them.
A packing workflow
This order of steps avoids rework:
- Unwrap every island and fix distortion first. Moving islands later is cheap, but reshaping them after packing means packing again.
- Equalize texel density across the islands you want to match.
- Run Pack Islands with the margin that fits your texture size.
- Look at the result with a checker texture and inspect the tightest gaps.
- Move any important islands by hand, then lock them with pins and pack the rest.
Important surfaces, such as a face on a character, can be scaled up before packing so they get more pixels. Hidden surfaces, such as the underside of a table, can be scaled down. The packer respects these relative sizes when Scale is off.
Packing several objects together
To share one texture between several objects, enter Edit Mode with all of them selected. The UV Editor then shows all their islands at once. Pack them together in one pass so the objects do not overlap. If you pack each object alone, every one fills the whole square and the islands land on top of each other in the shared texture.
Overlapping on purpose
Overlap is not always a fault. Identical parts, such as the left and right wheel of a car, can sit on the same UV area. They then share pixels, which doubles the effective resolution for the same image size. This works only when the parts need the same texture. Painted wear, baked shadows, and normal maps that depend on direction usually break the trick. The mirroring chapter covers when it is safe.
When you pack, exclude overlapping islands from the operation or move them out of the way, and then place them manually. Otherwise the packer separates them again.
Common problems
- Islands touch or bleed after baking. The margin is too small for the bake padding. Increase it and pack again.
- Large empty areas remain. Enable Rotate, switch Shape Method to Concave, or scale down one very large island.
- Textures run in the wrong direction. Rotation turned an island. Turn Rotate off, or rotate that island back by hand and exclude it from packing.
- Density looks uneven after packing. Scale was on. Turn it off and repack, or run the texel density step again.
- Islands extend beyond the square. Check for pinned or locked islands that the packer did not move, and for stray islands from hidden faces.
Checking the result
Open the checker texture used earlier in the tutorial. Look for three things. The squares should have a similar size in each part of the model, which confirms the density. The gaps should look even. No island should cross the border of the square. If you work with a checker, you can also zoom in to the narrowest gap and count the pixels yourself.
Exercise
You are baking a 2048 px texture and want at least 16 pixels of padding around each island. What is the smallest margin value, as a fraction of the UV square, that leaves room for the padding? What would you check afterward?
Show answer
16 / 2048 is about 0.0078, so a margin of 0.008 is the minimum, and a slightly larger value such as 0.01 gives a safety buffer. Afterward, check the narrowest gap with a checker texture, and confirm that no island crosses the border of the 0-1 square.
Exercise
After packing, the wood grain on a plank runs sideways while the other planks run correctly. What caused it, and how do you fix it?
Show answer
Rotate was enabled, so the packer turned that island to fit it better. Rotate the island back by hand, pin a vertex or exclude it from the operation, and repack the rest with Rotate disabled, or leave Rotate off for the whole object.