我一直在尝试在android-gpuimage
表面上下文中应用Mediacodec
库中使用的过滤器。到目前为止,我已成功使用仅需要一个额外纹理贴图的滤镜。但是,当我尝试应用至少需要两个的过滤器时,结果是蓝色或彩虹色的混乱。
以下问题涉及使用纹理查找过滤器和晕影过滤器的那个。
我使用的顶点着色器如下:
uniform mat4 uMVPMatrix;
uniform mat4 textureTransform;
attribute vec4 vPosition;
attribute vec4 vTexCoordinate;
varying vec2 v_TexCoordinate;
void main() {
gl_Position = uMVPMatrix * vPosition;
v_TexCoordinate = (textureTransform * vTexCoordinate).xy;
}
我使用的片段着色器如下:
#extension GL_OES_EGL_image_external : require
precision lowp float;
varying highp vec2 v_TexCoordinate;
uniform samplerExternalOES u_Texture; //MediaCodec decoder provided data
uniform sampler2D inputImageTexture2; //Amaro filter map
uniform sampler2D inputImageTexture3; //Common vignette map
void main()
{
vec3 texel = texture2D(u_Texture, v_TexCoordinate).rgb;
vec2 red = vec2(texel.r, 0.16666);
vec2 green = vec2(texel.g, 0.5);
vec2 blue = vec2(texel.b, 0.83333);
texel.rgb = vec3(
texture2D(inputImageTexture2, red).r,
texture2D(inputImageTexture2, green).g,
texture2D(inputImageTexture2, blue).b);
//After further research I found the problem is somewhere below
vec2 tc = (2.0 * v_TexCoordinate) - 1.0;
float d = dot(tc, tc);
vec2 lookup = vec2(d, texel.r);
texel.r = texture2D(inputImageTexture3, lookup).r;
lookup.y = texel.g;
texel.g = texture2D(inputImageTexture3, lookup).g;
lookup.y = texel.b;
texel.b = texture2D(inputImageTexture3, lookup).b;
//The problem is somewhere above
gl_FragColor = vec4(texel, 1.0);
}
这是不好的小插图地图的结果,还是与片段着色器的晕影应用程序部分有关?
编辑:
用于inputImageTexture2的纹理:
用于inputImageTexture3的纹理:
答案 0 :(得分:0)
结果我加载纹理很重要。
我目前加载纹理的代码:
public int loadColormap(final Bitmap colormap) {
IntBuffer textureIntBuf = IntBuffer.allocate(1);
GLES20.glGenTextures(1, textureIntBuf);
int textureHandle = textureIntBuf.get();
//if (textures[2] != 0) {
if (textureHandle != 0) {
//GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[2]);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, colormap, 0);
}
//if (textures[2] == 0) {
if (textureHandle == 0) {
throw new RuntimeException("Error loading texture.");
}
//return textures[2];
return textureHandle;
}
之前的版本使用了textures
数组,我用来从MediaCodec和水印加载数据。出于某种原因,如果我使用它而不是为每个纹理生成IntBuffer
,片段着色器中使用的纹理会混乱或者其他东西。