unpremultiplyAlpha
unpremultiplyAlpha
Converts a color from premultiplied alpha format back to its original, straight alpha format, enabling correct color adjustments.
Core Advantages
It enables mathematically correct color operations (like brightness adjustments) on semi-transparent colors by isolating the pure RGB values, avoiding incorrect, darkened results from modifying the premultiplied color directly.
Common Uses
Applying Post-Processing to a Render Target
Implementing Custom Color Blending Modes
Color Picking or Data Analysis
How to adjust
This is a pure function whose behavior depends on the input color's alpha. For colors with alpha 1.0, the output is unchanged; for semi-transparent colors, it 'brightens' the RGB components to restore their original pure color; for alpha 0.0, it safely returns a zero vector.
Code Examples
1// Assuming premultipliedColor is a premultiplied color
2// Convert it to straight alpha to get the pure color
3const straightAlphaColor = unpremultiplyAlpha( premultipliedColor );
4
5// Now, it's safe to modify the pure RGB values
6const brightenedRGB = straightAlphaColor.rgb.mul( 1.5 );