简体   繁体   English

颜色在OpenGL ES中无法正确混合

[英]Colors not blending properly in OpenGL ES

I'm trying to render 2 (light) circles in OpenGL ES in 2D. 我正在尝试在OpenGL ES中以2D渲染2个(浅色)圆。 The middle is white, the border is black. 中间是白色,边框是黑色。 It works fine, as long as they don't overlap: 只要它们不重叠,就可以正常工作:

在此处输入图片说明

But as soon as they do, I get this artifact: 但是一旦他们这样做,我就会得到以下结果:

在此处输入图片说明

I'm using glBlendFunc(GL_ONE, GL_ONE) with blending enabled of course. 我正在使用glBlendFunc(GL_ONE, GL_ONE)启用混合功能。

What could be causing this? 是什么原因造成的? Is there a way to fix it? 有办法解决吗?

I'd like them to blend more like this: 我希望他们像这样融合更多:

在此处输入图片说明

Thanks! 谢谢!

Are your circles currently linear gradients? 您的圈子目前是线性渐变吗? You might get less of an artifact if you have a different curve. 如果您具有不同的曲线,则可能会减少伪影。

Based on your example, though, it looks like you want the maximum intensity of the two circles, not the sum of the intensities. 但是,根据您的示例,您似乎想要两个圆的最大强度,而不是强度的总和。 It appears that Apple's OpenGL ES 2.0 implementation support the EXT_blend_minmax extension, which lets you specify that the resulting fragment values should be the maximum of the inbound and existing values. 看来Apple的OpenGL ES 2.0实现支持EXT_blend_minmax扩展,它使您可以指定结果片段值应为入站值和现有值的最大值。 Maybe try that? 也许尝试一下?

The result you're seeing is exactly what should come out for linear gradients. 您看到的结果恰好是线性渐变的结果。 Hint: Open up Photoshop or The GIMP draw two radial gradients into two layers and set them to "Addition" blending mode. 提示:打开Photoshop或GIMP将两个径向渐变绘制成两层并将其设置为“添加”混合模式。 It will look exactly like your picture. 它看起来和您的图片完全一样。

A effect like what you desire is given with square gradients. 正方形渐变会给您像您想要的效果一样的效果。 If your gradient is in the range 0…1 take the square of the value and draw this. 如果您的梯度在0…1范围内,则取该值的平方并绘制。 You may apply a sqrt later if you want to linearize the single gradients. 如果要线性化单个渐变,可以稍后再应用sqrt。

Not that this is something not easily done using the blending stage; 这并不是说使用混合阶段不容易做到; it can be done using multiple passes, but then it's actually more straightforward to use a shader to combine passed from two FBOs. 可以使用多次传递完成此操作,但是使用着色器组合从两个FBO传递来的传递实际上更为简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM