1. 程式人生 > 其它 >IOS – OPenGL ES 調節影象飽和度 GPUImageSaturationFilter

IOS – OPenGL ES 調節影象飽和度 GPUImageSaturationFilter

目錄

零基礎 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 , 視覺效果相關.

GPUImageSaturationFilter 屬於 GPUImage 顏色處理相關,用來處理圖片飽和度,shader 原始碼如下:

/******************************************************************************************/
//@Author:猿說程式設計
//@Blog(個人部落格地址): www.codersrc.com
//@File:IOS – OPenGL ES 調節影象飽和度 GPUImageSaturationFilter
//@Time:2022/03/12 07:30
//@Motto:不積跬步無以至千里,不積小流無以成江海,程式人生的精彩需要堅持不懈地積累!
/******************************************************************************************/

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

 uniform sampler2D inputImageTexture;
 uniform lowp float saturation;

 // Values from "Graphics Shaders: Theory and Practice" by Bailey and Cunningham
 const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);

 void main()
 {
    lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
    lowp float luminance = dot(textureColor.rgb, luminanceWeighting);
    lowp vec3 greyScaleColor = vec3(luminance);

	gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w);

 }
);
#else
NSString *const kGPUImageSaturationFragmentShaderString = SHADER_STRING
(
 varying vec2 textureCoordinate;

 uniform sampler2D inputImageTexture;
 uniform float saturation;

 // Values from "Graphics Shaders: Theory and Practice" by Bailey and Cunningham
 const vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);

 void main()
 {
     vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
     float luminance = dot(textureColor.rgb, luminanceWeighting);
     vec3 greyScaleColor = vec3(luminance);

     gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w);

 }
 );
#endif

二.效果演示

三.原始碼下載

下載地址:IOS – OPenGL ES 調節影象飽和度 GPUImageSaturationFilter

四.猜你喜歡

本文由部落格 - 猿說程式設計 猿說程式設計 釋出!