2011 03 07 Chungbuk National University Korea Raster
저수준 렌더링 정지성 2011. 03. 07 Chung-buk National University, Korea
Raster system image raster 바둑판 모델 ü pixel : picture element ü raster : an array of pixels ü frame buffer : pixel 저장용 memory area 2010 -01 -28 4
Raster system 1: 1 대응 관계 y for (y = 0; y < LINES; y++) for (x = 0; x < PIXELS; x++) display one pixel; display processor x 화면 출력 frame buffer 비디오 카드 2010 -01 -28 5
Output Devices ü CRT : cathode-ray tube 음극선관 frame buffer (in memory) ü raster system - frame buffer의 모든 pixel을 CRT에서 순서대로 출력 2010 -01 -28 6
Output Devices ü LCD : Liquid Crystal Display, 전압에 따른 액정의 배열을 변경으로 색상을 표현 frame buffer (in memory) 2010 -01 -28 7
Output Devices ü PDP : Plasma Display Panel, 대형 디스플레이에 사용, 방전의 원리 를 이용하여 색상을 구현 frame buffer (in memory) 2010 -01 -28 8
Graphics Architecture ü Modeling-Rendering Paradigm - 가장 간단한 graphics architecture modeler, renderer 가 별도의 program • 예 : Pixar’s Render. Man Interface • modeler / renderer 연결은 file 로 되어 있음. • Auto. CAD, 3 DS, MAYA, etc. 2010 -01 -28 Render. Man, BMRT, etc. 9
Graphics Architecture ü Single CPU Model - 초기의 computer 에서 사용 CPU 에 너무 많은 부하가 걸린다 • Intel x 86 : SSE (streaming SIMD extension) • - single CPU model을 위한 지원책 2010 -01 -28 10
Graphics Architecture ü Display Processor Model - DPU : display processor - graphics 처리 전용의 CPU를 추가 • 2010 -01 -28 pipeline architecture로 넘어가는 과도기 11
Graphics Architecture ü Pipeline Architecture - 가장 진보된 형태 - VLSI 기술의 발달로 가능 SGI (Silicon Graphics Inc. ) IRIS series , … , n. VIDIA Ge. Force chips • graphics 처리를 몇 단계로 나누어서 각각을 별도의 VLSI chip이 처리 • 2010 -01 -28 12
Graphics Architecture ü Pipeline Architecture - transformation • 좌표 변환을 위한 4× 4 matrix multiplication - clipping • projection plane 상에서 불필요한 부분 제거 - projection • 3 D object � 2 D image 로의 mapping - rasterization • 2010 -01 -28 image 를 frame buffer에 저장하는 과정 13
Images: Physical and Synthetic ü Image 생성과정 - 궁극적으로는 real world를 simulate • camera 또는 human visual system이 어떻게 작동하는 지를 그대로 simulate ü 주로, Open. GL에서는 camera의 정보를 통해 simulate real world 물체들 Camera 2010 -01 -28 3차원 공간 object viewer 14
Images: Physical and Synthetic ü Camera System - computer graphics : 3 D 2 D 로의 mapping object : 3 D • viewer : 3 D (= camera) • image : 2 D (camera의 film) • object viewer image 2010 -01 -28 15
Images: Physical and Synthetic ü Camera System with a light source - light : 3 D 에서 정의됨 light source light object viewer object의 표면 결정 light object shadow 그림자 생성 2010 -01 -28 16
Images: Physical and Synthetic ü Light, Optics - light : electro-magnetic radiation • light, color 는 modern optics에서 해석 - graphics 에서는 대부분 geometric optics 사용 2010 -01 -28 17
The Human Visual System ü Human Visual System - rod (간상체 杆狀體) : night vision - cones (원추체 圓錐體) : day vision 반응 곡선 - human visual system - back-end에 brain 이 있기 때문에, simulation 거의 불가능… 2010 -01 -28 18
The Pinhole Camera ü 바늘 구멍 사진기 - 가장 간단한 geometric model (x, y, z) : 3 D point (xp, yp, zp) : projection 2010 -01 -28 19
The Pinhole Camera ü 용어정리 - projection of the point (x, y, z) • (xp, yp, –d) : film 상의 좌표 - FOV : field of view (= angle of view) • 화면을 보는 최대각 - DOF : depth of field focus 가 맞는 거리 • pinhole camera는 infinite DOF • 2010 -01 -28 20
The Synthetic-Camera Model ü graphics 에서 사용하는 camera model - object 정의는 viewer와는 독립적 • object 정의 function을 별도로 독립 - image 생성 시에는 trigonometry 계산 필요 - projection plane • 2010 -01 -28 film을 center of projection 보다 앞으로 21
The Synthetic-Camera Model ü Projection plane, Clipping window - projection plane : 계산의 편의 - clipping rectangle • 2010 -01 -28 projection plane 상에서 실제로 보이는 부분 22
Color Model ü Light - electromagnetic wave • 흔히 가시광선(visible light)를 의미 red yellow AM 104 2010 -01 -28 106 FM 108 green blue violet ultraviolet infrared microwave visible X-ray 1010 1012 1014 1016 1018 1020 frequency (Hz) 23
Color Model ü Color - C(λ) : wave length에 대한 energy distribution • C(λ) 에 따라, color 결정 - additive color model • C(λ) 끼리 더할 수 있음 - three-color theory • 2010 -01 -28 C = T 1 R + T 2 G + T 3 B 24
Color Model ü Human Visual System - cones : red, green, blue 에 민감하게 반응 - sensitive curve Si(λ) : wavelength에 따른 반응 정도 - brain perception values - three-color theory의 기본 이론 • 2010 -01 -28 (Ared, Agreen, Ablue) 값들이 같으면, 같은 color로 인식 25
Color Model ü Color Model - color model color를 computer H/W, S/W에서 표현하는 방법 • 용도에 따라, 다양 : RGB, CMY, YIQ, CIE, … • - color gamut • 특정 color model 이 생성 가능한 모든 color - color solid (= color cube) color model 에서 흔히 three primary colors 사용 • three primary color에 의한 3차원 cube • color gamut 표현 가능 • 2010 -01 -28 26
Color Model ü RGB color model - Red, Green, Blue tri-stimulus theory • 눈에 가장 민감한 3가지 색상 • - RGB cube : 각각이 0 ~ 1 까지 Green C Y Blue M Red 2010 -01 -28 27
Color Model ü CMY, CMYK color model ü hard copy 기계에서는 잉크 사용 - subtractive system 감산 색계 - 흰 종이 위에 cyan, magenta, yellow 사용 Yellow G R Cyan B Magenta ü CMYK color model : K (black) 을 첨가 - 이론상, cyan + magenta + yellow = black - 실제로는 dark gray - 해결책 : black(K) ink를 별도로 2010 -01 -28 28
Color Model ü RGB vs CMY <RGB color system> <CMY color system> • additive primaries – 더하면 밝아진다 • subtractive primiaries – 더하면 어두워진다 • monitor 기준 – 형광 물질로 R, G, B 사용 • printer 기준 – ink로 C, M, Y 사용 • graphics는 주로 RGB 기준 2010 -01 -28 29
Color Model ü Direct color system - 기본적인 video card 구조 3개의 전자총, 3개의 frame buffer • frame buffer 마다, pixel 당 n bit 할당 • - 2 n × 2 n colors = 23 n colors 3 n can be 8, 12, 24, … • 3 n = 24 : true color system • 2010 -01 -28 30
Color Model ü Direct color system - Open. GL functions 3 n 값은 system 마다 틀리다 • color 설정은 RGB cube 기준 • red, green, blue 모두 0. 0 ~ 1. 0 • - void gl. Color*( ); - void gl. Color 3 f(GLclampf red, GLclampf green, GLclampf blue); 현재 색상 정의 • GLclampf : 0. 0 보다 작으면 0. 0, 1. 0보다 크면 1. 0 • see Open. GL manual • 2010 -01 -28 31
Color Model ü RGBA color model - RGB + A (alpha channel) - alpha channel 은 opacity value : image 합성에 사용 - A = 1. 0 이 보통의 경우 ü void gl. Color 4 f(red, green, blue, alpha); ü void gl. Clear. Color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); - clear color 설정 (= background color) ü void gl. Clear(GLbitfield mask); - mask = GL_COLOR_BUFFER_BIT 이면, frame buffer 전체를 clear color로 2010 -01 -28 32
Color Model ü Indexed color system - frame buffer size 를 줄이는 방법 • color lookup table (LUT) (= palette) - 23 m bit 로 color 값 2 k 개를 저장 • frame buffer : k bit index 값 저장 - 23 m color 중에서 2 k 개만 동시 표현 color LUT 2010 -01 -28 33
Color Model ü Indexed color system - why indexed color system ? - image 표현에 필요한 frame buffer size 축소 - image file format에서 사용 : GIF, BMP, … - Open. GL functions • LUT의 setting은 window system / GLUT 가 담당 - void gl. Index*(…); • current color를 LUT의 해당 index로 설정 - void glut. Set. Color(int index, GLfloat red, green, blue); • 2010 -01 -28 LUT의 해당 index를 새로운 color로 34
Open. GL설치 및 Console program 구조 ü Open. GL Library를 다운 - 강의자료 다운 - Open. GL/GL : C: Program FilesMicrosoft Visual Studio 9. 0VCinclude 로 복사 - Open. GL/LIB : C: Program FilesMicrosoft Visual Studio 9. 0VClib로 복사 - Open. GL/DLL : C: WindowsSystem 32로 복사 2010 -01 -28 35
Open. GL설치 및 Console program 구조 ü Console program - The Sierpinski Gasket • 전체 구조 - void main(void) { } • initialize_the_system( ); for (some_number_of_points) { pt = generate_a_point( ); display_the_point( pt ); } cleanup( ); // 좌표 계산 // 출력 제일 먼저 할 일 ? - 점을 어떻게 출력할 것인가? 2010 -01 -28 37
Open. GL설치 및 Console program 구조 ü Console program - Pen-Plotter Model • pen-plotter - 2 D 종이 위에 펜을 움직여서 출력 - moveto(x, y); 정해진 위치로 펜을 이동 - lineto(x, y); 정해진 위치까지 선분 출력 • 가장 오래된 graphics output model - 장점 : 간단. 2 D 종이, 2 D 화면에 적합한 model » printer 용 언어, 초기 graphics system 에서 사용 » Post. Script, PDF, LOGO, GKS, … - 단점 : 2010 -01 -28 3 D model 에는 부적합 38
Open. GL설치 및 Console program 구조 ü Console program - 2 D in a 3 D Model 2 D 는 3 D의 특별한 경우이다 • 3 D 좌표 : • 2 D로 해석할 때는 z = 0 : • 간단하게 : • (x, y , z ) (x, y, 0) (x, y) y z 3 D space x 2 D plane (z = 0) 2010 -01 -28 39
Open. GL설치 및 Console program 구조 ü Vertex - space 상의 위치 1개 • graphics 에서는 2 D, 3 D, 4 D space 사용 - 표기법 : column vector vertex - geometric objects point : vertex 1개로 정의 • line segment : vertex 2개로 정의 • triangle : vertex 3개로 정의 • triangle - point 와 헷갈리지 말 것 2010 -01 -28 40
Open. GL설치 및 Console program 구조 ü Vertex 정의 in Open. GL - Open. GL 에서 vertex 를 정의하는 함수 gl. Vertex[n][t][v](…); • n : number of coordinates - • t : coordinate type - • n = 2, 3, 4 t = i (integer), f (float), d (double), … v : vector or not - v 가 붙으면, vector (= array) form - Ex) gl. Vertex 2 i(2, 3), gl. Vertex 3 f(1. 5, 2. 3, 3. 0), GLdouble vertex[3] = { 1, 2, 3 }; gl. Vertex 3 dv(vertex); - 모든 Open. GL 함수는 gl 로 시작 2010 -01 -28 41
Open. GL설치 및 Console program 구조 ü Vertex 정의 in Open. GL suffix data type C-language b 8 -bit integer signed char s 16 -bit integer short i 32 -bit integer int / long f 32 -bit floating pt. float d 64 -bit floating pt. double ub 8 -bit unsigned int unsigned char us 16 -bit unsigned intunsigned shrot ui 32 -bit unsigned int / unsigned long 2010 -01 -28 Open. GL type GLbyte GLshort GLint, GLsizei GLfloat, GLclampf GLdouble, GLclampd GLubyte, GLboolean GLushort GLuint, GLenum, GLbitfield 42
Open. GL설치 및 Console program 구조 ü Object 정의 in Open. GL - geometric object 의 정의 vertex가 여러 개 모여서 하나의 object • gl. Begin(TYPE); gl. Vertex*(…); … /* 다른 함수도 가능 */ gl. End( ); • - 사용 예 • 2010 -01 -28 gl. Begin(GL_LINES); gl. Vertex 2 f(x 1, y 1); gl. Vertex 2 f(x 2, y 2); gl. End( ); 43
Open. GL설치 및 Console program 구조 ü Object-oriented Paradigm - graphics program들은 object-oriented paradigm에 적합 - Java 3 D : fully object-oriented library • Point 3 old(2, 1, 3); Vector 3 vec(1, 0, 0); Point 3 new = old + vec; - Open. GL : not object-oriented ! C-based library • 대안은 array 뿐 • typedef GLfloat Point 2[2]; Point 2 p = { 2, 3 }; … gl. Vertex 2 fv(p); • 2010 -01 -28 44
Open. GL설치 및 Console program 구조 ü Sierpinski gasket Algorithm void display( void ) { point 2 vertices[3]={{0. 0, 0. 0}, {250. 0, 500. 0}, {500. 0, 0. 0}}; /* A triangle */ point 2 p ={75. 0, 50. 0}; /* An arbitrary initial point inside triangle */ int i, j, k; } for (k=0; k<5000; k++) { j=rand( ) % 3; /* pick a vertex at random */ /* Compute point halfway between selected vertex and old point */ p[0] = (p[0] + vertices[j][0]) / 2. 0; p[1] = (p[1] + vertices[j][1]) / 2. 0; /* plot new point */ gl. Begin(GL_POINTS); gl. Vertex 2 fv(p); old (p[0], p[1]) gl. End( ); } new (p[0], p[1]) gl. Flush( ); /* flush buffers */ (vertices[j][0], vertices[j][1]) 2010 -01 -28 45
- Slides: 45