skip to content

What is premultiplied alpha, and why does it remove dark fringes from filtered sprites and let one blend mode mix additive and alpha-blended particles?

level: middleimportance: should knowfreq 50%

answer

  1. what a transparent texel's colour holds
  2. filtering averages neighbouring texels
  3. scale colour by coverage once
  4. source factor one
  5. alpha zero but colour non-zero

basics

~20 s

Premultiplied alpha stores colour already multiplied by alpha, so transparent texels are zero and add nothing when filtered. The blend becomes C = Cs + (1 - As) * Cd, which is additive when alpha is zero, so one blend state covers both.

solid answer

~50 s

A straight-alpha texture stores colour and alpha independently, so a fully transparent texel still carries a colour, often black. Bilinear filtering and mip generation average that colour into neighbouring visible texels, which draws a dark fringe around the sprite. Premultiplied alpha stores `(r*a, g*a, b*a, a)`: a transparent texel is `(0, 0, 0, 0)`, and averaging premultiplied values gives the alpha-weighted average, which is the correct one. The blend becomes `C = Cs + (1 - As) * Cd`. A texel with colour and `As = 0` adds to the target without hiding it, which is additive blending, while `As = 1` replaces it, so glowing embers and occluding smoke share one blend state and can be sorted and drawn together. Premultiplied layers also compose correctly in an offscreen buffer, because over is associative in that form.

go deeper

for a junior

Recall what premultiplied means: colour stored already multiplied by alpha, so a fully transparent texel is all zeros.

for a middle

Work the fringe example with numbers, write both blend equations, and show how alpha zero with non-zero colour turns the premultiplied blend into additive.

for a senior

Diagnose halos and dark edges from a mismatched convention, explain why premultiplying after sampling is too late, and use associativity to justify offscreen particle buffers.

for a principal

Decide one alpha convention for the whole content pipeline, enforced at texture import, so artists, tools and shaders cannot mix straight and premultiplied assets silently.

## Two ways to store a transparent colour A texel or fragment carries a colour and an opacity, **alpha**. **Straight alpha** stores them independently as `(r, g, b, a)`, where `rgb` is the surface colour whatever its opacity. **Premultiplied alpha** stores colour already scaled by opacity: `(r * a, g * a, b * a, a)`. In the table, `Cs` means the source colour as each convention stores it. | | Straight alpha | Premultiplied alpha | |---|---|---| | Fully transparent texel | any colour, often black or leftover paint | always `(0, 0, 0, 0)` | | Over blend | `As * Cs + (1 - As) * Cd` | `Cs + (1 - As) * Cd` | | Filtering and mips | wrong at edges | correct | | Additive in the same blend state | no | yes, with `As = 0` | | Flattening layers offscreen | needs a separate alpha blend | associative | ## Where the dark fringe comes from Filtering averages neighbouring texels. Take a white leaf texel `(1, 1, 1, 1)` beside a transparent texel stored as black `(0, 0, 0, 0)`, sampled halfway between them, drawn over a white background. - **Straight alpha:** the filtered sample has colour `(0.5, 0.5, 0.5)` and alpha `0.5`. Blending gives `0.5 * 0.5 + 0.5 * 1 = 0.75`: a grey edge on a white leaf over a white background. The transparent texel's colour, which should not matter at all, has been averaged in. - **Premultiplied alpha:** the filtered sample is `(0.5, 0.5, 0.5, 0.5)`. Blending gives `0.5 + 0.5 * 1 = 1.0`, white, as expected. Averaging premultiplied values is an **alpha-weighted average** of colour, so a texel with zero alpha carries zero weight. The same holds for mip generation, which is repeated averaging, and for filtered downsampling of render targets. Straight-alpha assets can hide the problem by **dilating** colour into transparent texels, copying the nearest visible colour outward, but that is a content workaround that has to hold at every mip level. ## One blend state for alpha and additive With premultiplied colour the blend uses a source factor of one and a destination factor of one minus source alpha: `C = Cs + (1 - As) * Cd`. - `As = 1`: `C = Cs`, the surface replaces what is behind it. - `0 < As < 1`: ordinary translucency. - `As = 0` with non-zero `Cs`: `C = Cs + Cd`, which is **additive** blending. A fire-and-smoke effect can therefore mix glowing embers, with alpha near 0, and dark occluding smoke, with alpha near 1, in one material, one blend state and one sorted draw, instead of two passes that cannot interleave correctly. The same factors also work on the alpha channel: `a = As + (1 - As) * ad` is exactly how coverage accumulates. Straight alpha needs a separate alpha blend to get that, because its colour factors applied to alpha would give `As * As + (1 - As) * ad`. ## Flattening layers offscreen In premultiplied form the over operator is **associative**: `(A over B) over C` equals `A over (B over C)`. A group of layers can therefore be flattened into one premultiplied layer and composited later, which is what an offscreen particle buffer, a UI layer or a pre-rendered sprite does: 1. Clear an offscreen target to `(0, 0, 0, 0)`. 2. Draw the layers into it back to front with the premultiplied over blend on all four channels. 3. Composite the result over the scene with `C = rgb + (1 - a) * Cscene`. For one layer this gives `Cs + (1 - As) * Cscene`, and for two layers it expands to the same terms as drawing each layer straight over the scene, so nothing is lost by the detour. ## Pitfalls - **Premultiply exactly once.** A straight texture drawn with the premultiplied blend adds `Cs` at full strength, so soft edges come out too bright and leftover colour in transparent texels shows as a halo. Premultiplying twice darkens soft edges instead. - **Premultiply before filtering.** Multiplying by alpha in the fragment program after sampling is too late: the filter has already averaged the transparent texels' colour into the edge. - **Premultiply linear values.** For colour textures stored with sRGB encoding, multiply the linear colour by alpha; premultiplying the encoded values gives slightly wrong edge colours once they are decoded. - **Precision at low alpha.** Premultiplied colour converted from a straight texture is never larger than its alpha, so in an 8-bit texture a faint texel has few colour levels left; faint particles can band, and a higher-precision format helps where it matters. - **Fog and tint.** They scale colour linearly, so they apply to premultiplied colour too, but fog must mix toward `fogColour * As`, not `fogColour`, or transparent pixels pick up fog they should not.

  • What goes wrong if a straight-alpha texture is drawn with the premultiplied blend?
    The blend adds `Cs` at full strength instead of `As * Cs`, so semi-transparent edges come out too bright, and transparent texels that still hold leftover colour add a glowing halo. The reverse mistake, premultiplying twice, multiplies by alpha twice and darkens soft edges. The fix is one agreed convention per asset, converted in the texture pipeline rather than patched per shader.
  • Why does premultiplied alpha matter when particles are rendered into a lower-resolution offscreen buffer?
    The buffer must hold the particles' combined colour and coverage so they can be composited over the scene later. With premultiplied over on all four channels, layers flatten associatively into one premultiplied layer, and the scene is finished with `C = rgb + (1 - a) * Cscene`. Straight alpha has no such single-layer form without a separate alpha blend and a division to recover colour.

  • Premultiplied alpha is just an optimisation that saves one multiply per pixel.
  • Dark sprite fringes come from texture compression, not from filtering straight alpha.
  • Additive and alpha-blended particles always need separate blend states and draws.
  • Multiplying by alpha in the fragment program after sampling fixes filtering fringes.
  • A fully transparent texel's colour never affects the rendered image.