Closed Rehamgalal closed 5 years ago
In your case, the error may be caused by the incompatibility of Vertex Shader and Fragment Shader. To solve this kind of problem, you should check each varying
field name carefully (Probably change from textureCoordinate
to vTextureCoord
) and make sure it's the same in both Vertex and Fragment shader. Another thing is that GlFilter
texture uniform field is sTexture
make sure you changed to everywhere in your new shader, and replace all inputImageTexture
to sTexture
.
I wrote and changed quite a few stuff here. Please take a look that might help you!
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLES20;
import android.util.SparseIntArray;
import com.daasuu.mp4compose.filter.GlFilter;
import com.daasuu.mp4compose.utils.EglUtil;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
abstract class IFVideoFilter extends GlFilter {
private final String[] textureHandleNames = new String[] {
"inputImageTexture2",
"inputImageTexture3",
"inputImageTexture4",
"inputImageTexture5",
"inputImageTexture6"
};
protected final Context context;
protected final ArrayList<Integer> textureResourceIds = new ArrayList<>();
protected final SparseIntArray texturesMap = new SparseIntArray();
protected final Queue<Runnable> preDrawRunnables = new LinkedList<>();
public IFVideoFilter(
final Context context,
final String fragmentShaderSource)
{
super(GlFilter.DEFAULT_VERTEX_SHADER, fragmentShaderSource);
this.context = context;
preDrawRunnables.add(this::initTextures);
}
@Override
protected void onDraw() {
while (!preDrawRunnables.isEmpty()) preDrawRunnables.poll().run();
for (int i = 0; i < texturesMap.size(); i++) {
final int uniformLocation = texturesMap.keyAt(i);
final int textureId = texturesMap.get(uniformLocation);
if (textureId != EglUtil.NO_TEXTURE) {
GLES20.glActiveTexture(GLES20.GL_TEXTURE3 + i);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
GLES20.glUniform1i(uniformLocation, 3 + i);
}
}
}
private void initTextures() {
for (int i = 0; i < textureHandleNames.length; i++) {
if (textureResourceIds.size() > i) {
int textureId;
final int textureLocation = getHandle(textureHandleNames[i]);
final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
textureResourceIds.get(i));
textureId = EglUtil.loadTexture(bitmap, EglUtil.NO_TEXTURE, true);
texturesMap.put(textureLocation, textureId);
}
}
}
}
Implementation Example of IFLomoFilter
import android.content.Context;
public class IFLomoFilter extends IFVideoFilter {
private static final String SHADER = "precision lowp float;\n" +
" \n" +
" varying highp vec2 vTextureCoord;\n" +
" \n" +
" uniform sampler2D sTexture;\n" +
" uniform sampler2D inputImageTexture2;\n" +
" uniform sampler2D inputImageTexture3;\n" +
" \n" +
" void main()\n" +
" {\n" +
" \n" +
" vec3 texel = texture2D(sTexture, vTextureCoord).rgb;\n" +
" \n" +
" vec2 red = vec2(texel.r, 0.16666);\n" +
" vec2 green = vec2(texel.g, 0.5);\n" +
" vec2 blue = vec2(texel.b, 0.83333);\n" +
" \n" +
" texel.rgb = vec3(\n" +
" texture2D(inputImageTexture2, red).r,\n" +
" texture2D(inputImageTexture2, green).g,\n" +
" texture2D(inputImageTexture2, blue).b);\n" +
" \n" +
" vec2 tc = (2.0 * vTextureCoord) - 1.0;\n" +
" float d = dot(tc, tc);\n" +
" vec2 lookup = vec2(d, texel.r);\n" +
" texel.r = texture2D(inputImageTexture3, lookup).r;\n" +
" lookup.y = texel.g;\n" +
" texel.g = texture2D(inputImageTexture3, lookup).g;\n" +
" lookup.y = texel.b;\n" +
" texel.b\t= texture2D(inputImageTexture3, lookup).b;\n" +
" \n" +
" gl_FragColor = vec4(texel,1.0);\n" +
" }\n";
public IFLomoFilter(Context context) {
super(context, SHADER);
textureResourceIds.add(R.drawable.lomo_map);
textureResourceIds.add(R.drawable.vignette_map);
}
}
@seanghay thank you it's working you saved my time
the same library for images is applying Instagram video i"m trying to apply them on the library like these 👍 https://github.com/imrunning/android-instagram-image-filter/tree/master/instagramfilter/src/main/java/jp/co/cyberagent/android/gpuimage/sample/filter
I'm trying to apply the IFImageFilter class for video like here
i get error java.lang.RuntimeException: Could not link program Player is accessed on the wrong thread.