2

I'm writing a small libGdx application that may be able to distort a face simulating hits (something similar to FaceSmash), but can't find what kind of filter should I apply, neither info about math algorithms to achieve something like a bulge effect.

I've started from SphereFilter on

http://www.jhlabs.com/

but definitely the effect is not what I'm looking for.

I'm aware of

Image Warping - Bulge Effect Algorithm

and

How to warp images in Android?

I've achieved to 'translate' the bulge effect mentioned on the first thread, but is relatively slow, and can't find the way to create bulges in a region, not the whole image.

The warp sample on Api demos (2nd thread) is really fast, and changes only part of the image, but is not exactly a bulge effect, and my image processing maths are far from understanding how could I modify the algorithm to change the effect.

I can feel I'm in the right direction, but I'm totally stuck. Any idea of how any of these algorithms could be modified in order to get 'local' bulges inside the image?

EDIT

Just found this thread.-

How can you apply distortions to a UIImage using OpenGL ES?

Not android, but looks promising. I'll give a try to OpenGL shaders and share (hopefully) a solution for my scenario.

4

1 回答 1

1

回答我自己的问题,我设法找到了一个使用shaders基于GPUImage框架的 OpenGL 的解决方案

生成的片段着色器看起来像这样。-

#ifdef GL_ES
    precision mediump float;
#endif

varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform float aspectRatio;
uniform vec2 center;
uniform float radius;
uniform float scale;

void main() 
{  
    vec2 textureCoordinateToUse = vec2(v_texCoords.x, (v_texCoords.y * aspectRatio + center.y - center.y * aspectRatio));
    float dist = distance(center, textureCoordinateToUse);
    textureCoordinateToUse = v_texCoords;
    if (dist < radius)
    {
        textureCoordinateToUse -= center;
        float percent = 1.0 - ((radius - dist) / radius) * scale;
        percent = percent * percent;
        textureCoordinateToUse = textureCoordinateToUse * percent;
        textureCoordinateToUse += center;
    }
    gl_FragColor = texture2D(u_texture, textureCoordinateToUse);
}

希望有人觉得它有帮助。

于 2013-07-19T11:33:41.500 回答