设为首页 加入收藏

TOP

IOS OpenGL ES GPUImage 图像混合 GPUImageNormalBlendFilter(一)
2023-07-23 13:26:00 】 浏览:67
Tags:IOS OpenGL GPUImage GPUImageNormalBlendFilter

目录

零基础 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 , 视觉效果相关.

GPUImageNormalBlendFilter 属于 GPUImage 图像混合模式相关,用于图像 alpha 混合。shader 源码如下:

/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:IOS – OpenGL ES GPUImage GPUImageNormalBlendFilter
//@Time:2022/07/02 06:30
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageNormalBlendFragmentShaderString = SHADER_STRING
(
 varying highp vec2 textureCoordinate;
 varying highp vec2 textureCoordinate2;

 uniform sampler2D inputImageTexture;
 uniform sampler2D inputImageTexture2;

 void main()
 {
     lowp vec4 c2 = texture2D(inputImageTexture, textureCoordinate);
	 lowp vec4 c1 = texture2D(inputImageTexture2, textureCoordinate2);

     lowp vec4 outputColor;

//     outputColor.r = c1.r + c2.r * c2.a * (1.0 - c1.a);
//     outputColor.g = c1.g + c2.g * c2.a * (1.0 - c1.a);
//     outputColor.b = c1.b + c2.b * c2.a * (1.0 - c1.a);
//     outputColor.a = c1.a + c2.a * (1.0 - c1.a);

     lowp float a = c1.a + c2.a * (1.0 - c1.a);
     lowp float alphaDivisor = a + step(a, 0.0); // Protect against a divide-by-zero blacking out things in the output

     outputColor.r = (c1.r * c1.a + c2.r * c2.a * (1.0 - c1.a))/alphaDivisor;
     outputColor.g = (c1.g * c1.a + c2.g * c2.a * (1.0 - c1.a))/alphaDivisor;
     outputColor.b = (c1.b * c1.a + c2.b * c2.a * (1.0 - c1.a))/alphaDivisor;
     outputColor.a = a;

     gl_FragColor = outputColor;
 }
);
#else
NSString *const kGPUImageNormalBlendFragmentShaderString = SHADER_STRING
(
 varying vec2 textureCoordinate;
 varying vec2 textureCoordinate2;

 uniform sampler2D inputImageTexture;
 uniform sampler2D inputImageTexture2;

 void main()
 {
     vec4 c2 = texture2D(inputImageTexture, textureCoordinate);
	 vec4 c1 = texture2D(inputImageTexture2, textureCoordinate2);

     vec4 outputColor;

     //     outputColor.r = c1.r + c2.r * c2.a * (1.0 - c1.a);
     //     outputColor.g = c1.g + c2.g * c2.a * (1.0 - c1.a);
     //     outputColor.b = c1.b + c2.b * c2.a * (1.0 - c1.a);
     //     outputColor.a = c1.a + c2.a * (1.0 - c1.a);

     float a = c1.a + c2.a * (1.0 - c1.a);
     float alphaDivisor = a + step(a, 0.0); // Protect against a divide-by-zero blacking out things in the output

     outputColor.r = (c1.r * c1.a + c2.r * c2.a * (1.0 - c1.a))/alphaDivisor;
     outputColor.g = (c1.g * c1.a + c2.g * c2.a * (1.0 - c1.a))/alphaDivisor;
     outputColor.b = (c1.b * c1.a + c2.b * c2.a * (1.0 - c1.a))/alphaDivisor;
     outputColor.a = a;

     gl_FragColor = outputColor;
 }
);
#endif

二.效果演示

使用**GPUImageNormalBlendFilter,**源图和目标图如下:

使用GPUImageNormalBlendFilter 效果如下:

三.源码下载

OpenGL ES Demo 下载地址 : IOS OpenGL ES GPUImage 图像混合 GPUImageNormalBlendFilter

四.猜你喜欢

  1. IOS OPenGL ES 设置图像亮度 GPUImageBrightnessFilter
  2. IO
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C语言循环打印空心正方形代码实现 下一篇C语言-值传递、地址传递与引用

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目