一.简介
GPUImage 共 125 个滤镜, 分为四类
1、Color adjustments : 31 filters , 颜色处理相关 2、Image processing : 40 filters , 图像处理相关. 3、Blending modes : 29 filters , 混合模式相关. 4、Visual effects : 25 filters , 视觉效果相关.
GPUImageVignetteFilter 属于 GPUImage 图像视觉效果相关,用来处理图片晕影扩散。shader 源码如下:
代码语言:javascript复制/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:IOS – OpenGL ES 图像晕影扩散 GPUImageVignetteFilter
//@Time:2022/05/28 06:30
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageVignetteFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;
varying highp vec2 textureCoordinate;
uniform lowp vec2 vignetteCenter;
uniform lowp vec3 vignetteColor;
uniform highp float vignetteStart;
uniform highp float vignetteEnd;
void main()
{
lowp vec4 sourceImageColor = texture2D(inputImageTexture, textureCoordinate);
lowp float d = distance(textureCoordinate, vec2(vignetteCenter.x, vignetteCenter.y));
lowp float percent = smoothstep(vignetteStart, vignetteEnd, d);
gl_FragColor = vec4(mix(sourceImageColor.rgb, vignetteColor, percent), sourceImageColor.a);
}
);
#else
NSString *const kGPUImageVignetteFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;
varying vec2 textureCoordinate;
uniform vec2 vignetteCenter;
uniform vec3 vignetteColor;
uniform float vignetteStart;
uniform float vignetteEnd;
void main()
{
vec4 sourceImageColor = texture2D(inputImageTexture, textureCoordinate);
float d = distance(textureCoordinate, vec2(vignetteCenter.x, vignetteCenter.y));
float percent = smoothstep(vignetteStart, vignetteEnd, d);
gl_FragColor = vec4(mix(sourceImageColor.rgb, vignetteColor, percent), sourceImageColor.a);
}
);
#endif
二.效果演示
使用**** GPUImageVignetteFilter **** 完成图片晕影扩散效果,原图:
** GPUImageVignetteFilter ** 完成图片晕影扩散效果:
三.源码下载
OpenGL ES Demo 下载地址 :IOS – OpenGL ES 图像晕影扩散 GPUImageVignetteFilter