iOS中的OpenGL:基础概念

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS中的OpenGL:基础概念相关的知识,希望对你有一定的参考价值。

参考技术A

无论是OpenGL 还是 OpenGL ES 或者 Metal ,本质上还是利用GPU来进行高效的渲染图形图像。
换句话说图形API,是我们ios开发者唯一接近GPU的方式。

首先,“状态机”这个东西是什么,学过编译原理的同学,一定听过或了解这三个字。 状态机是有限状态自动机的简称,是现实事物运行规则抽象而成的一个数学模型。

如果说下图“自动门”是个状态机,他 记忆 了open和close状态,知道自己处在不同状态时,下一步要干什么,是“开门”还是“关门”。 当在close状态时,你 输入 一个开门的信号,他就会切换成open状态

状态机的特点:

回到 OpenGL 状态机:

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

四.猜你喜欢

本文由博客 - 猿说编程 猿说编程 发布!

以上是关于iOS中的OpenGL:基础概念的主要内容,如果未能解决你的问题,请参考以下文章

OPENGL若干重要基础概念

Opengl ES 基础概念

OpenGL基础图形编程真实感图形基本概念

在Android中使用OpenGL ES进行开发第节:概念先行

基础概念OpenGLES(一)

渲染基础概念 unity shader 材质相关学习