Graphics Open GL redbook 4 5 kucg korea
Graphics Open. GL 세미나 redbook 4, 5장 김우림 kucg. korea. ac. kr Graphics Lab @ Korea University
4장 Color CGVR Color Perception n Computer Color n RGBA vs Color-Index n Shading Model n kucg. korea. ac. kr Graphics Lab @ Korea University
Color Perception n CGVR 실제 눈에는 3 종류의 cone n RGB 각각에 민감한 cone n Cone 혼합해서 색 인식 n Blue M C n 컴퓨터 사람 눈 흉내 n RGB 조합으로 색 저장, 표현 n kucg. korea. ac. kr Red Y Green Graphics Lab @ Korea University
Computer Color (1/2) n CGVR Pixel 마다 color data 저장 System 마다 다르다 n Pixel 당 8 bit -> 256 색 n Pixel 당 24 bit -> 2^24 색 n Color Buffer에 저장 n n Bitplane : 특정 색에 할당한 bit 수 n gl. Get. Integerv(GL_RED_BITS) kucg. korea. ac. kr Graphics Lab @ Korea University
Computer Color (2/2) n CGVR RGB 모드 rgb 각각 0. 0~1. 0 n {0. 0, 0. 0} -> 검정색 n pixel은 r, g, b 각각의 값 가짐 n n RGBA 모드 RGB 모드 + alpha n Alpha : 투명도 n pixel은 r, g, b, a 각각의 값 가짐 n n Color-index 모드 Color table 사용 n pixel은 index를 가짐 n kucg. korea. ac. kr Graphics Lab @ Korea University
RGBA vs Color-Index (1/5) n CGVR RGBA Display Mode R, G, B, A 마다 다른 bitplane n float 형태 n Alpha 값은 색깔에 직접 영향 X n kucg. korea. ac. kr Graphics Lab @ Korea University
RGBA vs Color-Index (3/5) n CGVR Open. GL 색 지정 함수 gl. Color 3{b s i f d ub us ui} (GLfloat r, GLfloat g, GLfloat b); gl. Color 4 f (GLfloat r, GLfloat g, GLfloat b, GLfloat a); gl. Color 3 fv (Glfloat * array); gl. Color 4 fv (Glfloat * array); n Byte, short, int, float, double kucg. korea. ac. kr Graphics Lab @ Korea University
RGBA vs Color-Index (2/5) n CGVR Color-Index mode n Color map 미리 table 생성 n Pixel은 color map의 index 가짐 n 같은 index를 가진 pixel -> 같은 색 n kucg. korea. ac. kr Graphics Lab @ Korea University
RGBA vs Color-Index (4/5) n CGVR Open. GL 색 지정 함수 n gl. Index 3 f (GLfloat color); o n Color index 설정 gl. Clear. Index (Glfloat cindex); Clear 색 지정. RBG : gl. Clear. Color (r, g, b, a); o gl. Clear () 시 사용 o kucg. korea. ac. kr Graphics Lab @ Korea University
RGBA vs Color-Index (5/5) n CGVR RGBA mode 쓰자!! n Open. GL 기능들 충분히 이용 위해 n Shading, lighting, texture mapping, fog n 특별한 목적 시 color-index kucg. korea. ac. kr Graphics Lab @ Korea University
Shading Model n CGVR Open. GL 기본 shading Flat shading – 단일 vertex n Smooth shading – vertex들의 평균 v 0 (1, 0, 0) n n Shading 지정 함수 n v 2 (0, 0, 0) v 1 (0, 1, 0) gl. Shade. Model (GLenum mode); o mode = GL_SMOOTH, GL_FLAT kucg. korea. ac. kr Graphics Lab @ Korea University
5장 Light n n n n CGVR 실제 vs Open. GL Lighting 종류 Light source Light 위치, 방향 Lighting Model Material Mathematics of Lighting kucg. korea. ac. kr Graphics Lab @ Korea University
실제 vs Open. GL n CGVR 실제 매우 복잡. 표면의 반사, 흡수. n 표면이 광원 역할. 다양한 재질. n n Open. GL Light source : RGB 로 구성 n Light source 여러 개. On/off 가능 n Suface의 Material과의 상호작용 n n Open. GL 기본 lighting model 속도 중시. 단순하다. n 사실적 표현 -> 직접 구현 필요. n kucg. korea. ac. kr Graphics Lab @ Korea University
Lighting 종류 CGVR Ambient n n n 한 방향서 오는 light 주변광. 모든 pixel에 동일하게 영향 Diffuse 한 방향서 오는 light n 모든 방향으로 반사 n 표면 접선 영향 n n lxn Specular n 반짝임. 관측자 eye 영향 n sxn Emissive n Material이 스스로 빛을 낼 경우 kucg. korea. ac. kr Graphics Lab @ Korea University
Light source (1/6) CGVR gl. Enable (GL_LIGHTING) n gl. Disable (GL_LIGHTING) n gl. Enable (GL_LIGHT 0) n n gl. Light{if} (light, pname, param); n Light : GL_LIGHT 0, GL_LIGHT 1 … GL_LIGHT 7 kucg. korea. ac. kr Graphics Lab @ Korea University
Light source (2/6) n CGVR pname Parameter Name 의미 GL_AMBIENT ambient RGBA intensity of light GL_DIFFUSE diffuse RGBA intensity of light GL_SPECULAR specular RGBA intensity of light GL_POSITION (x, y, z, w) position of light GL_SPOT_DIRECTION (x, y, z) direction of spotlight GL_SPOT_EXPONENT spotlight exponent GL_SPOT_CUTOFF spotlight cutoff angle GL_CONSTANT_ATTENUATION constant attenuation factor GL_LINEAR_ATTENUATION linear attenuation factor GL_QUADRATIC_ATTENUATION quadratic attenuation factor kucg. korea. ac. kr Graphics Lab @ Korea University
Light source (3/6) n param n n CGVR 지정할 값. 일반적으로 Glfloat 배열. GLLight() 예제 GLfloat light_ambient[] = { 0. 0, 1. 0 }; light_diffuse[] = { 1. 0, 1. 0 }; light_specular[] = { 1. 0, 1. 0 }; light_position[] = { 1. 0, 0. 0 }; gl. Lightfv(GL_LIGHT 0, kucg. korea. ac. kr GL_AMBIENT, light_ambient); GL_DIFFUSE, light_diffuse); GL_SPECULAR, light_specular); GL_POSITION, light_position); Graphics Lab @ Korea University
Light source (4/6) n CGVR Directional Light 광원이 무한한 곳에 위치. ( 태양) n 방향만 고려. 위치 고려 X. n GLfloat light_position[] = { 1. 0, 0. 0 }; gl. Lightfv(GL_LIGHT 0, GL_POSITION, light_position); kucg. korea. ac. kr Graphics Lab @ Korea University
Light source (5/6) n CGVR Positional Light 점 광원. (전구) n 광원 중심으로 모든 방향에 영향. n GLfloat light_position[] = { 0. 0, 1. 0 }; gl. Lightfv(GL_LIGHT 0, GL_POSITION, light_position); kucg. korea. ac. kr Graphics Lab @ Korea University
Light source (6/6) n CGVR Spot Light 원뿔 모양의 빛. n 특정 방향으로 영향. n GLfloat direction[] = { -1. 0, 0. 0 }; gl. Lightfv(GL_LIGHT 0, GL_SPOT_DIRECTION, direction); gl. Lightf(GL_LIGHT 0, GL_SPOT_CUTOFF, 45. 0); kucg. korea. ac. kr Graphics Lab @ Korea University
Light 위치, 방향 (1/3) n Open. GL Light : 물체로 취급 n n CGVR Modelview 행렬에 영향 받음 고정된 Light Viewport, projection 행렬 설정 n Modelview 행렬 초기화 n light 위치 지정 n kucg. korea. ac. kr Graphics Lab @ Korea University
Light 위치, 방향 (2/3) n CGVR Object에 상대적 Light n Object의 변환 행렬 후 Light 위치 지정 gl. Push. Matrix(); gl. Translatef(0. 0, -5. 0); gl. Rotated((GLdouble) spin, 1. 0, 0. 0); gl. Lightfv(GL_LIGHT 0, GL_POSITION, light_position); glut. Solid. Cube (1. 0); gl. Pop. Matrix(); kucg. korea. ac. kr Graphics Lab @ Korea University
Light 위치, 방향 (3/3) n CGVR Viewport 따라다니는 Light n Viewport 변환 시에 Light 위치 지정 Glfloat posiion[] = { 0. 0, 1. 0 }; gl. Matrix. Mode(GL_MODELVIEW); gl. Load. Identy(); glu. Look. At (); gl. Lightfv (GL_LIGHT 0, GL_POSITION, posiion); kucg. korea. ac. kr Graphics Lab @ Korea University
Lighting Model n Global ambient light intensity n n CGVR 기본값 : (0. 2, 1. 0) Viewposition 위치 Specular 관련. n 0. 0, GL_FALSE n n Light 연산 적용 범위 (front, back) n n 0. 0, GL_FALSE 연산 with Texture 원래는 A, D, S 연산 후 texture n texture 연산 후에 Specular 적용 n GL_SEPARATE_SPECULAR_COLOR, GL_SINGLE_COLOR n kucg. korea. ac. kr Graphics Lab @ Korea University
Material (1/3) n CGVR 4가지 설정. (light과 동일) ambient, diffuse, specular, emissive n 설정 -> RGB n n gl. Enable (GL_MATERIAL); kucg. korea. ac. kr Graphics Lab @ Korea University
Material (2/3) n CGVR gl. Material{if} (face, pname, param); o o face : GL_FRONT, GL_BACK, GL_FRONT_AND_BACK pname Parameter Name (pname) 의미 GL_AMBIENT ambient color of material GL_DIFFUSE diffuse color of material GL_AMBIENT_AND_DIFFUSE ambient and diffuse color of material GL_SPECULAR specular color of material GL_SHININESS specular 지수 GL_EMISSION emissive color of material GL_COLOR_INDEXES Ambient, diffuse, specular color indices kucg. korea. ac. kr Graphics Lab @ Korea University
Material (3/3) n CGVR 예제 GLfloat color[] = { 1. 0, 0. 0, 1. 0 }; gl. Materialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); 재질의 ambient, diffuse -> Red n 물체의 앞, 뒷면 모두에 영향 n kucg. korea. ac. kr Graphics Lab @ Korea University
Mathematics of Lighting (1/4) CGVR n Vertex color = material emission + global ambient light * material’s ambient + total light source n light source 영향 attenuation factor * spotlight effect * (ambient term + diffuse term + specular term) kucg. korea. ac. kr Graphics Lab @ Korea University
Mathematics of Lighting (2/4) n Attenuation factor n Spotlight Effect CGVR 0 : Spotlight 아닐 경우 n 1 : Spotlight 이고, cone 바깥에 vertex n (max{v·d, 0}) ^ GL_SPOT_EXPONENT n o o v : spotlight -> vertex d : spotlight 방향 kucg. korea. ac. kr Graphics Lab @ Korea University
Mathematics of Lighting (3/4) n Ambient term n n Light’s A * Material’s A Diffuse Term n n CGVR (max{L·n, 0}) * Light’s D * Material’s D Specular Term n (max{s·n, 0}) * Light’s S * Material’s S kucg. korea. ac. kr Graphics Lab @ Korea University
Mathematics of Lighting (4/4) n CGVR 다 합하면, Vertex color = emission material + ambientlight model * MA + [ LA *MA + (max { 1 x n , 0 } ) * LD * MD + (max {s x n , 0} )shininess * LS * MS ] kucg. korea. ac. kr Graphics Lab @ Korea University
- Slides: 31