我使用Brad Larson的GPUImage库。
GPUImageBulgeDistortionFilter可以很好地处理图像。但GPUImagePinchDistortion滤镜在圆形剪切中渲染原始图像的效果。这不能与原始图像平滑混合。
任何人都可以为此提供解决方案吗?
好的,解决了..以下是最终着色器,以实现捏合效果的平滑混合..
highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
highp float dist = distance(center, textureCoordinateToUse);
textureCoordinateToUse = textureCoordinate;
if (dist < radius)
{
textureCoordinateToUse -= center;
highp float percent = 1.0 + ((0.5 - dist) / 0.5) * scale;
textureCoordinateToUse = textureCoordinateToUse * percent;
textureCoordinateToUse += center;
//modification start
highp vec2 textureCoordinateDiff = textureCoordinate - textureCoordinateToUse;
textureCoordinateToUse = textureCoordinateToUse + textureCoordinateDiff*(dist/radius);
//modification end
gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse );
}
else
{
gl_FragColor = texture2D(inputImageTexture, textureCoordinate );
}
答案 0 :(得分:2)
捏合失真滤波器使用以下片段着色器:
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform highp float aspectRatio;
uniform highp vec2 center;
uniform highp float radius;
uniform highp float scale;
void main()
{
highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
highp float dist = distance(center, textureCoordinateToUse);
textureCoordinateToUse = textureCoordinate;
if (dist < radius)
{
textureCoordinateToUse -= center;
highp float percent = 1.0 + ((0.5 - dist) / 0.5) * scale;
textureCoordinateToUse = textureCoordinateToUse * percent;
textureCoordinateToUse += center;
gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse );
}
else
{
gl_FragColor = texture2D(inputImageTexture, textureCoordinate );
}
}
从中可以看出,当从效果的中心点到当前像素的距离小于效果的半径到大于该效果的半径时,存在明显的区别。这导致了扭曲区域和普通图像之间的边缘。
如果您希望它具有更多渐进效果,可以使用smoothstep()
函数修改上述内容,以逐渐缓解失真区域和正常区域之间的边界。如果你这样做,我很乐意接受这种拉动请求。