GPUImage 共 125 个滤镜, 分为四类
1、Color adjustments : 31 filters , 颜色处理相关 2、Image processing : 40 filters , 图像处理相关. 3、Blending modes : 29 filters , 混合模式相关. 4、Visual effects : 25 filters , 视觉效果相关.
GPUImageStretchDistortionFilter 属于 GPUImage 图像视觉效果相关,用来处理图像哈哈镜。shader 源码如下:
/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:IOS – OpenGL ES 图像哈哈镜效果 GPUImageStretchDistortionFilter
//@Time:2022/06/02 06:30
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageStretchDistortionFragmentShaderString = SHADER_STRING
(
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform highp vec2 center;
void main()
{
highp vec2 normCoord = 2.0 * textureCoordinate - 1.0;
highp vec2 normCenter = 2.0 * center - 1.0;
normCoord -= normCenter;
mediump vec2 s = sign(normCoord);
normCoord = abs(normCoord);
normCoord = 0.5 * normCoord + 0.5 * smoothstep(0.25, 0.5, normCoord) * normCoord;
normCoord = s * normCoord;
normCoord += normCenter;
mediump vec2 textureCoordinateToUse = normCoord / 2.0 + 0.5;
gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse );
}
);
#else
NSString *const kGPUImageStretchDistortionFragmentShaderString = SHADER_STRING
(
varying vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform vec2 center;
void main()
{
vec2 normCoord = 2.0 * textureCoordinate - 1.0;
vec2 normCenter = 2.0 * center - 1.0;
normCoord -= normCenter;
vec2 s = sign(normCoord);
normCoord = abs(normCoord);
normCoord = 0.5 * normCoord + 0.5 * smoothstep(0.25, 0.5, normCoord) * normCoord;
normCoord = s * normCoord;
normCoord += normCenter;
vec2 textureCoordinateToUse = normCoord / 2.0 + 0.5;
gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse);
}
);
#endif
使用 **GPUImageStretchDistortionFilter** 完成图像哈哈镜效果,原图:
使用 **GPUImageStretchDistortionFilter 完成图像哈哈镜效果:
OpenGL ES Demo 下载地址 : IOS – OpenGL ES 图像凹面镜效果 GPUImagePinchDistortionFilter
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有