Game Development Reference
In-Depth Information
We can substitute a,b by some color values, a = {0.37, 0.37, 0.37, 0.25} and b = {1,1,1,1}
this will blend a dark gray color onto a white render target.
The result is a light gray color.
Figure 38 - Alpha blending.
Note that the calculations are done in normalized values [0..1], however the final pixel
value is represented in 8 bits (assuming we are using an 8-bit per channel format); a value
from [0..255] often represented in hex as [0x00..0xff], in this example the final color value
is 0xd7 or 215.
3.10.2.2 Premultiplied Alpha
Insomecases,thesourcealphacanbepremultipliedtothecoloroftheimage,itavoidsper-
forming these multiplications during the blend. If our source color is {1,0,0,0.5} , we would
premultiply it by 0.5 such that the final color would be red at 50% intensity {0.5, 0.0, 0.0} .
Usually the premultiplication is done as part of a pre-process on the source image.
Why is it different than conventional non-premultiplied alpha blending? At a glance it
wouldappearasifthereisnosignificantdifferenceexceptofwhenthemultiplicationtakes
place,howeverthereareafewthingstoconsider,thefirstonebeingfiltering.Filtersareap-
plied when some amount of scaling occurs; when scaling up we need to fill in some pixels
in the space in between source pixels and when scaling down we want to blend pixels to-
gether to ensure the destination image retains enough information and quality. The prob-
lembecomesparticularlynoticeablewhenthereisasharpdiscontinuitybetweenanopaque
pixel (alpha = 1.0) and a transparent pixel (alpha = 0.0), a linear interpolation filter will
Search WWH ::




Custom Search