简体   繁体   English

GPUImageSoftLightBlendFilter - 显示iOS图像中透明区域的黑色区域

[英]GPUImageSoftLightBlendFilter - show black area at transparent area in an image iOS

I have developed an iPhone application using GPUImage framework which includes extensive use of filters, blending images etc. 我使用GPUImage框架开发了一个iPhone应用程序,其中包括广泛使用过滤器,混合图像等。

Everything is working fine except GPUImageSoftLightBlendFilter as it shows black area at transparent area in an image. GPUImageSoftLightBlendFilter外,一切正常,因为它在图像的透明区域显示黑色区域。 Please reply if any one has faced a similar type of issue while implementing the same. 如果任何人在实施同样的问题时遇到类似问题,请回复。

Please find attached screenshot for more information. 有关更多信息,请参阅附件截图。

在此输入图像描述

I believe this is due to a divide-by-zero error in the fragment shader. 我相信这是由于片段着色器中的除零错误。 The current fragment shader code for this blend operation looks like this: 此混合操作的当前片段着色器代码如下所示:

mediump vec4 base = texture2D(inputImageTexture, textureCoordinate);
mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);

gl_FragColor = base * (overlay.a * (base / base.a) + (2.0 * overlay * (1.0 - (base / base.a)))) + overlay * (1.0 - base.a) + base * (1.0 - overlay.a);

As you can see, if the alpha channel of the base image (input 0) is zero, you'll get an error in the above. 如您所见,如果基本图像(输入0)的Alpha通道为零,您将在上面收到错误。 This leads to black output for those pixels. 这导致这些像素的黑色输出。

One potential solution for this would be to replace the above shader code with the following: 一个可能的解决方案是用以下内容替换上面的着色器代码:

 mediump vec4 base = texture2D(inputImageTexture, textureCoordinate);
 mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);

 lowp float alphaDivisor = base.a + step(base.a, 0.0); // Protect against a divide-by-zero blacking out things in the output
 gl_FragColor = base * (overlay.a * (base / alphaDivisor) + (2.0 * overlay * (1.0 - (base / alphaDivisor)))) + overlay * (1.0 - base.a) + base * (1.0 - overlay.a);

Try to replace your GPUImageSoftLightBlendFilter's shader code from the first section with the second and see if that removes the black region. 尝试使用第二部分替换第一部分中的GPUImageSoftLightBlendFilter着色器代码,并查看是否删除了黑色区域。 If that fixes this, I'll roll it into the main framework. 如果这解决了这个问题,我会将其推入主框架。

I believe this stems from the above filter attempting to correct for premultiplied alpha in input images, which I was going to look into removing. 我相信这源于上面的过滤器试图纠正输入图像中的预乘alpha,我将考虑去除。

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

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