Alpha的奇怪行为而未在WebGL中融合 [英] Strange behavior of alpha without blending in WebGL
问题描述
我发现在关闭混合功能的情况下,WebGL呈现奇怪的行为.我在这个最简单的教程上进行了复制. 只需更改字符串即可:
I found strange behavior of WebGL when it is rendering with blending turned off. I reproduced it on this simplest tutorial. Just change strings:
gl_FragColor = vec4(1.0,1.0,1.0,1.0); 到 gl_FragColor = vec4(0.0,0.0,0.0,0.5);
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); to gl_FragColor = vec4(0.0, 0.0, 0.0, 0.5);
和 gl.clearColor(0.0,0.0,0.0,1.0); 到 gl.clearColor(1.0,1.0,1.0,1.0);
and gl.clearColor(0.0, 0.0, 0.0, 1.0); to gl.clearColor(1.0, 1.0, 1.0, 1.0);
因此,由于关闭了混合功能,因此我应该在白色背景上看到黑色形状(像素的alpha 0.5不应产生影响).但我在白色背景上看到灰色的形状.我相信我错过了一些东西,但是我无法理解.有什么想法吗?
So, since blending is turned off, I supposed to see black shapes on white background (alpha 0.5 of the pixel shouldn't make influence). But I see gray shapes on white backgound. I believe I missed something, but I can't undertand what. Any ideas?
P.S. gl.disable(gl.BLEND)不会改变结果.
P.S. gl.disable(gl.BLEND) doesn't change the result.
推荐答案
在这里基本上已经回答了
This is basically already answered here
您看到的是,默认情况下,WebGL画布与背景混合在一起.画布的背景色或它的子级. HTML的默认背景颜色是白色,因此如果使用[0.0、0.0、0.0、0.5]进行绘制,则50%的alpha黑色与白色网页混合在一起.
What you're seeing is that WebGL canvases are, by default, blended with the background. Either the background color of the canvas or whatever it's a child of. The default background color for HTML is white so if you draw with [0.0, 0.0, 0.0, 0.5] that's 50% alpha black blended with the white webpage.
有关修复方法,请参见上面的链接.
See the link above for how to fix it.
这篇关于Alpha的奇怪行为而未在WebGL中融合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!