Compositing a Foreground with Opacity

Blend a partially opaque foreground over an opaque background using compatible linear color values.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Trace a grayscale sample
  2. Check composition order

For foreground opacity \(\alpha\), multiply the foreground color by \(\alpha\) and the background color by \(1-\alpha\), then add.

Trace a grayscale sample

Putting white at opacity one quarter over black gives linear intensity one quarter under that model. Weighted means describe the arithmetic.

Check composition order

Swapping which color is the foreground changes the weights applied to each color. For partially transparent layers the output also carries opacity. See order-sensitive operations.[1]

References

  1. Matt Pharr, Wenzel Jakob and Greg Humphreys, Physically Based Rendering ↩