Sub topic 8
Packing Islands into the Image Space
This chapter assumes you can switch between Object Mode and Edit Mode and select faces. It also assumes you have already marked seams, unwrapped a mesh, and checked it with a test grid. Packing comes after island scale and texel density, covered in the previous chapter, because packing decides how much of the image each island gets to keep.
What packing does
After an unwrap, the UV islands sit wherever the solver left them. Some may hang outside the image, some may overlap, and some may be tiny next to others. Packing is the step that arranges all islands inside the 0 to 1 square of UV space so that:
- every island lies inside the image,
- no two islands overlap,
- the gaps between islands are wide enough to prevent color bleeding,
- as little of the image as possible goes unused.
Each unused pixel is wasted resolution. A well-packed layout lets you use a smaller image, or gives you sharper detail from the same image.
The UV square and what "inside" means
UV space is a square whose corners are (0, 0) and (1, 1), regardless of the image's pixel size. A 512 by 512 image and a 4096 by 4096 image both map to the same square. The packed layout therefore does not depend on the image resolution. Only the margin you need, measured in pixels, depends on it.
Coordinates outside 0 to 1 are legal. Blender repeats or clamps the image there, depending on the Extension setting of the Image Texture node. Islands outside the square give you tiling or smeared edge pixels. For a first unwrap that gives each part of the object unique texture detail, you want everything inside the square.
Running Pack Islands
In the UV Editor:
- Select the islands you want to pack. In Edit Mode, press
Ain the UV Editor to select all UVs. With UV Sync Selection off, only the faces selected in the 3D viewport appear in the editor, and only selected UVs are packed. - Choose UV > Pack Islands or press
Ctrl+P. - Open the Adjust Last Operation panel in the lower left of the editor to change the options.
The options you will use most:
| Option | Effect | Typical choice |
|---|---|---|
| Rotate | Lets the packer turn islands to fit tighter | On, unless the texture has a directional pattern such as wood grain |
| Margin | Gap between islands and around the border, in UV units | 0.004 to 0.02 depending on resolution |
| Scale | Lets the packer resize islands to fill the square | On for a first unwrap |
| Merge Overlapping | Treats overlapping islands as one group, so mirrored copies stay stacked | Off, unless you overlap on purpose |
| Lock Pinned Islands | Keeps pinned islands where they are | Off, unless you have pinned some |
Newer Blender releases add a Shape Method (bounding box, convex hull, or concave). A bounding box is fast but wastes space around L-shaped islands. Concave follows the island outline and packs tightest, so use it if your version offers it. Option names vary a little between versions, so check the Adjust Last Operation panel in yours.
Scale and packing interact
With Scale on, the packer scales all islands by one common factor so the whole layout fills the square. It does not change the ratio between islands. If you balanced texel density in the previous step, packing preserves that balance. A small island stays small compared with a large one.
With Scale off, islands keep their current size. If they do not fit, the packer may place some outside the square. Use this when you have sized the islands by hand and want the packer to arrange them only.
A common mistake is to run Average Island Scale after packing. That operator rescales islands to a uniform density and can push them out of the square or into each other. The correct order is to balance density first, then pack.
Choosing a margin
The gap between islands exists because image sampling is not exact. Two effects pull color across island borders:
- Filtering. With Linear interpolation, a sample near an island edge blends in neighboring pixels, which may belong to another island.
- Mipmaps. When the object is far from the camera, or when a game engine or EEVEE samples a lower-resolution copy of the image, each pixel in that copy covers a larger area. A gap of 4 pixels at full size can shrink to less than 1 pixel at lower levels.
If the margin is too small, you see thin lines of the neighboring island's color along the seam edges. Painted or baked textures also need that gap, because the bake extends edge color outward into it (called padding) to hide the seam.
To turn pixels into UV units, divide the pixels you want by the image width. For a 1024 pixel image and a 4 pixel gap:
image_size = 1024
gap_pixels = 4
margin = gap_pixels / image_size
print(round(margin, 5)) # 0.00391The Margin field is measured in UV units. Depending on the Blender version and the margin method you choose, the actual gap may be a bit different from the number you enter, so measure the result in the editor rather than trusting the formula alone. As a rough guide:
- 512 px: use about 0.008 (4 px)
- 1024 px: use about 0.004 to 0.008
- 2048 px: use about 0.004 (8 px)
- 4096 px: use about 0.004 to 0.008 for baking (16 to 32 px)
Larger gaps cost space. Tiny islands in a crowded layout are the first to get squeezed. If the packer shrinks everything noticeably after you raise the margin, you are paying for the gap with resolution. Weigh that against the artifacts you actually see.
Packing more than one object or material
Each object has its own UV map, and each UV map spans the full square. Two objects that share one image texture and one material need their islands packed together, or they will paint over each other in the same pixels.
To pack several objects into one layout, enter Edit Mode with all of them selected (multi-object editing). Select all UVs in the UV Editor and run Pack Islands once. The packer treats all islands as one group. If you pack each object separately, each fills the whole square on its own, and their islands overlap in the image.
Overlap is sometimes intended. Mirrored left and right halves of a character can sit on top of each other so both halves share the same pixels. In that case turn Merge Overlapping on, so the packer keeps the stacked islands together and does not spread them apart.
UDIMs, briefly
When one square is not enough, UDIM tiles extend UV space to the right in steps of 1: tile 1001 covers U from 0 to 1, tile 1002 covers U from 1 to 2, and so on. Each tile is a separate image. Packing then has more room, but each tile needs its own file and a UDIM-aware image setup. This tutorial stays with a single tile.
Checking the result
Look at the layout first. Then confirm with numbers, because overlaps and out-of-bounds islands are easy to miss at a glance.
Two quick visual checks:
- Turn on the UV test grid from the earlier chapter. Squares should look similar in size across islands, and none should be stretched.
- In the UV Editor, open the Overlays popover and turn on Stretch, or select a single island and look at its outline against the square border.
For numbers, this script reports the bounds of the active mesh's UV map and the fraction of the square covered by islands. Run it in Object Mode, because Edit Mode data is not written to the mesh until you leave it.
import bpy
obj = bpy.context.active_object
mesh = obj.data
uv_data = mesh.uv_layers.active.data
total_area = 0.0
u_min = v_min = float("inf")
u_max = v_max = float("-inf")
for poly in mesh.polygons:
pts = [uv_data[i].uv for i in poly.loop_indices]
# Shoelace formula gives the area of the polygon in UV space.
twice_area = 0.0
for a, b in zip(pts, pts[1:] + pts[:1]):
twice_area += a.x * b.y - b.x * a.y
total_area += abs(twice_area) / 2.0
for p in pts:
u_min, u_max = min(u_min, p.x), max(u_max, p.x)
v_min, v_max = min(v_min, p.y), max(v_max, p.y)
print(f"U range: {u_min:.4f} to {u_max:.4f}")
print(f"V range: {v_min:.4f} to {v_max:.4f}")
print(f"Coverage: {total_area * 100:.1f}% of the 0-1 square")How to read the output:
- A range that starts below 0 or ends above 1 means some islands lie outside the image.
- A coverage close to or above 100% means islands overlap. Overlapping area is counted twice.
- A typical good packing of a hard-surface object reaches 60% to 85%. Organic shapes with many irregular islands often reach less. The remainder is the margin and gaps between curved outlines.
Packing in a script
The packing step fits at the end of the unwrap script. The new part is the call to bpy.ops.uv.pack_islands. Setting use_uv_select_sync makes the UV operators follow the mesh selection, so every face you selected is unwrapped and packed without any extra UV selection step.
import bpy
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode='EDIT')
bpy.context.scene.tool_settings.use_uv_select_sync = True
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.001)
bpy.ops.uv.pack_islands(rotate=True, margin=0.004)
bpy.ops.object.mode_set(mode='OBJECT')This changes the scene's selection sync setting and does not restore it. If you rely on the default, set it back afterwards.
Common errors
- Islands pile on top of each other after packing. Several objects were packed one at a time. Pack them together in multi-object Edit Mode.
- Some faces are not packed. Those faces were not selected, or their UVs were not selected with sync off. Select all UVs, or turn on UV Sync Selection.
- Seam lines appear on the texture. The margin is too small for the image size or for the mipmap distance. Raise it, or increase the bake padding.
- Detail looks uneven after packing. Island scales were not balanced before packing, or Average Island Scale was run afterwards. Balance first, then pack.
- Pattern runs the wrong way on rotated islands. Rotate was on and the texture has a direction. Turn it off, or pack with rotation limited to 90-degree steps if your version offers it.
- Packing seems to do nothing. Only pinned islands were selected and Lock Pinned Islands was on.
Exercise
A 2048 by 2048 image is baked from a packed layout, and thin bright lines show along island borders when the object is viewed from far away. The margin was 0.001. What is the likely cause, and what margin would give about 8 pixels of gap?
Show answer
The margin is too small. 0.001 on 2048 pixels is about 2 pixels, and mipmaps for distant views shrink that gap to under one pixel, so neighboring island colors blend in. For an 8 pixel gap, use 8 / 2048 ≈ 0.0039, so about 0.004. Re-pack with that margin, then re-bake.
Exercise
You run the coverage script and it prints "Coverage: 140.0% of the 0-1 square" and a U range of 0.0120 to 1.0000. Name one cause of the coverage number and say whether the U range shows a problem.
Show answer
Coverage above 100% means islands overlap, because overlapping area is counted twice. This can happen when several objects were packed separately into the same image, or when mirrored islands are stacked on purpose. The U range of 0.0120 to 1.0000 is inside 0 to 1, so no island is out of bounds on that axis. The bound touches 1.0000 exactly, so the margin at the right border may be zero, which could cause bleeding at that edge.