Title: Introduction to Computer Graphics
1??????? 729441 Chapter 4 Lighting Shading
2Wireframe
?????
????????? ?????????????????????????? (shading
algorithm)
????????? ?????? ?????????
3(No Transcript)
4Rendering
- ????????????? pixel
- ??????????(??? pixel ) ?????????????
- ?????????????????? (normal direction)
- ?????????????????? (luminaires)
- ??????????????????????????????????????
- ????????????????????????????????????
5Rendering Algorithms
- local illumination algorithms
- ?????????????????????????????????????
?????????????????????????????????????????? - global illumination algorithms
- ???????????????????????????????????????????
6Local VS Global Illumination
7Local VS Global Illumination
Global
Local
8Scene Geometry
9Radiosity
10Ray-Tracing
11Illumination Variables
- ????????????
- ???????
- ?????????
- ?????
- ??????????????????????
- ?????????????????????????
- ?????????????????????????????????
- surface normal
- ??????????????????? view plane
p0
N
p
12A Model for Lighting
- ???????????????????????????????
- ?????????????????????????????????????????????????
- direct light ????????????????????????????????
- indirect light ???????????????????????????????????
?????? - ?????????????????????????????????????????????
13A Model for Lighting
- ????????????
- ?????????????
- ?????????
- ??????????????????
- ???????????????????
- ???????????
14Lighting in Computer Graphics
- ????????? projection plane
- ????????????????????? COP ???????
- projection plane ????????????????????
- ????? pixel ?????????? interaction model
15????????????
- Ambient
- ???????????????????????????????????????????????
????????????????????? Why?
???????????????? ???? ??????????????????????
16????????????
- Diffuse
- ????????????????????????????????????????
Specular ?????????????????????????????????
????? ??????????
Emission ????????????????????????????????????
17Interaction Between Light and Materials
- ?? ????????? ????????? ???????????????????????????
??????????????????????? - ?????????????????????????????????????????(??????)
???????????? ????????????????????????????? - Shading ?????????????????????????????????
18Material Model
- ???????????????????????????????????????? ????
??????????????????????
19Material Model
20Specular Surfaces
- ????????????????????
- ?????????????????????????????????
- ????? pecfectly specular surface
- ??????????????????????????
21Diffuse Surfaces
- ?????????
- ??????????????????????
- ?????????????????????
22BRDF
- Bi-directional Reflectance Distribution Function
- ????????????????????????????????????
-
Ideal specular
Ideal diffuse
Rough specular
Directional diffuse
23Illumination Examples
????????????????????specular
?????????????????????(shininess coefficient)
???????????????????? diffuse
24??????????????????????
directional
positional
25?????????????????????
- ???????????????????
- ?????????????????????????????????
- ?????????????????????????
- ??????????????????????????????????????????????????
????? ???? ?????????? - ??????????????????
- ???????????????????????????????
- ???????????????????????????????????????????????
- ??????????????????????????????????????????????????
??????????????
26?????????????????????
- ??????????????? spot light
- ???????????????????????????
- ??????? spor light
27Shading
28Lighting Models
- illumination model
- surface rendering algorithm
29Shading
- ?????????????????? effect ????????????????????????
?????????????? - ??? normal vector ???????????????????????????????
?????????????????????
30Example
31Normal Vector
n
p0
p1
p2
32Shading
- Flat Shading
- ???????????????????? normal vector
??????????????? - Smooth Shading
- ??????????????????????????????????????????????????
??? - ?? 2 ????
- Gouraud Shading
- Phong Shading
33Flat Shading
- Flat Shading
- ???????????????????? normal vector
??????????????? - ??????????????????? 1 ??????????
- ????????????????????????????????????
34Gouraud Shading
- Gouraud Shading
- ??????????????????? normal vector ?????????
- ????? interporation ??????????????????????????????
??? - ?????????
- ???????????? Flat Shading
35Normal Vector ?????????
- Normal Vector ?????????
- normal vector ????????????????????????????
???????????? - ????? normal vector ?????????????????????????
effect ?????? - ?????????
- ?????????????? normal vector ?????????????????
- ??????????????????
36Phong Shading
37???????????
38Lighting in OpenGL
- ???????????????????? 8 ???
- GL_LIGHT0,GL_LIGHT1,,GL_LIGHT7
glEnable(GL_LIGHTING) glEnable(GL_LIGHT0)
39Lighting in OpenGL
glLightfv()
glLightfiv(GL_LIGHT0, param, value)
GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_POSITION GL_S
POT_DIRECTION GL_SPOT_EXPONENT GL_SPOT_CUTOFF GL_C
ONSTANT_ATTENTUATION GL_LINEAR_ATTENUATION GL_QUAD
RATIC_ATTENUATION
Light source color intensity
spotlight parameters
irradiance control
40Light Color
- float amb 0.2, 0.2, 0.2. 1.0
- glLightfv(GL_LIGHT0, GL_AMBIENT, amb)
41Light Position
Glfloat position x,y,z,w
1.0f,2.0f,1.0f,1
Glfloat position x,y,z,w
0.0f, 0.0f, 1.0f, 0.0
glLightfv(GL_LIGHT0,GL_POSITION,position)
42glNormal()
- glBegin(GL_QUADS)
- glNormal3f(0,1,0)
- glVertex3f(1,0,-1,0)
- glVertex3f(1,0,1,0)
- glVertex3f(-1,0,1,0)
- glVertex3f(-1,0,-1,0)
- glEnd()
43Shading and OpenGL
glShadeModel(GL_FLAT)
glShadeModel(GL_SMOOTH)
44Material Model
- ????????????????????????????????????????
????????????????????????????????? 0?
?????????????????????
45OpenGL Material Properties
glMaterialfv()
glMaterialifv(face, param, value)
GL_FRONT GL_BACK GL_FRONT_AND_BACK
GL_AMBIENT GL_DIFFUSE GL_AMBIENT_AND_DIFFUSE GL_SP
ECULAR GL_EMISSION GL_SHININESS
RGB Values
Phong Exponent
46OpenGL Material Properties
glMaterialfv()
Glfloat mat_ambient 1.0,1.0,1.0,1
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient)
47OpenGL Material Properties
glMaterialfv()
Glfloat mat_diffuse 1.0,1.0,1.0,1
Glfloat mat_specular 0.5,0.4,1.0,1
Glfloat mat_shininess 128.0
glMaterialfv(GL_FRONT,GL_DIFFUSE, mat_diffuse)
glMaterialfv(GL_FRONT,GL_SPECULAR, mat_specular)
glMaterialf(GL_FRONT,GL_SHININESS, mat_shininess)
48Example
(0.0,0.0,1.0,1.0)
(0.0,0.0,4.0,1.0)
(0.0,0.0,2.0,1.0)
49Example
(0.0,0.0,10.0,1.0)
(0.0,0.0,1.0,0.0)
50Example
51Example
????
????
52Example
53(No Transcript)
54Display List
- ????????????????????
- ???????????? memory
- ????????????????????????????? display list
- ???????????????????????????
???????????? Display List
- ?????????????????????????????????
- ?????????? texture ???????????
- ??????????????????????????????? Tree ???
55Display List Model
glBegin(GL_LINES) glVertex() . glEnd()
56???????????? Display List
Gluint glGenLists(int count)
- ????????????????? display list
- ??? ID(????)
- count ??????????? display list
- ???????????????
- Glboolean glIslist(Gluint list)
- ?????????????? list ?????????????????
57?????????? Display List
Glvoid glNewList(Gluinit Listindex,Glenum
Mode) Glvoid glEndList() Listindex ????
display list Mode GLCOMPILE, GLCOMPILE_AND_EXECUT
E
glNewList( 1, GL_COMPILE ) glColor3fv(
colorVector ) glTranslatef( 1.5, 0.0, 0.0
) glBegin( GL_TRIANGLES ) glVertex2f( 0.0, 0.0
) glVertex2f( 1.0, 0.0 ) glVertex2f( 0.0, 1.0
) glEnd() glEndList()
58?? Display List
GLvoid glDeleteLists( GLuint rstIndex, GLsizei
count )
59Example
glNewList( 1, GL_COMPILE ) /????? 1
/ drawFin() glEndList() glNewList( 2,
GL_COMPILE ) / ????? 2 / drawFish() glEndLi
st() glNewList( 3, GL_COMPILE ) / ?????
3(run 1?2/ glCallList( 1 ) glCallList(
2 ) glEndList() glCallList( 3 ) /
drawFin() drawFish() /
60Display List
glNewList( 1, GL_COMPILE ) / define ???? 1
/ drawNewFin() glEndList() glCallList( 3
) / drawNewFin() drawFish() /