Real timeimageprocessing

887 views
793 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
887
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Real timeimageprocessing

  1. 1. Real Time Image Processing with OpenGL ES 2.013年3月24日日曜日
  2. 2. カメラ OpenGL ES テクスチャ Custom Fragment Shader CAEAGLLayer UIView13年3月24日日曜日
  3. 3. カメラ OpenGL ES テクスチャ Custom Fragment Shader ・爆速(GPU) ・多彩な表現 CAEAGLLayer ・無限の自由度 UIView13年3月24日日曜日
  4. 4. 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日日曜日
  5. 5. 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日日曜日
  6. 6. 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日日曜日
  7. 7. 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日日曜日
  8. 8. 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日日曜日
  9. 9. 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日日曜日
  10. 10. Enjoy Shader! https://github.com/Ushio/RealTimeImageProcessing13年3月24日日曜日

×