blendColor
Performs standard 'Normal' alpha blending to correctly composite a color with transparency (alpha channel) over a base color.
Core Advantages
Encapsulates the standard, complex blending formula, including premultiplied alpha handling, which ensures correct transparency processing, prevents common artifacts at transparent edges, and greatly simplifies shader logic.
Common Uses
Applying decals or logos with transparent backgrounds onto surfaces.
Layering different materials, like rust on metal, using a mask.
Rendering semi-transparent VFX (like smoke particles) or 3D UI elements.
Creating fade-in/fade-out animations by dynamically changing the alpha value.
How to adjust
The effect is entirely controlled by the alpha channel of the `blend` input (`blend.a`). When `blend.a` is 0, the `base` color is shown. When `blend.a` is 1, the `blend` color fully covers the `base`. Values between 0 and 1 create a semi-transparent overlay. This is often controlled by a mask texture to precisely define where the blend effect occurs.
Code Examples
1// Use a mask texture to blend a semi-transparent puddle color onto dry ground
2const finalResult = blendColor(
3 dryGroundTexture, // base: vec4
4 vec4( waterColor.rgb, waterColor.a * puddleMask.r ) // blend: vec4
5);