1

我正在尝试编写类似 photobooth ios 或 osx 应用程序中的挤压效果;我是着色器的新手,但我能够实现 GPUImage 库和一些着色器;然而,我所能获得的只是球面变形,最终结果与我想要实现的有点不同。

这是我从 #import "GPUImageBulgeDistortionFilter.h" 修改的一些代码

特别是我正在使用这段代码

    NSString *const kGPUImageBulgeDistortionFragmentShaderString = SHADER_STRING
    (
     varying highp vec2 textureCoordinate;

     uniform sampler2D inputImageTexture;

     uniform highp vec2 center;
     uniform highp float radius;
     uniform highp float scale;

     void main()
     {
         highp vec2 textureCoordinateToUse = textureCoordinate;
         highp float dist = distance(center, textureCoordinate);
         highp float PI = 3.14159265358979323846264;//stone added
         textureCoordinateToUse -= center;
        textureCoordinateToUse.x = 0.5+textureCoordinateToUse.x*cos(textureCoordinateToUse.x*PI/radius)*scale;
         textureCoordinateToUse.y = 0.5 + textureCoordinateToUse.y*cos(textureCoordinateToUse.y*PI/radius)*scale;


         gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse );

     }
    );

这段代码使用 cos 和 sin 和 PI,所以它肯定在球面范围内;任何让它更平坦的提示,中间有一个小的未拉伸部分都会有很大的帮助!

4

0 回答 0