【问题标题】:Seems like a bug in GPUImagePinchDistortionFilter. Can anyone provide a solution?似乎是 GPUImagePinchDistortionFilter 中的一个错误。任何人都可以提供解决方案吗?
【发布时间】:2013-07-25 08:20:09
【问题描述】:

我使用 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 );
 }

【问题讨论】:

    标签: ios xcode image filter gpuimage


    【解决方案1】:

    捏失真滤镜使用以下片段着色器:

     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() 函数修改上述内容,以更加渐进地缓解扭曲区域和正常区域之间的边界。如果你这样做,我很乐意接受一个拉取请求。

    【讨论】:

    • 嗨,Brad.. 感谢您将我引导至着色器区域。我做了修改,终于让它工作了。您可以在此问题的编辑中看到最终着色器。
    猜你喜欢
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 2020-09-19
    • 1970-01-01
    • 2014-10-17
    • 2018-06-03
    相关资源
    最近更新 更多