premultiplyAlpha
premultiplyAlpha
Converts a color from straight alpha format to premultiplied alpha format to ensure correct blending results in rendering.
Core Advantages
Its core value is ensuring physically correct blending of semi-transparent objects against a background, preventing common edge artifacts (like dark fringes) caused by alpha format mismatches.
Common Uses
Rendering textures with an alpha channel (e.g., PNGs)
Implementing custom color blending or post-processing
Outputting to a render target that expects a premultiplied format
How to adjust
This is a pure function whose behavior is determined by the input color's alpha value. When alpha is 1, the output is unchanged; when alpha is 0.5, the output RGB values are halved; when alpha is 0, the output RGB becomes zero.
Code Examples
1// Combine into a straight alpha color
2const straightAlphaColor = vec4( textureNode.rgb, textureNode.a.mul( opacityNode ) );
3
4// Convert using the premultiplyAlpha node
5const premultipliedColor = premultiplyAlpha( straightAlphaColor );