blendFunc method

Sets the blending factors used to combine source and destination pixels.




WebGLRenderingContext.blendFunc(sfactor, dfactor);


sfactor [in]

Type: Number

A multiplier for the source color. See below.

dfactor [in]

Type: Number

A multiplier for destination color. See below.

Return value

This method does not return a value.


The blending function is calculated like this: color(RGBA) = ((source color) * sfactor) + ((destination color) * dfactor). Values of colors are between 0 and 1 for each RGB value. Alpha values are between 1 (fully opaque) and 0 (fully transparent).

gl.ZERO0 0 0 0Multiply by all colors by 0.
gl.ONE1 1 1 1Multiplies all colors by 1.
gl.SRC_COLORRs Gs Bs AsMultiply by source color value.
gl.ONE_MINUS_SRC_COLOR(1-Rs) (1-Gs) (1-Bs) (1-As)Multiply by 1 minus each color value.
gl.DST_COLORRd Gd Bd AdMultiply by destination color value.
gl.ONE_MINUS_DST_COLOR(1-Rd) (1-Gd) (1-Bd) (1-Ad)Multiply by 1 minus each color value.
gl.SRC_ALPHAAs As As AsMultiply all colors by source alpha value.
gl.ONE_MINUS_SRC_ALPHA(1-As) (1-As) (1-As) (1-As)Multiply all colors by 1 minus source alpha value.
gl.DST_ALPHAAd Ad Ad AdMultiply all colors by source alpha value.
gl.ONE_MINUS_DST_ALPHA(1-Ad) (1-Ad) (1-Ad) (1-Ad)Multiply all colors by 1 minus destination alpha value.
gl.SRC_ALPHA_SATURATEmin(As, Ad) min(As,Ad) min(As,Ad) 1Multiply by the smaller of either source or destination alpha value.


WebGL errorDescription
gl.INVALID_ENUMIf the sfactor or the dfactor isn't one of the listed values.


See also