Three.js Material Blending Property Explained
This article explains the purpose and functionality of the
blending property in Three.js materials. You will learn how
this property controls how overlapping colors and transparent objects
mix together on the screen, the different blending modes available, and
how to apply them to achieve realistic visual effects like glows,
shadows, and custom particle systems.
In Three.js, the blending property determines how the
pixels of a newly rendered object (the source) combine with the pixels
already present in the WebGL frame buffer (the destination). By default,
WebGL simply overwrites background pixels with foreground pixels based
on their opacity. However, by configuring the blending
property on a material, you can instruct the renderer to perform
mathematical calculations to merge these colors, which is essential for
rendering transparent surfaces, light beams, fire, and other complex
visual effects.
Three.js provides several built-in blending modes through the
THREE namespace:
THREE.NormalBlending(Default): This mode uses the alpha (transparency) channel of the source material to blend it with the background. If an object is 50% transparent, you will see 50% of its color mixed with 50% of the background color.THREE.AdditiveBlending: This mode adds the color values of the source object directly to the destination colors. Because adding color values moves them closer to white, this mode is ideal for glowing effects, fire, lasers, and particle engines.THREE.SubtractiveBlending: This mode subtracts the source color values from the destination colors. This results in a darkening effect, making it useful for creating dark smoke, shadows, or inverse-color artistic effects.THREE.MultiplyBlending: This mode multiplies the source and destination color values. Since color values are represented between 0 and 1, multiplication always results in a color that is as dark as or darker than the original colors, mimicking how real-world filters or pigments mix.THREE.NoBlending: This disables all blending calculations. The source object completely overwrites any existing pixels behind it, ignoring transparency entirely. This is highly efficient and useful for fully opaque background elements.
For advanced rendering needs, Three.js also supports custom blending.
By setting the blending property to
THREE.CustomBlending, developers can gain precise control
over the mathematical equations used by the GPU. This is configured
using additional material properties such as blendEquation,
blendSrc, and blendDst, allowing you to define
exactly how the red, green, blue, and alpha channels interact during the
rendering pipeline.