目录
零基础 OpenGL (ES) 学习路线推荐 : OpenGL (ES) 学习目录 >> OpenGL ES 基础
零基础 OpenGL (ES) 学习路线推荐 : OpenGL (ES) 学习目录 >> OpenGL ES 转场
零基础 OpenGL (ES) 学习路线推荐 : OpenGL (ES) 学习目录 >> OpenGL ES 特效
零基础 OpenGL (ES) 学习路线推荐 : OpenGL (ES) 学习目录 >> OpenGL ES 函数
零基础 OpenGL (ES) 学习路线推荐 : OpenGL (ES) 学习目录 >> OpenGL ES GPUImage 使用
零基础 OpenGL (ES) 学习路线推荐 : OpenGL (ES) 学习目录 >> OpenGL ES GLSL 编程
GPUImage 共 125 个滤镜, 分为四类
1、Color adjustments : 31 filters , 颜色处理相关
2、Image processing : 40 filters , 图像处理相关.
3、Blending modes : 29 filters , 混合模式相关.
4、Visual effects : 25 filters , 视觉效果相关.
GPUImageLanczosResamplingFilter 属于 GPUImage 图像视觉效果相关,用来处理**图像 Lanczos 重取样模糊效果**。shader 源码如下:
/******************************************************************************************/ //@Author:猿说编程 //@Blog(个人博客地址): www.codersrc.com //@File:IOS – OpenGL ES GPUImage 图像Lanczos重取样模糊效果 GPUImageLanczosResamplingFilter //@Time:2022/06/11 06:30 //@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累! /******************************************************************************************/ #if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE NSString *const kGPUImageLanczosFragmentShaderString = SHADER_STRING ( precision highp float; uniform sampler2D inputImageTexture; varying vec2 centerTextureCoordinate; varying vec2 oneStepLeftTextureCoordinate; varying vec2 twoStepsLeftTextureCoordinate; varying vec2 threeStepsLeftTextureCoordinate; varying vec2 fourStepsLeftTextureCoordinate; varying vec2 oneStepRightTextureCoordinate; varying vec2 twoStepsRightTextureCoordinate; varying vec2 threeStepsRightTextureCoordinate; varying vec2 fourStepsRightTextureCoordinate; // sinc(x) * sinc(x/a) = (a * sin(pi * x) * sin(pi * x / a)) / (pi^2 * x^2) // Assuming a Lanczos constant of 2.0, and scaling values to max out at x = +/- 1.5 void main() { lowp vec4 fragmentColor = texture2D(inputImageTexture, centerTextureCoordinate) * 0.38026; fragmentColor += texture2D(inputImageTexture, oneStepLeftTextureCoordinate) * 0.27667; fragmentColor += texture2D(inputImageTexture, oneStepRightTextureCoordinate) * 0.27667; fragmentColor += texture2D(inputImageTexture, twoStepsLeftTextureCoordinate) * 0.08074; fragmentColor += texture2D(inputImageTexture, twoStepsRightTextureCoordinate) * 0.08074; fragmentColor += texture2D(inputImageTexture, threeStepsLeftTextureCoordinate) * -0.02612; fragmentColor += texture2D(inputImageTexture, threeStepsRightTextureCoordinate) * -0.02612; fragmentColor += texture2D(inputImageTexture, fourStepsLeftTextureCoordinate) * -0.02143; fragmentColor += texture2D(inputImageTexture, fourStepsRightTextureCoordinate) * -0.02143; gl_FragColor = fragmentColor; } ); #else NSString *const kGPUImageLanczosFragmentShaderString = SHADER_STRING ( uniform sampler2D inputImageTexture; varying vec2 centerTextureCoordinate; varying vec2 oneStepLeftTextureCoordinate; varying vec2 twoStepsLeftTextureCoordinate; varying vec2 threeStepsLeftTextureCoordinate; varying vec2 fourStepsLeftTextureCoordinate; varying vec2 oneStepRightTextureCoordinate; varying vec2 twoStepsRightTextureCoordinate; varying vec2 threeStepsRightTextureCoordinate; varying vec2 fourStepsRightTextureCoordinate; // sinc(x) * sinc(x/a) = (a * sin(pi * x) * sin(pi * x / a)) / (pi^2 * x^2) // Assuming a Lanczos constant of 2.0, and scaling values to max out at x = +/- 1.5 void main() { vec4 fragmentColor = texture2D(inputImageTexture, centerTextureCoordinate) * 0.38026; fragmentColor += texture2D(inputImageTexture, oneStepLeftTextureCoordinate) * 0.27667; fragmentColor += texture2D(inputImageTexture, oneStepRightTextureCoordinate) * 0.27667; fragmentColor += texture2D(inputImageTexture, twoStepsLeftTextureCoordinate) * 0.08074; fragmentColor += texture2D(inputImageTexture, twoStepsRightTextureCoordinate) * 0.08074; fragmentColor += texture2D(inputImageTexture, threeStepsLeftTextureCoordinate) * -0.02612; fragmentColor += texture2D(inputImageTexture, threeStepsRightTextureCoordinate) * -0.02612; fragmentColor += texture2D(inputImageTexture, fourStepsLeftTextureCoordinate) * -0.02143; fragmentColor += texture2D(inputImageTexture, fourStepsRightTextureCoordinate) * -0.02143; gl_FragColor = fragmentColor; } ); #endif
使用 GPUImageLanczosResamplingFilter 完成图像 Lanczos 重取样模糊效果****,原图如下:
使用 GPUImageLanczosResamplingFilter 完成图像 Lanczos 重取样模糊效果****,效果如下:
OpenGL ES Demo 下载地址 : IOS – OpenGL ES GPUImage 图像 Lanczos 重取样模糊效果 GPUImageLanczosResamplingFilter
本文由博客 - 猿说编程 猿说编程 发布!