real timeimageprocessing

10

Click here to load reader

Upload: atsushi-yoshimura

Post on 13-Jun-2015

609 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Real timeimageprocessing

Real TimeImage Processing

with OpenGL ES 2.0

13年3月24日日曜日

Page 2: Real timeimageprocessing

カメラ

OpenGL ES テクスチャ

Custom Fragment Shader

CAEAGLLayer

UIView

13年3月24日日曜日

Page 3: Real timeimageprocessing

カメラ

OpenGL ES テクスチャ

Custom Fragment Shader

CAEAGLLayer

UIView

・爆速(GPU)

・多彩な表現・無限の自由度

13年3月24日日曜日

Page 4: Real timeimageprocessing

Fragment Shaderって何だよ(怒

const int wide = 100; const int high = 100; unsigned char pixels[wide * high * 4] = {0}; for(int y = 0 ; y < high ; ++y) { for(int x = 0 ; x < wide ; ++x) { unsigned char *color = pixels + 4 * (y * wide + x); color[0] = 32; color[1] = 12; color[2] = 0; color[3] = 120; } }

よくある画像処理プログラミング

13年3月24日日曜日

Page 5: Real timeimageprocessing

Fragment Shaderって何だよ(怒

const int wide = 100; const int high = 100; unsigned char pixels[wide * high * 4] = {0}; for(int y = 0 ; y < high ; ++y) { for(int x = 0 ; x < wide ; ++x) {

} }

Fragment Shader!

13年3月24日日曜日

Page 6: Real timeimageprocessing

Basics

precision highp float;

uniform sampler2D videoInput;uniform float iGlobalTime;uniform vec2 iResolution;

varying highp vec2 uv;void main(){ vec2 unused1 = iResolution; float unused2 = iGlobalTime; gl_FragColor = texture2D(videoInput, uv);}

ユーザー定義定数

浮動小数点精度

出力色 画像 座標

13年3月24日日曜日

Page 7: Real timeimageprocessing

precision highp float;

uniform sampler2D videoInput;uniform float iGlobalTime;uniform vec2 iResolution;

varying vec2 uv;void main(){ vec2 unused = iResolution; float stongth = sin(iGlobalTime) * 0.5 + 0.5; float waveu = sin((uv.y + iGlobalTime) * 20.0) * 0.5 * 0.1 * stongth; gl_FragColor = texture2D(videoInput, uv + vec2(waveu, 0));}

13年3月24日日曜日

Page 8: Real timeimageprocessing

precision highp float;

uniform sampler2D videoInput;uniform float iGlobalTime;uniform vec2 iResolution;

varying vec2 uv;

void main(void){ vec2 unused = iResolution; float blurx = sin(iGlobalTime) * 0.5 + 0.5; float offsetx = blurx * 0.05; vec2 ruv = uv + vec2(offsetx, 0.0); vec2 guv = uv; vec2 buv = uv - vec2(offsetx, 0.0); float r = texture2D(videoInput, ruv).r; float g = texture2D(videoInput, guv).g; float b = texture2D(videoInput, buv).b; gl_FragColor = vec4(r, g, b, 1.0);}

13年3月24日日曜日

Page 9: Real timeimageprocessing

precision highp float;uniform sampler2D videoInput;uniform float iGlobalTime;uniform vec2 iResolution;varying vec2 uv;float gray(vec4 color){ return (color.r + color.g + color.b) * 0.33333333;}void main(void){ float unused = iGlobalTime; float pixelwide = 1.0 / iResolution.x; float pixelhigh = 1.0 / iResolution.y; vec4 c = texture2D(videoInput, uv); float c_value = gray(c); vec4 l = texture2D(videoInput, uv + vec2(-pixelwide, 0.0)); vec4 u = texture2D(videoInput, uv + vec2(0.0, pixelhigh)); vec4 r = texture2D(videoInput, uv + vec2( pixelwide, 0.0)); vec4 b = texture2D(videoInput, uv + vec2(0.0, -pixelhigh)); float difference = 0.0; difference = max(difference, abs(c_value - gray(l))); difference = max(difference, abs(c_value - gray(u))); difference = max(difference, abs(c_value - gray(r))); difference = max(difference, abs(c_value - gray(b))); difference = clamp(difference * 20.0, 0.0, 1.0); gl_FragColor = vec4(difference, difference, difference, 1.0);}

13年3月24日日曜日

Page 10: Real timeimageprocessing

Enjoy Shader!

https://github.com/Ushio/RealTimeImageProcessing

13年3月24日日曜日