Alpha Compositing
Combining images using a fourth channel that records each pixel's opacity, the arithmetic behind transparency, layering, and smooth edges.
Alpha compositing combines images using an alpha channel, a fourth value stored with each pixel's red, green, and blue that records how opaque the pixel is, from 0 for fully transparent to 1 for fully opaque. Alvy Ray Smith and Ed Catmull developed the integrated alpha channel in the late 1970s. In 1984, Thomas Porter and Tom Duff defined an algebra of compositing operators, now called the Porter-Duff operators.
The most common operator is over: put image A on top of image B. Each resulting pixel is A's color weighted by A's alpha, plus B's color weighted by whatever A lets through. Other operators cut images by each other's shapes, such as in, out, and atop, which is how masks and clipping work.
Premultiplied alpha stores color already multiplied by alpha. A half-transparent red pixel is stored as half-intensity red with alpha 0.5. This makes the over operation simpler and, more importantly, makes filtering correct. With straight alpha, a fully transparent pixel can still hold a color, often black or white, and when an image is scaled or blurred that hidden color bleeds into the edges, leaving dark or light fringes around sprites and icons. Premultiplied alpha avoids the problem in Image Resampling and Mipmapping, which is why game engines and compositors use it internally.
Order matters. The over operator isn't commutative: A over B differs from B over A. In 3D rendering this creates a long-standing problem. Opaque objects can be drawn in any order, because the depth buffer keeps the nearest surface, but transparent ones must be sorted back to front and blended in order. Sorting fails when transparent objects intersect, and deferred shading has no room to store several overlapping surfaces per pixel, so engines draw transparent objects in a separate pass. Order-independent transparency techniques exist but cost memory or accuracy. Particle System effects like fire often use additive blending instead, which ignores order.
Compositing also has a color-space subtlety. Blending should happen in linear light, but much software blends gamma-encoded values directly, which makes edges between bright and dark colors look too dark.
Alpha is everywhere in interfaces. A desktop Compositor layers translucent windows and shadows; browsers composite CSS opacity in groups defined by the Stacking Context; video editors key out green screens into alpha. Smooth edges themselves are a form of alpha: an anti-aliased edge pixel is partly covered, so its coverage is blended like opacity, as discussed under Aliasing. Text works the same way, with each glyph rendered as a coverage mask, as described under Font Rendering.
Alpha has limits in what it can represent. A single value per pixel can't express colored glass that tints what's behind it differently for each color, which requires separate transmission per channel.
See also2
Glassmorphism
An interface style of translucent, blurred panels that let the content behind them show through like frosted glass, recurring across operating systems since the 2000s and repeatedly criticized for hurting legibility.
Design & Interface9 connections
GIF
A 1987 image format limited to 256 colors per frame that survived a patent fight, the rise of better formats, and its own inefficiency to become the internet's format for short looping clips and reactions.
Graphics & Rendering4 connections
Linked from5
- GIFGraphics & Rendering
A 1987 image format limited to 256 colors per frame that survived a patent fight, the rise of better formats, and its own inefficiency to become the internet's format for short looping clips and reactions.
- GlassmorphismDesign & Interface
An interface style of translucent, blurred panels that let the content behind them show through like frosted glass, recurring across operating systems since the 2000s and repeatedly criticized for hurting legibility.
- PixelGraphics & Rendering
The smallest addressable element of a digital image or screen, better understood as a point sample than as a little square, whose physical form, shape and density vary enough between devices that the web had to invent a separate reference pixel.
- SpriteGraphics & Rendering
A 2D image drawn and moved as a unit, from the hardware sprites of arcade machines and consoles to sprite sheets and atlases in modern engines.
- Stacking ContextDesign & Interface
The nested coordinate system that decides what paints above what, and why z-index often does nothing.