fa09_CG_06

advertisement
School of Computer Science
University of Seoul
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Light and Matter
Light Sources
The Phong Reflection Model
Computation of Vectors
Polygonal Shading
Approximation of a Sphere by Recursive Subdivision
Light Sources in OpenGL
Specification of Materials in OpenGL
Shading of the Sphere Model
Global Illumination

Rendering equation [Kaj86]
Integral eq. resulted by recursive scattering
 Physics-based, slow to compute


Radiosity, raytracing (Ch.12) and photon
mapping
Approximation of rendering equation for particular
surfaces
 Still slow


Phong reflection model

Fast!
Proposed in “The rendering equation” (by
James Kajiya, 1986)
 Based on “conservation of energy”

FEM (Finite Element Method) applied to
solve the rendering equation
 For scenes with diffuse surfaces


Supported by 3D Max, EIAS, etc.
(image courtesy of David Stoddard, EIAS)
(image courtesy of JCM animation, EIAS)
Rendering by tracing rays for each pixel
from the viewer (camera)
 Suitable for reflective surfaces

(image courtesy of Wikipedia)

Supported by POV-Ray, YafaRay, etc.
(“Glasses” by Gilles Tran, POV-Ray)
(“Nikon” by Bert Buchholz, YafaRay)

Rays from the light source & camera are
traced independently
Image courtesy of Wikipedia)
Reflected, absorbed and transmitted
 Depends on

 opaqueness
 wavelength-
“Why does an object look red?”
 roughness - “Why does an object look shiny?”
 Orientation
 etc.
Specular surfaces
 Diffuse surfaces
 Translucent surfaces

Can be modeled by an illumination function
I(x,y,z,,,)
 Each frequency considered
independently
 Total contribution can be
computed by integration
 Directional properties can
vary with frequency
 Too complicated to compute

Four types: ambient lighting, point sources,
spotlights, and distant lights
 Light sources with three components, RGB
- based on “three-color theory”
 Each component calculated independently
 Intensity or luminance:
 Ir 



I  I g 
 I b 
Models uniform illumination
 Simplified as an intensity that is identical at
every point in the scene:

 I ar 
I a   I ag 
 I ab 

Located at p0:
 I r p 0 
Ip 0    I g p 0 
 I b p 0 
Intensity received at p: ip, p 0   p  p 2 Ip 0 
0
 High contrast than surface light
 Can be made soft by
2 1
the distance term: a  bd  cd 

1
Cone-shaped directional range
 Distribution of the light within the cone
usually defined by cos e 

Rays can be assumed parallel
 Direction instead of location:

 x
 y
p0   
z
 
1 
 x
 y
p0   
z
 
0
Introduced by Phong
 Four vectors used
 Three types of material-light interactions –
ambient, diffuse, and specular
 Local model

(image courtesy of Wikipedia)



i-the light source:
L ia   Lira

L i  L id    Lird
 L is   Lirs
Liga
Ligd
Ligb
 R ia   Rira

R i  R id    Rird
 R is   Rirs
Riga
Rigd
Rigb
Liba 

Libd 
Libs 
Reflection terms for a material:
Riba 

Ribd 
Ribs 
Contribution of each light color (e.g., red):
I ir  Rira Lira  Rird Lird  Rirs Lirs  I ira  I ird  I irs

Contribution of all sources (e.g., red):
I r   I ira  I ird  I irs   I ar
i
Intensity same at every point on the surface
 Depends on

 Material

property
Independent of
 Location
of the light source
 Location of the viewer
I a  k a La
Characterized by rough surfaces
 Assumed to be “perfectly diffuse”
 Depends on

 Material
property
 Location of the light source

Independent of
 Location
of the viewer

Lambert’s law (for perfectly diffuse surface):
Rd  cos 
kd
Id 
Ld max l  n,0 
2
a  bd  cd
Characterized by smooth surfaces
 Depends on

 Material
property
 Location of the light source
 Location of the viewer

“shininess coefficient” ()

ks

Is 
Ls max r  v  ,0
2
a  bd  cd




1





I  Ia  Id  Is 
k
L
max
l

n
,
0

k
L
max
r

v
,0  k a La
d d
s s
2
a  bd  cd
Modified by Blinn  a.k.a. “Blinn-Phong
Shading Model”
 Simplified by halfway angle (h) for faster
calculation
lv

 rv

replaced by n h
h
lv
Faster calculation when the light
and the viewer are at infinity (WHY?)
 GL_LIGHT_MODEL_LOCAL_VIEWER

Default model in OpenGL

How to compute the normal vector of
a
triangle?
 a (smooth) surface?

How to compute reflection vector?
r  2l  nn  l

Flat shading
 The

normal of the first vertex used
Gouraud shading
 Lighting
calculation at vertices
 Linearly interpolated at each fragment
 Artifacts for coarse polygon
Lighting computation at each fragment
 Not directly supported by OpenGL
 Can be implemented using GLSL (OpenGL
Shading Language)


Enable/disable:
glEnable(GL_LIGHTING);
 glEnable(GL_LIGHT#);

 At least 8 lights
 Positional or directional light:


glLight*(GL_LIGHT#, GL_POSITION, position);
Ambient, diffuse, specular components:

glLight*(GL_LIGHT#, GL_*, value);
 GL_AMBIENT
 GL_DIFFUSE
 GL_SPECULAR

Global ambient:


Distance-attenuation model:


glLightModel*(GL_LIGHT_MODEL_AMBIENT, value);
glLight*(GL_LIGHT#, GL_*, value);
 GL_CONSTANT_ATTENUATION (a)
 GL_LINEAR_ATTENUATION (b)
 GL_QUADRATIC_ATTENUATION (c)
Spotlight:

glLight*(GL_LIGHT#, GL_*, value);
 GL_SPOT_DIRECTION
 GL_SPOT_EXPONENT
 GL_SPOT_CUTOFF ([0,90] or 180)
1
a  bd  cd 2

Infinite/local viewer:
 glLightModel*(GL_LIGHT_MODEL_LOCAL_VIEW
ER, value);

One/two-sided lighting:
 glLightModel*(GL_LIGHT_MODEL_TWO_SIDED,
value);

Light sources are transformed by
modelview matrices!


Material properties are OpenGL states!
Ambient, diffuse, specular, emissive:
 glMaterial*v(face, GL_*, value);


GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION,
GL_DIFFUSE_AND_SPECULAR
Emissive property
 Does not affect any other surface (it’s not a light!)
 Simply adds color




Shininess:
 glMaterial*(face, GL_SHININESS, value);
Front/back/front&back:
 GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
glColorMaterial
Various materials: refer to teapots.c!

Try yourself!!!
Download