问题:当本相机上显示图像且包含辉光效果时,图像变为黑色

问题描述

解决。请在下面查看我的答案。

---------------------------

编辑3:

几乎解决了。请最后一推。 我尝试了Rabbid76建议的音阶和modulateGlow,并且蝴蝶是透明的。请看着椅子上的蝴蝶和地板上的大蝴蝶

enter image description here

这是原始图像(其中一个):

enter image description here

---------------------------

编辑2:

感谢Rabbid76,它几乎解决了! 左图显示了Rabbid76解决方案的当前结果。右图显示了预期的解决方案。如您所见,蝴蝶现在变得更轻\透明了。

enter image description here

---------------------------

编辑1:

我尝试添加建议的glBlendFunc,尽管它稍微影响了发光效果,但它没有帮助。我需要添加GLES20.glEnable(GLES20.GL_BLEND),因为认情况下它是禁用的。

---------------------------

我正在使用此存储库

https://github.com/MasayukiSuda/GPUVideo-android

它包含可以在相机上显示的滤镜。筛选器之一名为“ WATERMARK”。当我将此图像更改为具有发光效果的图像时,发光变为黑色。

图片位于:GPUVideo-android-master \ sample \ src \ main \ res \ drawable-nodpi \ sample_bitmap.png。为了触发问题,应将其更改为具有发光效果的图像。例如,我生成了以下图像:https://drive.google.com/file/d/1u8PtIftovPbXRLnI3OR9_1Kv37L5s96_/view?usp=sharing

您会看到白色发光效果变成黑色的问题:

the white glow effect becomes light black

只需运行该应用程序,单击“摄像机记录”,然后选择“肖像”,然后从左侧列表中选择“ WATERMARK”(从末尾起第5个)。不要忘记更改我提到的图像。

相关的类名为:GlWatermarkFilter。它扩展了包含下一个着色器的gloverlayFilter:

 private final static String FRAGMENT_SHADER =
        "precision mediump float;\n" +
                "varying vec2 vTextureCoord;\n" +
                "uniform lowp sampler2D sTexture;\n" +
                "uniform lowp sampler2D oTexture;\n" +
                "void main() {\n" +
                "   lowp vec4 textureColor = texture2D(sTexture,vTextureCoord);\n" +
                "   lowp vec4 textureColor2 = texture2D(oTexture,vTextureCoord);\n" +
                "   \n" +
                "   gl_FragColor = mix(textureColor,textureColor2,textureColor2.a);\n" +
                "}\n";

并且该类还包含以下设置:

GLES20.glGenTextures(1,textures,0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,textures[0]);

GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MIN_FILTER,GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MAG_FILTER,GLES20.GL_TEXTURE_WRAP_S,GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_WRAP_T,GLES20.GL_CLAMP_TO_EDGE);

此类扩展了GlFilter,其中包含:

protected static final String DEFAULT_VERTEX_SHADER =
        "attribute highp vec4 aPosition;\n" +
                "attribute highp vec4 aTextureCoord;\n" +
                "varying highp vec2 vTextureCoord;\n" +
                "void main() {\n" +
                "gl_Position = aPosition;\n" +
                "vTextureCoord = aTextureCoord.xy;\n" +
                "}\n";

protected static final String DEFAULT_FRAGMENT_SHADER =
        "precision mediump float;\n" +
                "varying highp vec2 vTextureCoord;\n" +
                "uniform lowp sampler2D sTexture;\n" +
                "void main() {\n" +
                "gl_FragColor = texture2D(sTexture,vTextureCoord);\n" +
                "}\n";

请帮助我找出解决方法。我知道这是关于半alpha问题的,而这台相机不知道要显示它。我的目标是录制带有发光蝴蝶的视频。

解决方法

最有可能的是,发光效果纹理的颜色通道在发光区域的边缘逐渐淡出。这意味着在发光区域边缘的纹理颜色通道具有从白色到黑色的渐变。如果是这种情况,则会错误地混合纹理。您需要将发光效果(textureColor2)添加到基本纹理(textureColor):

gl_FragColor = textureColor + textureColor2;

一个选项是通过其Alpha通道缩放发光效果纹理

gl_FragColor = textureColor + textureColor2 * textureColor2.a;

如果发光效果看起来太亮,则可以通过缩放发光纹理来降低发光效果:

float scale = 0.5;
gl_FragColor = textureColor + textureColor2 * scale;

或者您可以通过颜色纹理来调整发光效果:

vec4 modulateGlow = textureColor2 * textureColor;
gl_FragColor = textureColor + modulateGlow;
,

这解决了所有问题,因此请注意最后两行:

private final static String FRAGMENT_SHADER =
        "precision mediump float;\n" +
                "varying vec2 vTextureCoord;\n" +
                "uniform lowp sampler2D sTexture;\n" +
                "uniform lowp sampler2D oTexture;\n" +
                "void main() {\n" +
                "   lowp vec4 textureColor = texture2D(sTexture,vTextureCoord);\n" +
                "   lowp vec4 textureColor2 = texture2D(oTexture,vTextureCoord);\n" +
                "   lowp float alphaDivisor = textureColor2.a + step(textureColor2.a,0.0);\n" +
                "   gl_FragColor = vec4(mix(textureColor.rgb,textureColor2.rgb / alphaDivisor,textureColor2.a),textureColor.a);\n" +
                "}\n";