
目錄

創(chuàng)新互聯(lián)是一家專業(yè)提供賽罕企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站設(shè)計(jì)、H5響應(yīng)式網(wǎng)站、小程序制作等業(yè)務(wù)。10年已為賽罕眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。
零基礎(chǔ) OpenGL (ES) 學(xué)習(xí)路線推薦 : OpenGL (ES) 學(xué)習(xí)目錄 >> OpenGL ES 基礎(chǔ)
零基礎(chǔ) OpenGL (ES) 學(xué)習(xí)路線推薦 : OpenGL (ES) 學(xué)習(xí)目錄 >> OpenGL ES 轉(zhuǎn)場(chǎng)
零基礎(chǔ) OpenGL (ES) 學(xué)習(xí)路線推薦 : OpenGL (ES) 學(xué)習(xí)目錄 >> OpenGL ES 特效
零基礎(chǔ) OpenGL (ES) 學(xué)習(xí)路線推薦 : OpenGL (ES) 學(xué)習(xí)目錄 >> OpenGL ES 函數(shù)
零基礎(chǔ) OpenGL (ES) 學(xué)習(xí)路線推薦 : OpenGL (ES) 學(xué)習(xí)目錄 >> OpenGL ES GPUImage 使用
零基礎(chǔ) OpenGL (ES) 學(xué)習(xí)路線推薦 : OpenGL (ES) 學(xué)習(xí)目錄 >> OpenGL ES GLSL 編程
GPUImage 共 125 個(gè)濾鏡, 分為四類
1、Color adjustments : 31 filters , 顏色處理相關(guān)
2、Image processing : 40 filters , 圖像處理相關(guān).
3、Blending modes : 29 filters , 混合模式相關(guān).
4、Visual effects : 25 filters , 視覺(jué)效果相關(guān).
GPUImageOverlayBlendFilter 屬于 GPUImage 圖像混合模式相關(guān),用于圖像疊加。shader 源碼如下:
/******************************************************************************************/
//@Author:猿說(shuō)編程
//@Blog(個(gè)人博客地址): www.codersrc.com
//@File:IOS – OpenGL ES GPUImage GPUImageOverlayBlendFilter
//@Time:2022/07/02 06:30
//@Motto:不積跬步無(wú)以至千里,不積小流無(wú)以成江海,程序人生的精彩需要堅(jiān)持不懈地積累!
/******************************************************************************************/
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageOverlayBlendFragmentShaderString = SHADER_STRING
(
varying highp vec2 textureCoordinate;
varying highp vec2 textureCoordinate2;
uniform sampler2D inputImageTexture;
uniform sampler2D inputImageTexture2;
void main()
{
mediump vec4 base = texture2D(inputImageTexture, textureCoordinate);
mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);
mediump float ra;
if (2.0 * base.r < base.a) {
ra = 2.0 * overlay.r * base.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);
} else {
ra = overlay.a * base.a - 2.0 * (base.a - base.r) * (overlay.a - overlay.r) + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);
}
mediump float ga;
if (2.0 * base.g < base.a) {
ga = 2.0 * overlay.g * base.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);
} else {
ga = overlay.a * base.a - 2.0 * (base.a - base.g) * (overlay.a - overlay.g) + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);
}
mediump float ba;
if (2.0 * base.b < base.a) {
ba = 2.0 * overlay.b * base.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);
} else {
ba = overlay.a * base.a - 2.0 * (base.a - base.b) * (overlay.a - overlay.b) + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);
}
gl_FragColor = vec4(ra, ga, ba, 1.0);
}
);
#else
NSString *const kGPUImageOverlayBlendFragmentShaderString = SHADER_STRING
(
varying vec2 textureCoordinate;
varying vec2 textureCoordinate2;
uniform sampler2D inputImageTexture;
uniform sampler2D inputImageTexture2;
void main()
{
vec4 base = texture2D(inputImageTexture, textureCoordinate);
vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);
float ra;
if (2.0 * base.r < base.a) {
ra = 2.0 * overlay.r * base.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);
} else {
ra = overlay.a * base.a - 2.0 * (base.a - base.r) * (overlay.a - overlay.r) + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);
}
float ga;
if (2.0 * base.g < base.a) {
ga = 2.0 * overlay.g * base.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);
} else {
ga = overlay.a * base.a - 2.0 * (base.a - base.g) * (overlay.a - overlay.g) + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);
}
float ba;
if (2.0 * base.b < base.a) {
ba = 2.0 * overlay.b * base.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);
} else {
ba = overlay.a * base.a - 2.0 * (base.a - base.b) * (overlay.a - overlay.b) + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);
}
gl_FragColor = vec4(ra, ga, ba, 1.0);
}
);
#endif
使用 GPUImageOverlayBlendFilter**,**源圖和目標(biāo)圖如下:
使用 GPUImageOverlayBlendFilter 效果如下:
OpenGL ES Demo 下載地址 : IOS OpenGL ES GPUImage 圖像疊加 GPUImageOverlayBlendFilter
本文由博客 - 猿說(shuō)編程 猿說(shuō)編程 發(fā)布!