目录
- 一.简介
- 二.效果演示
- 三.源码下载
- 四.猜你喜欢
一.简介
GPUImage 共 125 个滤镜, 分为四类
1、Color adjustments : 31 filters , 颜色处理相关 2、Image processing : 40 filters , 图像处理相关. 3、Blending modes : 29 filters , 混合模式相关. 4、Visual effects : 25 filters , 视觉效果相关.
GPUImageHighlightShadowFilter 属于 GPUImage 颜色处理相关,用来处理图片阴影,shader 源码如下:
代码语言:javascript复制/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:IOS – OpenGL ES 调节图像阴影 GPUImageHighlightShadowFilter
//@Time:2022/03/17 07:30
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageHighlightShadowFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;
varying highp vec2 textureCoordinate;
uniform lowp float shadows;
uniform lowp float highlights;
const mediump vec3 luminanceWeighting = vec3(0.3, 0.3, 0.3);
void main()
{
lowp vec4 source = texture2D(inputImageTexture, textureCoordinate);
mediump float luminance = dot(source.rgb, luminanceWeighting);
mediump float shadow = clamp((pow(luminance, 1.0/(shadows 1.0)) (-0.76)*pow(luminance, 2.0/(shadows 1.0))) - luminance, 0.0, 1.0);
mediump float highlight = clamp((1.0 - (pow(1.0-luminance, 1.0/(2.0-highlights)) (-0.8)*pow(1.0-luminance, 2.0/(2.0-highlights)))) - luminance, -1.0, 0.0);
lowp vec3 result = vec3(0.0, 0.0, 0.0) ((luminance shadow highlight) - 0.0) * ((source.rgb - vec3(0.0, 0.0, 0.0))/(luminance - 0.0));
gl_FragColor = vec4(result.rgb, source.a);
}
);
#else
NSString *const kGPUImageHighlightShadowFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;
varying vec2 textureCoordinate;
uniform float shadows;
uniform float highlights;
const vec3 luminanceWeighting = vec3(0.3, 0.3, 0.3);
void main()
{
vec4 source = texture2D(inputImageTexture, textureCoordinate);
float luminance = dot(source.rgb, luminanceWeighting);
float shadow = clamp((pow(luminance, 1.0/(shadows 1.0)) (-0.76)*pow(luminance, 2.0/(shadows 1.0))) - luminance, 0.0, 1.0);
float highlight = clamp((1.0 - (pow(1.0-luminance, 1.0/(2.0-highlights)) (-0.8)*pow(1.0-luminance, 2.0/(2.0-highlights)))) - luminance, -1.0, 0.0);
vec3 result = vec3(0.0, 0.0, 0.0) ((luminance shadow highlight) - 0.0) * ((source.rgb - vec3(0.0, 0.0, 0.0))/(luminance - 0.0));
gl_FragColor = vec4(result.rgb, source.a);
}
);
#endif
二.效果演示
三.源码下载
下载地址 : IOS – OpenGL ES 调节图像阴影 GPUImageHighlightShadowFilter