skip to content

A UI texture atlas shows neighbouring icons bleeding into each other's edges when drawn small; what causes it, and how do you fix it?

level: seniorimportance: should knowfreq 42%

answer

  1. only when small
  2. coarse levels average across borders
  3. addressing knows the texture, not the icon
  4. gutters sized to the level you sample
  5. 4x4 blocks share endpoints

basics

~20 s

Filtering reaches past each icon: bilinear taps near an edge pull in neighbours, and coarser mip levels average across icon borders. Pad icons with duplicated edge texels, align them to a power-of-two grid, and cap the mip level the padding protects.

solid answer

~50 s

It shows only at small sizes, so **mip levels** are the main cause: at level `k` one texel averages a `2^k x 2^k` block of the base level, and blocks straddling an icon border mix both icons. Bilinear lookups add half a texel of reach at any level, trilinear also reads the next coarser level, and block compression shares colour endpoints within a 4x4 block. Clamp addressing does not help, because it acts on the whole texture's edges, not on rectangles inside it. The fix is a **gutter**: align each icon to a `2^k` grid, extrude at least `2^k` texels of its own edge colours on every side, and cap the level of detail at `k`, so every level-`k` texel touching an icon holds only that icon. Align icons to 4x4 blocks when compressed. Alternatives are an array texture with one icon per layer, or pre-sized icons that are never minified.

go deeper

for a junior

Know that filtering reads texels around the sample point, so neighbouring icons in one texture can leak into each other, and that padding between icons is the usual fix.

for a middle

Explain how mip levels average 2^k blocks, why bilinear lookups reach half a texel outside, and why addressing modes do not apply to sub-rectangles of an atlas.

for a senior

Separate the causes with toggles for size, filtering and compression, size the gutter and the level cap from the smallest draw size, and add the rule to the packer.

for a principal

Decide when an atlas is the right container at all versus array textures or pre-sized icons, weighing draw batching against padding waste and quality at small sizes.

## Reproduce and narrow it down Bleeding in an atlas has several causes, and a few toggles tell them apart: - **Does it depend on on-screen size?** If icons are clean at native size and bleed only when drawn small, coarser mip levels are involved. - **Does point sampling at native size remove it?** If a faint line at native size vanishes with point sampling, the bilinear footprint is crossing the icon's rectangle. - **Does an uncompressed build remove it?** If so, block compression is mixing icons that share a block. - **Is the fringe dark rather than tinted by the neighbour?** Then transparent padding texels hold black or stale colour that straight-alpha filtering pulls in. That is an alpha-handling problem, covered with transparency and premultiplied alpha, rather than a layout one. ## Why filtering crosses icon borders | Mechanism | When it shows | Why | |---|---|---| | Bilinear footprint | any size, faint | a lookup near the edge blends the 2x2 texels around it, reaching half a texel outside | | Mip averaging | small sizes, strong | at level k each texel averages a 2^k x 2^k block of the base level, so blocks straddle borders | | Trilinear blend | between sizes | a lookup at lod 2.4 also reads level 3, one level coarser than the nearest | | Block compression | any size | a 4x4 block shares two colour endpoints, so icons inside one block skew each other | **Addressing modes do not help.** Wrap, clamp and mirror act at the edges of the whole texture, at 0 and 1; the sampler knows nothing about the rectangles inside it. Clamp to edge on an atlas only protects the sides of icons that touch the atlas border. ## Padding that survives the mip chain The robust fix is a **gutter** of duplicated edge texels around each icon (edge extrusion, or dilation for irregular shapes), sized to the levels you will sample: 1. **Align** each icon's rectangle to a grid of `2^k` texels. 2. **Extrude** at least `2^k` texels of the icon's own edge colours on every side. 3. **Cap** the level of detail at `k`, with a maximum-level setting or by generating only `k + 1` levels. With that layout, each level-`k` texel touching an icon covers only that icon and its own gutter, so lookups stay clean through level `k`. One level coarser, a texel spans both icons' gutters and the neighbour leaks in, which is why the cap matters: trilinear filtering would otherwise read that level. For example, 64x64 icons with 4 texels of extrusion on a 4-texel grid stay clean through level 2, where an icon is 16x16; drawn at 8 pixels they would sample level 3 and bleed, so either cap at level 2 or double the gutter. Two smaller measures complement padding but do not replace it: - **Inset the UVs** by half a texel so bilinear lookups at the base level never reach outside the rectangle; the inset needed doubles with each mip level, so it is not a fix for minification. - **Align to 4x4 blocks** when the atlas is block-compressed, so no block holds texels of two icons. Each mip level is compressed too, and a block at level `k` spans `4 x 2^k` base texels, so keeping coarse levels clean needs that larger grid. ## Alternatives to one big atlas - An **array texture** gives each icon its own layer with its own edges, mip chain and addressing, so nothing bleeds between layers; every layer shares one size and format. - **Per-size icons**: interfaces often draw icons at a handful of fixed sizes, and icons pre-rendered at each size need no minification. - **Mips built per icon, then packed**: generating each icon's chain separately and packing level by level keeps averaging inside each icon, though bilinear taps still need a little padding. ## Tiling a region of an atlas Hardware wrap cannot repeat a sub-rectangle. Repeating one region means wrapping the coordinate in the program, and the jump in texture coordinates at each repeat distorts the level-of-detail estimate there (why belongs to the shader programming model) unless the level is computed from the unwrapped coordinates. Moving a tiling texture out of the atlas is usually simpler. ## Checking the fix - Draw every icon at the smallest size the interface uses, and one step smaller, on a contrasting background. - Repeat with the compressed build and with the filtering mode the game ships, since trilinear and anisotropic settings change which levels are read. - Add the padding rule to the atlas packer so a new icon cannot be placed without its gutter.

  • Why might the bleeding fringe look dark instead of tinted by the neighbouring icon?
    Transparent texels in the gutter often hold black or leftover colour. With straight alpha, filtering blends that colour into the edge even though its alpha is zero, giving a dark halo. Dilating colour into the transparent texels, or storing premultiplied alpha, removes it; that is an alpha-handling fix rather than an atlas-layout one.
  • How would you repeat a border pattern that lives in one region of an atlas?
    Hardware addressing cannot wrap a sub-rectangle, so either move the pattern to its own texture or array layer and use wrap addressing, or wrap the coordinate in the program and compute the level of detail from the unwrapped coordinate to avoid a seam at each repeat. Unrolling the repeats into geometry also works for short borders.
  • How does block compression change the padding rule?
    Block formats encode 4x4 texel blocks with shared endpoints, so an icon boundary inside a block lets one icon's colours shift the other's. Align every icon rectangle and its gutter to multiples of 4 texels at the base level. Each mip level is compressed separately and a block at level k spans 4 x 2^k base texels, so clean coarse levels need alignment to that larger grid.

  • Clamp-to-edge addressing stops icons in an atlas bleeding into each other.
  • A half-texel UV inset fixes bleeding at every mip level.
  • A one-texel transparent border around each icon is enough padding.
  • Bleeding at small sizes means the atlas resolution is too low.
  • Turning off mipmaps on the atlas is a free fix with no downside.