How to implement Drag Distortion Image filter in android?

前端 未结 1 838
感情败类
感情败类 2021-02-05 09:49

I am working on custom image filter project. And I came across one challenging task, in which I am supposed to apply distorted filters as can be seen in Funny face effect app. I

相关标签:
1条回答
  • 2021-02-05 09:59

    One way to achieve it is to use an additional texture to specify to the fragment shader the deformation to apply. You can modify that texture contents from the app as the user touches the image to apply deformations.

    GPUImageBulgeDistortionFilter extends GPUImageFilter which is designed to use only one texture.

    You'll need to duplicate the texture binding (glBindTexture) and assignation to the fragment shader (glUniform1i) in GPUImageFilter using 1 for the new texture (instead of 0). You'll need also to duplicate glGetUniformLocation and use other name instead of inputImageTexture, for example inputImageTexture2.

    Modify the fragment shader at GPUImageBulgeDistortionFilter or create a new class derived from GPUImageBulgeDistortionFilter to add "uniform sampler2D inputImageTexture2;\n" +

    Finally add code to use inputImageTexture2 texels to deform data at inputImageTexture in the same fragment shader.

    0 讨论(0)
提交回复
热议问题