简体   繁体   English

点精灵Alpha混合

[英]Point Sprite Alpha Blending

I'm working on a paint app for Android that allows users to draw using their finger. 我正在开发适用于Android的绘画应用程序,该应用程序允许用户使用手指进行绘制。 It's built using OpenGL ES 2.0 using point sprite technique as well as an FBO for quick rendering. 它是使用OpenGL ES 2.0,点精灵技术以及用于快速渲染的FBO构建的。 I am having an issue blending the individual point sprites together where the transparent regions are correctly rendered on the FBO but when the sprites overlap I can see the transparent areas being rendered on the previous sprite. 我在将单个点精灵混合在一起时遇到问题,这些地方透明的区域正确地在FBO上渲染,但是当精灵重叠时,我可以看到在先前的精灵上渲染了透明区域。 Here's how it looks currently: 当前的外观如下:

在此处输入图片说明

This is with this blending equation: 这是这个混合方程式:

GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);

If I change the drawing color to white or black it works perfectly: 如果我将绘图颜色更改为白色或黑色,则效果很好:

在此处输入图片说明

I've also tried this blending function: 我也尝试过此混合功能:

GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_DST_ALPHA);

Which results in this: 结果是:

在此处输入图片说明

Which is almost perfect but instead to white the main color should darken. 这几乎是完美的选择,但改为白色时,主色应变暗。 Any ideas on what the correct blending function should be to achieve this? 关于实现此目标的正确混合功能有什么想法?

Note: I have an idea of how the blending function works by taking fractions of the source and destination color and in my case adding them together so it makes sense that the color would go towards white. 注意:我对混合功能的工作方式有所了解,方法是将源和目标颜色的一部分取整,然后将它们加在一起,这样颜色就趋于白色是有意义的。 So I'm wondering if what I would like to achieve can be done with blending function only or would I need something else? 所以我想知道我想实现的目标是仅使用混合功能还是需要其他功能? I can provide code from the fragment shader if necessary but it doesn't look like a fragment problem to me. 如有必要,我可以从片段着色器提供代码,但对我来说,这看起来好像不是片段问题。

Okay so I found out what was wrong. 好的,所以我找出了问题所在。 It wasn't the blending function after all but the fragment shader.. I had some logic to unpremultiply the pixels which was redundant as the blending function 毕竟不是混合功能,而是片段着色器。.我有一些逻辑可以对像素进行预乘,这是冗余的混合功能

GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);

already handles premultiplied images. 已经处理了预乘图像。 In addition to that, I had some code in the fragment shader to convert the image to grayscale and then to convert the grayscale into transparency and my color multiplications were wrong. 除此之外,我在片段着色器中有一些代码将图像转换为灰度,然后将灰度转换为透明度,并且我的颜色乘法是错误的。

Finally I ended up leaving my original blending function unchanged (as above). 最终,我保留了原来的混合功能不变(如上所述)。 It works properly and here's the result I was looking for: 它可以正常工作,这是我一直在寻找的结果:

在此处输入图片说明

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

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