31
Graphics kucg.korea.ac.kr Graphics Lab @ Korea University OpenGL 세세세 redbook 4, 5 세 김김김

OpenGL 세미나 redbook 4, 5 장

  • Upload
    hestia

  • View
    143

  • Download
    0

Embed Size (px)

DESCRIPTION

OpenGL 세미나 redbook 4, 5 장. 김우림. 4 장 Color. Color Perception Computer Color RGBA vs Color-Index Shading Model. Blue. Red. M. Green. Y. C. Color Perception. 실제 눈에는 3 종류의 cone RGB 각각에 민감한 cone Cone 혼합해서 색 인식 컴퓨터 사람 눈 흉내 RGB 조합으로 색 저장 , 표현. Computer Color (1/2). - PowerPoint PPT Presentation

Citation preview

Page 1: OpenGL  세미나 redbook 4, 5 장

Graphics

kucg.korea.ac.kr Graphics Lab @ Korea University

OpenGL 세미나redbook 4, 5 장

김우림

Page 2: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

4 장 Color

Color Perception Computer Color RGBA vs Color-Index Shading Model

Page 3: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Color Perception

실제 눈에는 3 종류의 cone RGB 각각에 민감한 cone Cone 혼합해서 색 인식

컴퓨터 사람 눈 흉내 RGB 조합으로 색 저장 , 표현

Red

Blue

Green

M

Y

C

Page 4: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Computer Color (1/2)

Pixel 마다 color data 저장 System 마다 다르다 Pixel 당 8bit -> 256 색 Pixel 당 24bit -> 2^24 색 Color Buffer 에 저장

Bitplane : 특정 색에 할당한 bit 수 glGetIntegerv(GL_RED_BITS)

Page 5: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Computer Color (2/2)

RGB 모드 rgb 각각 0.0~1.0 {0.0, 0.0, 0.0} -> 검정색 pixel 은 r,g,b 각각의 값 가짐

RGBA 모드 RGB 모드 + alpha Alpha : 투명도 pixel 은 r,g,b,a 각각의 값 가짐

Color-index 모드 Color table 사용 pixel 은 index 를 가짐

Page 6: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

RGBA vs Color-Index (1/5)

RGBA Display Mode R,G,B,A 마다 다른 bitplane float 형태 Alpha 값은 색깔에 직접 영향 X

Page 7: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

RGBA vs Color-Index (3/5)

OpenGL 색 지정 함수

Byte, short, int, float, double

glColor3{b s i f d ub us ui} (GLfloat r, GLfloat g, GLfloat b);

glColor4f (GLfloat r, GLfloat g, GLfloat b, GLfloat a);

glColor3fv (Glfloat * array);

glColor4fv (Glfloat * array);

Page 8: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

RGBA vs Color-Index (2/5)

Color-Index mode Color map

미리 table 생성 Pixel 은 color map 의 index 가짐 같은 index 를 가진 pixel -> 같은 색

Page 9: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

RGBA vs Color-Index (4/5)

OpenGL 색 지정 함수

glIndex3f (GLfloat color); Color index 설정

glClearIndex (Glfloat cindex); Clear 색 지정 . RBG : glClearColor (r,g,b,a); glClear () 시 사용

Page 10: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

RGBA vs Color-Index (5/5)

RGBA mode 쓰자 !!

OpenGL 기능들 충분히 이용 위해

Shading, lighting, texture mapping, fog

특별한 목적 시 color-index

Page 11: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Shading Model

OpenGL 기본 shading Flat shading – 단일 vertex Smooth shading – vertex 들의 평균

Shading 지정 함수 glShadeModel (GLenum mode);

mode = GL_SMOOTH, GL_FLAT

v0 (1,0,0)

v2 (0,0,0) v1 (0,1,0)

Page 12: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

5 장 Light

실제 vs OpenGL Lighting 종류 Light source Light 위치 , 방향 Lighting Model Material Mathematics of Lighting

Page 13: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

실제 vs OpenGL

실제 매우 복잡 . 표면의 반사 , 흡수 . 표면이 광원 역할 . 다양한 재질 .

OpenGL Light source : RGB 로 구성 Light source 여러 개 . On/off 가능 Suface 의 Material 과의 상호작용

OpenGL 기본 lighting model 속도 중시 . 단순하다 . 사실적 표현 -> 직접 구현 필요 .

Page 14: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Lighting 종류

Ambient 한 방향서 오는 light 주변광 . 모든 pixel 에 동일하게 영향

Diffuse 한 방향서 오는 light 모든 방향으로 반사 표면 접선 영향 l x n

Specular 반짝임 . 관측자 eye 영향 s x n

Emissive Material 이 스스로 빛을 낼 경우

Page 15: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Light source (1/6)

glEnable (GL_LIGHTING) glDisable (GL_LIGHTING) glEnable (GL_LIGHT0)

glLight{if} (light, pname, param); Light : GL_LIGHT0, GL_LIGHT1 … GL_LIGHT7

Page 16: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Light source (2/6)

pnameParameter 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

Page 17: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Light source (3/6)

param 지정할 값 . 일반적으로 Glfloat 배열 .

GLLight() 예제

GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position);

Page 18: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Light source (4/6)

Directional Light 광원이 무한한 곳에 위치 .

( 태양 ) 방향만 고려 . 위치 고려

X.

GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

glLightfv(GL_LIGHT0, GL_POSITION, light_position);

Page 19: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Light source (5/6)

Positional Light 점 광원 . ( 전구 ) 광원 중심으로 모든 방향에

영향 .

GLfloat light_position[] = { 0.0, 0.0, 1.0, 1.0 };

glLightfv(GL_LIGHT0, GL_POSITION, light_position);

Page 20: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Light source (6/6)

Spot Light 원뿔 모양의 빛 . 특정 방향으로 영향 .

GLfloat direction[] = { -1.0, -1.0, 0.0 };

glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction);

glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0);

Page 21: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Light 위치 , 방향 (1/3)

OpenGL Light : 물체로 취급 Modelview 행렬에 영향 받음

고정된 Light Viewport, projection 행렬 설정 Modelview 행렬 초기화 light 위치 지정

Page 22: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Light 위치 , 방향 (2/3)

Object 에 상대적 Light Object 의 변환 행렬 후 Light 위치 지정

glPushMatrix();        glTranslatef(0.0, 0.0, -5.0);         

   glRotated((GLdouble) spin, 1.0, 0.0, 0.0);             glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glutSolidCube (1.0);        glPopMatrix();

Page 23: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Light 위치 , 방향 (3/3)

Viewport 따라다니는 Light Viewport 변환 시에 Light 위치 지정

Glfloat posiion[] = { 0.0, 0.0, 0.0, 1.0 };

glMatrixMode(GL_MODELVIEW);glLoadIdenty();gluLookAt ();glLightfv (GL_LIGHT0, GL_POSITION, posiion);

Page 24: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Lighting Model

Global ambient light intensity 기본값 : (0.2, 0.2, 0.2, 1.0)

Viewposition 위치 Specular 관련 . 0.0, GL_FALSE

Light 연산 적용 범위 (front, back) 0.0, GL_FALSE

연산 with Texture 원래는 A, D, S 연산 후 texture texture 연산 후에 Specular 적용 GL_SEPARATE_SPECULAR_COLOR, GL_SINGLE_COLOR

Page 25: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Material (1/3)

4 가지 설정 . (light 과 동일 ) ambient, diffuse, specular, emissive 설정 -> RGB

glEnable (GL_MATERIAL);

Page 26: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Material (2/3)

glMaterial{if} (face, pname, param); 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

Page 27: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Material (3/3)

예제

재질의 ambient, diffuse -> Red 물체의 앞 , 뒷면 모두에 영향

GLfloat color[] = { 1.0, 0.0, 0.0, 1.0 };

glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); 

Page 28: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Mathematics of Lighting (1/4)

Vertex color

= material emission +

global ambient light * material’s ambient +

total light source

light source 영향attenuation factor * spotlight effect *

(ambient term + diffuse term + specular term)

Page 29: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Mathematics of Lighting (2/4)

Attenuation factor

Spotlight Effect 0 : Spotlight 아닐 경우 1 : Spotlight 이고 , cone 바깥에 vertex (max{v·d,0}) ^ GL_SPOT_EXPONENT

v : spotlight -> vertex d : spotlight 방향

Page 30: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Mathematics of Lighting (3/4)

Ambient term Light’s A * Material’s A

Diffuse Term (max{L·n, 0}) * Light’s D * Material’s D

Specular Term (max{s·n, 0}) * Light’s S * Material’s S

Page 31: OpenGL  세미나 redbook 4, 5 장

kucg.korea.ac.kr

CGVR

Graphics Lab @ Korea University

Mathematics of Lighting (4/4)

다 합하면 ,

Vertex color = emission material +

ambientlight model * MA +

[ LA *MA +

(max { 1 x n , 0 } ) * LD * MD +

(max {s x n ,0} )shininess * LS * MS ]