WebGLRenderingContext.blendFuncSeparate() - Web APIs 编辑

The WebGLRenderingContext.blendFuncSeparate() method of the WebGL API defines which function is used for blending pixel arithmetic for RGB and alpha components separately.

Syntax

void gl.blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);

Parameters

srcRGB
A GLenum specifying a multiplier for the red, green and blue (RGB) source blending factors. The default value is gl.ONE. For possible values, see below.
dstRGB
A GLenum specifying a multiplier for the red, green and blue (RGB) destination blending factors. The default value is gl.ZERO. For possible values, see below.
srcAlpha
A GLenum specifying a multiplier for the alpha source blending factor. The default value is gl.ONE. For possible values, see below.
dstAlpha
A GLenum specifying a multiplier for the alpha destination blending factor. The default value is gl.ZERO. For possible values, see below.

Return value

None.

Exceptions

  • If srcRGB, dstRGB, srcAlpha, or dstAlpha is not one of the listed possible values, a gl.INVALID_ENUM error is thrown.
  • If a constant color and a constant alpha value are used together as source (srcRGB) and destination (dstRGB) factors, a gl.INVALID_ENUM error is thrown.

Constants

The following constants can be used for srcRGB, dstRGB, srcAlpha, and dstAlpha

The formulas for the blending factors can be described like this (all RGBA values are between 0 and 1):

  • color(RGB) = (sourceColor * srcRGB) + (destinationColor * dstRGB)
  • color(A) = (sourceAlpha * srcAlpha) + (destinationAlpha * dstAlpha)
ConstantRGB factorAlpha factorDescription
gl.ZERO0,0,00Multiplies all colors by 0.
gl.ONE1,1,1,11Multiplies all colors by 1.
gl.SRC_COLORRS, GS, BSASMultiplies all colors by the source colors.
gl.ONE_MINUS_SRC_COLOR1-RS, 1-GS, 1-BS1-ASMultiplies all colors by 1 minus each source color.
gl.DST_COLORRD, GD, BDADMultiplies all colors by the destination color.
gl.ONE_MINUS_DST_COLOR1-RD, 1-GD, 1-BD1-ADMultiplies all colors by 1 minus each destination color.
gl.SRC_ALPHAAS, AS, ASASMultiplies all colors by the source alpha color.
gl.ONE_MINUS_SRC_ALPHA1-AS, 1-AS, 1-AS1-ASMultiplies all colors by 1 minus the source alpha color.
gl.DST_ALPHAAD, AD, ADADMultiplies all colors by the destination alpha color.
gl.ONE_MINUS_DST_ALPHA1-AD, 1-AD, 1-AD1-ADMultiplies all colors by 1 minus the destination alpha color.
gl.CONSTANT_COLORRC, GC, BCACMultiplies all colors by a constant color.
gl.ONE_MINUS_CONSTANT_COLOR1-RC, 1-GC, 1-BC1-ACMultiplies all colors by 1 minus a constant color.
gl.CONSTANT_ALPHAAC, AC, ACACMultiplies all colors by a constant alpha value.
gl.ONE_MINUS_CONSTANT_ALPHA1-AC, 1-AC, 1-AC1-ACMultiplies all colors by 1 minus a constant alpha value.
gl.SRC_ALPHA_SATURATE

min(AS, 1 - AD), min(AS, 1 - AD), min(AS, 1 - AD)

1Multiplies the RGB colors by the smaller of either the source alpha color or the value of 1 minus the destination alpha color. The alpha value is multiplied by 1.

Examples

To use the blend function, you first have to activate blending with WebGLRenderingContext.enable() with the argument gl.BLEND.

gl.enable(gl.BLEND);
gl.blendFuncSeparate(gl.SRC_COLOR, gl.DST_COLOR, gl.ONE, gl.ZERO);

To get the current blend function, query the BLEND_SRC_RGB, BLEND_SRC_ALPHA, BLEND_DST_RGB, and BLEND_DST_ALPHA constants which return one of the blend function constants.

gl.enable(gl.BLEND);
gl.blendFuncSeparate(gl.SRC_COLOR, gl.DST_COLOR, gl.ONE, gl.ZERO);
gl.getParameter(gl.BLEND_SRC_RGB) == gl.SRC_COLOR;
// true

Specifications

SpecificationStatusComment
WebGL 1.0
The definition of 'blendFunc' in that specification.
RecommendationInitial definition.
In WebGL, constant color and constant alpha cannot be used together as source and destination factors in the blend function. See section 6.13. of the specification.
OpenGL ES 2.0
The definition of 'glBlendFunc' in that specification.
StandardMan page of the OpenGL API.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:93 次

字数:9115

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文