目錄
“專業(yè)、務(wù)實(shí)、高效、創(chuàng)新、把客戶的事當(dāng)成自己的事”是我們每一個(gè)人一直以來堅(jiān)持追求的企業(yè)文化。 創(chuàng)新互聯(lián)建站是您可以信賴的網(wǎng)站建設(shè)服務(wù)商、專業(yè)的互聯(lián)網(wǎng)服務(wù)提供商! 專注于成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、軟件開發(fā)、設(shè)計(jì)服務(wù)業(yè)務(wù)。我們始終堅(jiān)持以客戶需求為導(dǎo)向,結(jié)合用戶體驗(yàn)與視覺傳達(dá),提供有針對(duì)性的項(xiàng)目解決方案,提供專業(yè)性的建議,創(chuàng)新互聯(lián)建站將不斷地超越自我,追逐市場(chǎng),引領(lǐng)市場(chǎng)!
零基礎(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 , 視覺效果相關(guān).
GPUImageThresholdEdgeDetectionFilter 屬于 GPUImage 圖像視覺效果相關(guān),用于圖像閾值邊緣檢測(cè)。shader 源碼如下:
/******************************************************************************************/
//@Author:猿說編程
//@Blog(個(gè)人博客地址): www.codersrc.com
//@File:IOS – OpenGL ES GPUImage GPUImageThresholdEdgeDetectionFilter
//@Time:2022/06/26 06:30
//@Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅(jiān)持不懈地積累!
/******************************************************************************************/
// Invert the colorspace for a sketch
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageThresholdEdgeDetectionFragmentShaderString = SHADER_STRING
(
precision highp float;
varying vec2 textureCoordinate;
varying vec2 leftTextureCoordinate;
varying vec2 rightTextureCoordinate;
varying vec2 topTextureCoordinate;
varying vec2 topLeftTextureCoordinate;
varying vec2 topRightTextureCoordinate;
varying vec2 bottomTextureCoordinate;
varying vec2 bottomLeftTextureCoordinate;
varying vec2 bottomRightTextureCoordinate;
uniform sampler2D inputImageTexture;
uniform lowp float threshold;
uniform float edgeStrength;
void main()
{
// float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
// float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;
// float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
// float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;
float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;
float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;
float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;
float centerIntensity = texture2D(inputImageTexture, textureCoordinate).r;
// float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
// float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;
// float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + leftIntensity + 2.0 * centerIntensity + rightIntensity;
// float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomIntensity + 2.0 * centerIntensity + topIntensity;
float h = (centerIntensity - topIntensity) + (bottomIntensity - centerIntensity);
float v = (centerIntensity - leftIntensity) + (rightIntensity - centerIntensity);
// float h = (centerIntensity - topIntensity);
// float j = (topIntensity - centerIntensity);
// h = max(h,j);
// j = abs(h);
// float v = (centerIntensity - leftIntensity);
float mag = length(vec2(h, v)) * edgeStrength;
mag = step(threshold, mag);
// float mag = abs(h);
// gl_FragColor = vec4(h, h, h, 1.0);
// gl_FragColor = vec4(texture2D(inputImageTexture, textureCoordinate));
// gl_FragColor = vec4(h, centerIntensity, j, 1.0);
gl_FragColor = vec4(mag, mag, mag, 1.0);
}
);
#else
NSString *const kGPUImageThresholdEdgeDetectionFragmentShaderString = SHADER_STRING
(
varying vec2 textureCoordinate;
varying vec2 leftTextureCoordinate;
varying vec2 rightTextureCoordinate;
varying vec2 topTextureCoordinate;
varying vec2 topLeftTextureCoordinate;
varying vec2 topRightTextureCoordinate;
varying vec2 bottomTextureCoordinate;
varying vec2 bottomLeftTextureCoordinate;
varying vec2 bottomRightTextureCoordinate;
uniform sampler2D inputImageTexture;
uniform float threshold;
uniform float edgeStrength;
void main()
{
float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;
float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;
float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;
float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;
float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;
float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
h = max(0.0, h);
float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;
v = max(0.0, v);
float mag = length(vec2(h, v)) * edgeStrength;
mag = step(threshold, mag);
gl_FragColor = vec4(vec3(mag), 1.0);
}
);
#endif
使用 GPUImageThresholdEdgeDetectionFilter **,**原圖如下:
使用 GPUImageThresholdEdgeDetectionFilter 效果如下:
OpenGL ES Demo 下載地址 : IOS OpenGL ES GPUImage 圖像閾值邊緣檢測(cè) GPUImageThresholdEdgeDetectionFilter
本文由博客 - 猿說編程 猿說編程 發(fā)布!