IOS – OpenGL ES 图像柏林噪点/花边噪点 GPUImagePerlinNoiseFilter
目錄
- 一.簡介
- 二.效果演示
- 三.源碼下載
- 四.猜你喜歡
零基礎 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 , 視覺效果相關.
GPUImagePerlinNoiseFilter 屬于 GPUImage 圖像視覺效果相關,用來處理圖像柏林噪點/花邊噪點。shader 源碼如下:
/******************************************************************************************/ //@Author:猿說編程 //@Blog(個人博客地址): www.codersrc.com //@File:IOS – OpenGL ES 圖像柏林噪點/花邊噪點 GPUImagePerlinNoiseFilter //@Time:2022/06/08 06:30 //@Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累! /******************************************************************************************/#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE NSString *const kGPUImagePerlinNoiseFragmentShaderString = SHADER_STRING (precision highp float;varying highp vec2 textureCoordinate;uniform float scale;uniform vec4 colorStart;uniform vec4 colorFinish;//// Description : Array and textureless GLSL 2D/3D/4D simplex// noise functions.// Author : Ian McEwan, Ashima Arts.// Maintainer : ijm// Lastmod : 20110822 (ijm)// License : Copyright (C) 2011 Ashima Arts. All rights reserved.// Distributed under the MIT License. See LICENSE file.// https://github.com/ashima/webgl-noise//vec4 mod289(vec4 x) {return x - floor(x * (1.0 / 289.0)) * 289.0; }vec4 permute(vec4 x) {return mod289(((x*34.0)+1.0)*x); }vec4 taylorInvSqrt(vec4 r) {return 1.79284291400159 - 0.85373472095314 * r; }vec2 fade(vec2 t) {return t*t*t*(t*(t*6.0-15.0)+10.0);}// Classic Perlin noisefloat cnoise(vec2 P) {vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);Pi = mod289(Pi); // To avoid truncation effects in permutationvec4 ix = Pi.xzxz;vec4 iy = Pi.yyww;vec4 fx = Pf.xzxz;vec4 fy = Pf.yyww;vec4 i = permute(permute(ix) + iy);vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;vec4 gy = abs(gx) - 0.5 ;vec4 tx = floor(gx + 0.5);gx = gx - tx;vec2 g00 = vec2(gx.x,gy.x);vec2 g10 = vec2(gx.y,gy.y);vec2 g01 = vec2(gx.z,gy.z);vec2 g11 = vec2(gx.w,gy.w);vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));g00 *= norm.x;g01 *= norm.y;g10 *= norm.z;g11 *= norm.w;float n00 = dot(g00, vec2(fx.x, fy.x));float n10 = dot(g10, vec2(fx.y, fy.y));float n01 = dot(g01, vec2(fx.z, fy.z));float n11 = dot(g11, vec2(fx.w, fy.w));vec2 fade_xy = fade(Pf.xy);vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);float n_xy = mix(n_x.x, n_x.y, fade_xy.y);return 2.3 * n_xy; }void main(){float n1 = (cnoise(textureCoordinate * scale) + 1.0) / 2.0;vec4 colorDiff = colorFinish - colorStart;vec4 color = colorStart + colorDiff * n1;gl_FragColor = color;} ); #else NSString *const kGPUImagePerlinNoiseFragmentShaderString = SHADER_STRING (varying vec2 textureCoordinate;uniform float scale;uniform vec4 colorStart;uniform vec4 colorFinish;//// Description : Array and textureless GLSL 2D/3D/4D simplex// noise functions.// Author : Ian McEwan, Ashima Arts.// Maintainer : ijm// Lastmod : 20110822 (ijm)// License : Copyright (C) 2011 Ashima Arts. All rights reserved.// Distributed under the MIT License. See LICENSE file.// https://github.com/ashima/webgl-noise//vec4 mod289(vec4 x) {return x - floor(x * (1.0 / 289.0)) * 289.0; }vec4 permute(vec4 x) {return mod289(((x*34.0)+1.0)*x); }vec4 taylorInvSqrt(vec4 r) {return 1.79284291400159 - 0.85373472095314 * r; }vec2 fade(vec2 t) {return t*t*t*(t*(t*6.0-15.0)+10.0);}// Classic Perlin noisefloat cnoise(vec2 P) {vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);Pi = mod289(Pi); // To avoid truncation effects in permutationvec4 ix = Pi.xzxz;vec4 iy = Pi.yyww;vec4 fx = Pf.xzxz;vec4 fy = Pf.yyww;vec4 i = permute(permute(ix) + iy);vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;vec4 gy = abs(gx) - 0.5 ;vec4 tx = floor(gx + 0.5);gx = gx - tx;vec2 g00 = vec2(gx.x,gy.x);vec2 g10 = vec2(gx.y,gy.y);vec2 g01 = vec2(gx.z,gy.z);vec2 g11 = vec2(gx.w,gy.w);vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));g00 *= norm.x;g01 *= norm.y;g10 *= norm.z;g11 *= norm.w;float n00 = dot(g00, vec2(fx.x, fy.x));float n10 = dot(g10, vec2(fx.y, fy.y));float n01 = dot(g01, vec2(fx.z, fy.z));float n11 = dot(g11, vec2(fx.w, fy.w));vec2 fade_xy = fade(Pf.xy);vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);float n_xy = mix(n_x.x, n_x.y, fade_xy.y);return 2.3 * n_xy;}void main(){float n1 = (cnoise(textureCoordinate * scale) + 1.0) / 2.0;vec4 colorDiff = colorFinish - colorStart;vec4 color = colorStart + colorDiff * n1;gl_FragColor = color;} ); #endif二.效果演示
使用**GPUImagePerlinNoiseFilter 完成**圖像柏林噪點/花邊噪點****
三.源碼下載
OpenGL ES Demo 下載地址 : IOS – OpenGL ES 圖像柏林噪點/花邊噪點 GPUImagePerlinNoiseFilter
四.猜你喜歡
總結
以上是生活随笔為你收集整理的IOS – OpenGL ES 图像柏林噪点/花边噪点 GPUImagePerlinNoiseFilter的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 好佳居软装十大品牌 每个人都有着适合自己
- 下一篇: python写闲鱼脚本_自动化篇 - 躺