Discrete Techniques
Historical Background 1970 년대 : local illumination models Phong shading : plastic 처럼보인다... 1980년대 : realism 의추구 global illumination models high cost, but very realistic texture mapping low cost, but reasonable results 예 : environment mapping ray tracing 과유사. 그러나열등 1
9.1 Buffers and Mappings
Buffers a block of memory n m k bit elements bit plane any of the k n m planes in a buffer pixel all k of the elements at a position pixel 1 개 bit plane 1 개 3
Mappings rendering 의사실성을높이는방법 물체의 model 자체를자세하고복잡하게 rendering 시에 detail 만변화 mapping texture mapping map a pattern (or texture) onto the surfaces of objects bump mapping distort the shape of the surface to create variations reflection or environmental mapping paint an image of the environment 4
Mapping 의종류 color : texture mapping 물체표면에무늬를입힌다 specular color : environment mapping shiny object 의표면에 ray-tracing 효과 normal vector pertubation : bump mapping 울퉁불퉁한표면효과 displacement mapping : (normal meshes, 2000) geometry에변형을가함 transparency : etched glass 물체의투명도를조절가능 5
9.2 Texture Mapping
Texture Mapping texture space (s, t) : 2차원 image [0,1] [0,1] texel : texture element. pixel in the texture object space (x w, y w, z w ) : 3차원물체 screen space (x s, y s ) : 2차원화면 7
Texture Mapping 의모델링 texture space (s, t) object space (x w, y w, z w ) screen space (x s, y s ) forward mapping texture space 의폐영역 backward mapping pixel : 정사각형 8
Texture Mapping 방법들 practical 한방법 polygon mesh 의각 vertex 에 texture coordinate (s, t) 를설정 보통은사람이직접 set polygon 내부의점들은 forward mapping texture를 rubber sheet 로보고, mapping backward mapping pixel 1개 texture 상의폐영역 9
Texture Mapping mapping from texture space to object space linear mapping for a parametric surface linear mapping function: (s,t) (u,v) u = f u (s,t) = a s + b t + c v = f v (s,t) = d s + e t + f invertible mapping when a e b d u= u v= v min min + s + t s s max t t max min s min t min min ( u ( v max max u v min min ) ) 10
Two-part texture mapping Bier and Sloan, Two-part texture mapping, IEEE CG&A, 6(9), 1986. intermediate surface의도입 2D texture 2D simple 3D mapping 3D intermediate surface 간단한형태 simple 3D complex 3D mapping 3D object (maybe complex) 왜? texture coordinate 설정을쉽게 environment mapping 으로가는중간과정 11
Two-part texture mapping two-stage forward mapping S mapping (surface mapping) T(u, v) T (x i, y i, z i ) : intermediate surface O mapping (object mapping) T (x i, y i, z i ) O(x w, y w, z w ) intermediate surface : plane, cylinder, cube, sphere cylinder 의경우 cube 의경우 12
Two-part texture mapping O mapping (object mapping) 어느 pixel 을고를지는선택가능 밖에서안으로 normal 방향 center 에서의 ray 로 전체과정 texture S mapping O mapping 13
Texture mapping in OpenGL OpenGL 기능 from one- or two-dimensional texture to 1D, 2D, 3D, 4D object 2D texture to 3D object 가일반적 14
glteximage2d( ) void glteximage2d( GLenum target, GL_TEXTURE_2D: target texture buffer GLint level, 0, 1, 2, : level-of-detail for Mip-Map GLint components, 0, 1, 2, 3 : components GLsizei width, width of texture GLsizei height, height of texture GLint border, 0 : border width GLenum format, pixel의저장형식 (R, G, B, A 중의어느것 ) GLenum type, pixels의저장형식 (int, short, long, ) const GLvoid* pixels source color array ); pixels 배열의내용을 texture buffer 에저장 15
glgetteximage( ) void glgetteximage( GLenum target, GLint level, GLenum format, GLenum type, GLvoid* pixels ); GL_TEXTURE_2D: target texture buffer 0, 1, 2, : level-of-detail for Mip-Map pixel의저장형식 pixel의저장형식 texture buffer 의내용을가져올곳 texture buffer 의내용을 pixels 배열에저장 16
Texture 사용예제 glenable(gl_texture_2d); texture 적용시작 glbegin(gl_quad); gltexcoord2f(0.0, 0.0); glvertex2f(x1, y1, z1); gltexcoord2f(1.0, 0.0); glvertex2f(x2, y2, z2); gltexcoord2f(1.0, 1.0); glvertex2f(x3, y3, z3); gltexcoord2f(0.0, 1.0); glvertex3f(x4, y4, z4); glend( ); 17
Repeat or Clamp texture coordinate 가 [0,1] [0,1] 을벗어날때, repeat : texture 가무한반복된다고해석 clamp : 경계를벗어나면, 전부 black void gltexparameterf( GLenum target, GLenum pname, GLfloat param ); 보통, GL_TEXTURE_2D pname = GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T param = GL_REPEAT, GL_CLAMP 18
Aliasing texture sampling 시에, aliasing 문제발생가능 void gltexparameterf( ); GLenum target, // GL_TEXTURE_2D GLenum pname, GLfloat param pname = GL_TEXTURE_MAG_FILTER, 확대 (magnification) GL_TEXTURE_MIN_FILTER 축소 (minifiication) 19
Aliasing param = GL_NEAREST, point sampling GL_LINEAR, linear interpolation GL_NEAREST_MIPMAP_NEAREST Mip-Map : texture pyramid MIPMAP 가장가까운크기 2 를합성해서, 최적의 texture 생성 ¼ ¼ ½ ½ 비슷한크기의 2 개를합성 20
glubuild2dmipmaps int glubuild2dmipmaps( GLenum target, GL_TEXTURE_2D: target texture buffer GLint level, 0, 1, 2, : level-of-detail for Mip-Map GLint components, 0, 1, 2, 3 : components GLsizei width, width of texture GLsizei height, height of texture GLint border, 0 : border width GLenum format, pixel의저장형식 (R, G, B, A 중의어느것 ) GLenum type, pixels의저장형식 (int, short, long, ) const GLvoid* pixels source color array ); Mip-Map 을생성해서, texture buffer 에저장 (level: 0, 1, 2, ) 21
Texture and Shading shading 결과와 texture 적용의해석 modulate : 두결과를서로곱해서, 최종값 decaling : shading 무시, texture color 만단순 copy void gltexenvi( GLenum target, GLenum pname, GLint param ); GL_TEXTURE_2D: target texture buffer GL_TEX_ENV_MODE GL_MODULATE, GL_DECAL 22
Perspective Projection 교정 texture mapping : linear interpolation 에기초 parallel projection : 문제없음 perspective projection : 문제발생가능 glhint(gl_perspective_correction, GL_NICEST); perspective projection 에의한오차를교정 23
9.3 Environmental Maps
Environment Mapping Blinn, Models of light reflection for computer synthesized pictures, Computer Graphics, 11(2):192~198, 1977. Greene, Environment mapping and other applications of world projections, IEEE CG&A, 6(11):21~29, 1986. = reflection mapping ray tracing 에대한 trick 으로제안 shiny object shiny object environment texture mapping camera ray tracing object camera object environment mapping 25
Environment Mapping 의예 26
Ray Tracing vs. Environment Map environment map ray tracing 27
Environment Mapping 의한계 물체가비교적작아야한다. 커지면, reflection vector 에서의오차가크다 concave 한물체에서는 incorrect 각 object 마다별도의 environment map 필요 view direction 이다르므로 camera 위치가바뀔때마다새로운 environment map 필요 view direction 이다르므로 28
Environment Mapping 의개요 2 stage algorithm R : reflection vector environment map 만들기 environment map 을 texture 처럼 mapping 시킴 29
9.4 Bump Maps
Bump Mapping Blinn, Simulation of wrinkled surfaces, Computer Graphics, 1978. wrinkle, dimple 을표현하는 trick 기법 물체의 geometry는변화시키지않음 표면의 normal vector 만 perturbation local model 에의해, dimple 이있는것처럼보임 단점 : silhouette line들에서는매끈함 31
Bump Mapping 의예 32
Bump Mapping Process u v = P P N N P P + = ), ( ), ( ), ( ' v u B v u v u u B u B u B u u + + = + = N N P N P P ) ( ' P(u,v) N(u,v) B(u,v) 33 u v B v u B v B v u B u v u + + + + = P N P N N N P N P P P N ' ' ' u u u u u v B v B v B v v + + = + = N N P N P P ) ( ' P (u,v) N (u,v)
Bump Mapping Process 정리하면, D N B A N P N P N N N + = + + = + + v B u B u v B v u B ' 34 = N+D N u P v P P N v = P N A u = P N B D
Two-pass Bump Mapping McReynolds and Blythe, Programming with OpenGL: Advanced Rendering, SIGGRAPH 97 Lecture Notes. Key Idea : N L = N L + D L N L의계산 : Gouraud Shading과동일 D L 의계산 : image 상에서 approximation D= B u N P v + B v N P u 결과적으로 2 개의 rendering 결과를합성해서 bumpmapping 가능 texture mapping H/W 만으로가능 35
Bump Mapping 의다른예 36
9.5 Writes into Buffers
Read from / write into buffers 보통의 memory read / write 와차이점? single pixel 이아니라, block 단위로 read / write bit-blt (bit-block transfer) = raster-ops, raster operations geometric operation 들과는무관 source 에서, destination 으로 m n 픽셀들을 block transfer 38
Writing Modes source destination 시의 operation 총 16 modes d d 1 1 자주쓰이는것들 mode 3: 단순 copy dest source mode 7: logical OR dest source + dest mode 6: XOR dest source dest 39
XOR mode interaction 시에자주사용 mode 6 : XOR 복구가능 (x y) y = x mode 7 : copy Mode 6 mouse cursor 구현방법 S : frame buffer, M : back buffer (backing storage) S 1 S 0 M 0 M 1 S 1 M 0 = (S 0 M 0 ) M 0 = S 0 S 2 S 1 M 1 = (S 0 M 0 ) M 1 = (S 0 M 0 ) S 0 = M 0 40
9.6 Bit and Pixel Operations in OpenGL
OpenGL buffers color buffers (including frame buffer) double buffering : front / back buffers stereo buffering : right / left buffers depth buffer (= Z-buffer) for hidden-surface removal accumulation buffer 다양한용도로사용 motion blur, anti-aliasing, stencil buffer used for masking operation 42
Pixel Operations in OpenGL raster position : raster-op 의출력기준점 geometric object 출력과는무관 void glrasterpos{d}{f}{v}( ); d = 2, 3, 4 f = i, s, d, f void glbitmap( GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte* bitmap ); rasterpos + (xorig, yorig) 부터 copy rasterpos rasterpos +(xmove, ymove) 43
Pixel Operations in OpenGL void glreadpixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels ); void gldrawpixels( GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels ); void glcopypixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum type ); raster position 을기준으로 read, draw, copy 를수행 44
Pseudo-color images gray-scale image 를 color 로출력하는방법 look-up table 의값들을 thermal color 로 setting blue green red 로색상변화 45
9.7 Compositing Techniques
Alpha Channel 4-channel color : (R, G, B, A) color channels RGB + alpha channel alpha channel : 다양한용도로사용 opacity and blending image composition anti-aliasing back-to-front rendering depth cueing and fog effect 47
Blending opacity : 물체의불투명한정도 opacity of 1 (α = 1.0) : 완전불투명 opacity of 0 (α = 0.0) : 완전투명 transparency : 물체의투명한정도 transparency = 1 opacity blending source : s = [s r s g s b s a ] destination : d = [d r d g d b d a ] transparent blended color : blending factor b and c d = [b r s r +c r d r b g s g +c g d g b b s b +c b d b b a s a +c a d a ] opaque 48
glblendfunc( ) glenable(gl_blend); blending 을시작 void glblendfunc( GLenum sfactor, GLenum dfactor ); blend color 에서, b, c 를결정 GL_ZERO factor = 0.0 GL_ONE factor = 1.0 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA factor = s a or factor = 1 s a d = [s a s r +(1 s a )d r s a s g +(1 s a )d g s a s b +(1 s a )d b s a s a +(1 s a )d a ] GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA 49
glblendfunc( ) draw the rectangle (dr, dg, db, da) // destination glenable(gl_blend); glblendfunc(gl_one_minus_src_alpha, GL_SRC_ALPHA); draw the triangle (sr, sg, sb, sa) // source 50
Image Composition n 개의 image 합성하기 C i = (R i, G i, B i ) alpha channel 사용시, = = n i i result n 1 1 C C 51 alpha channel 사용시, 같은결과 alpha channel hardware 때문에더빠르다... ) ( 3 1 3 1 ) ( 2 1 3 2 3 1 ) 3 1 (1 : 3 1 ) ( 2 1 2 1 ) 2 1 (1 : 2 1 1: 3 2 1 3 2 1 3 2 3 2 1 2 1 2 1 1 C C C C C C C C C C C C C C C C + + = + + = + = = + = + = = = = result result result result α α α
Anti-aliasing line 을그릴때, pixel coverage 를감안해야 area 계산법 : pixel 에걸리는면적을직접계산 면적 : 30% alpha channel : 면적을저장 draw 시에는 GL_SRC_ALPHA 사용 면적에따라, anti-aliasing 가능 OpenGL에서전체를수행하게하는방법 glenable(gl_point_smooth); glenable(gl_line_smooth); glenable(gl_smoothing); glblendfunc(gl_src_alpha, GL_ONE_MINUS_SRC_ALPHR); draw the objects 52
Depth Cueing and Fog depth cueing (= intensity cueing) 가까운것은진하고또렷하게 멀리있는것은연하고흐릿하게 C s = f C s + (1 f) C f f : fog factor 거리에따라변화 C s, C f : color for source and fog 설정방법 glenable(gl_fog); glfogf(gl_fog_mode, {GL_LINEAR,GL_EXP,GL_EXP2}); glfogf(gl_fog_density, 0.5); glfogfv(gl_fog_color, fogcolor); e z 2 e z 1 0.5z 53
9.8 Use of the Accumulation Buffer
Accumulation Buffer another buffer frame buffer 와같은 resolution bit 수는훨씬많음 가능한 operation glclear(gl_accum_buffer_bit); AccumBuffer 0 void glaccum( GLenum op, GLfloat value ); GL_LOAD : AccumBuffer FrameBuffer GL_ACCUM : AccumBuffer AccumBuffer + value * FrameBuffer GL_MULT : AccumBuffer AccumBuffer * value GL_RETURN : FrameBuffer AccumBuffer 55
Accumulation Buffer convolution image 에행렬곱하기 1/3 1/3 1/3 clear make FrameBuffer with camera at (x, y) AccumBuffer AccumBuffer + 1.0 * FrameBuffer make FrameBuffer with camera at (x+1, y) AccumBuffer AccumBuffer + 1.0 * FrameBuffer make FrameBuffer with camera at (x 1, y) AccumBuffer AccumBuffer + 1.0 * FrameBuffer AccumBuffer AccumBuffer * 0.33 FrameBuffer AccumBuffer convoluted image 56
Motion Blur 운동하는물체를제대로표현하기 t = 0.3 t = 0.2 t = 0.1 t = 0.0 motion blurred image another example 57
Depth of Field 사진에서, focus 를어디에두느냐? 만드는법? accumulation buffer! camera #1 camera #2 focus 가맞는부분 camera #3 모두 accumulation! 58
9.9 Sampling and Aliasing partially skipped
Nyquist sampling theorem The ideal samples of a continuous function contain all the information in the original function if and only if the continuous function is sampled at a frequency at least twice the highest frequency in the function. We can reconstruct a continuous function f(x) from its samples {f i } by the formula: f ( x, y) = + fi sinc( x i= sinπx sinc( x) = πx x i ) 60
요약 61