我正在编写一个小的libGdx
应用程序,可能会扭曲模拟命中的面部(类似于FaceSmash
),但无法找到我应该应用的过滤器类型,也不能有关数学算法的信息,以实现像膨胀效应。
我是从
的SphereFilter开始的但肯定效果不是我想要的。
我知道
Image Warping - Bulge Effect Algorithm
和
How to warp images in Android?
我已经实现了'翻译'第一个线程中提到的凸起效果,但速度相对较慢,无法找到在区域中创建凸起的方法,而不是整个图像。
Api demos
(第二个线程)上的warp示例非常快,并且只更改图像的一部分,但不是一个凸起效果,我的图像处理数学远非理解我怎么能修改算法改变效果。
我能感觉到我正朝着正确的方向前进,但我完全陷入困境。是否可以修改这些算法中的任何一种,以便在图像中获得“局部”凸起?
修改
刚刚找到这个帖子.-
How can you apply distortions to a UIImage using OpenGL ES?
不是安卓,但看起来很有希望。我将试一下OpenGL着色器并分享(希望)我的方案的解决方案。
答案 0 :(得分:1)
回答我自己的问题,我设法找到了一个基于GPUImage框架的OpenGL shaders
的解决方案
生成的片段着色器看起来像这样.-
#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);
}
希望有人觉得有帮助。