Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
1
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 1
University ofUniversity ofBritish ColumbiaBritish Columbia
Chapter 7
Illumination Models & Shading
University ofUniversity ofBritish ColumbiaBritish Columbia
Shading Models
Realistic interaction of light and objects Simulate physical phenomena
Fast - Fake it!!! Ignore real physics, approximate the look
Physically based reflection modelsBRDFs: Bidirectional Reflection Distribution Functions
2
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 2
University ofUniversity ofBritish ColumbiaBritish Columbia
Photorealistic Illumination
[[electricimage.comelectricimage.com]]
University ofUniversity ofBritish ColumbiaBritish Columbia
Local vs. Global Illumination Models
Local model - interaction of each object with light
Global model: interactions between objects
3
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 3
University ofUniversity ofBritish ColumbiaBritish Columbia
Fast Local Illumination
University ofUniversity ofBritish ColumbiaBritish Columbia
Light Sources
Point sourcelight originates at a pointRays hit planar surface at different angles
Parallel sourcelight rays are parallel
Rays hit a planar surface at identical anglesMay be modeled as point source at infinityDirectional light
4
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 4
University ofUniversity ofBritish ColumbiaBritish Columbia
Light Sources
Area sourceLight originates at finite area in
space.In-between point and parallel sources
spotlightsposition, direction, angle
ambient light (environment light)
University ofUniversity ofBritish ColumbiaBritish Columbia
Light Sources - OpenGL
Specify parametersglLightfv(GL_LIGHTi,GL_POSITION,light[])i – between 0 & 8 (or more)Directional Point source Spotlight has extra parameters:
GL_SPOT_DIRECTION, GL_SPOT_EXPONENT, GL_SPOT_CUTOFF
Area source – too complex for projective pipeline (e.g. OpenGL)
[ ]0zyx
[ ]1zyx
5
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 5
University ofUniversity ofBritish ColumbiaBritish Columbia
non-directional light – environment lightObject illuminated with same light everywhere
Looks like silhouetteIllumination equation
- ambient light intensity- fraction of this light reflected from surface
Defines object color
Ambient Light
I I ka a=aI
ak
University ofUniversity ofBritish ColumbiaBritish Columbia
Diffuse Light
Dull surfaces - such as solid matte plastic-reflect uniformly in all directionsThis is called diffuse or Lambertian reflectionFor light source normalized direction L & surface with normal N reflected light is proportional to LN
LN
11
θ
6
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 6
University ofUniversity ofBritish ColumbiaBritish Columbia
Illumination equation is now:
- point source’s intensity- surface diffuse reflection coefficient
Can we locate light source from shading?
Diffuse Reflection
I I k I k N L I k I ka a p d a a p d= + ⋅ = +( ) cosθ
Ipkd
University ofUniversity ofBritish ColumbiaBritish Columbia
Shiny objects (e.g. metallic) reflect light in preferred direction R determined by surface normal N.
Most objects are not ideal mirrors - reflect in the immediate vicinity of R
Specular Reflection
NL RVθθ α
7
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 7
University ofUniversity ofBritish ColumbiaBritish Columbia
Specular
Phong Model (Phong Bui-Tuong, 1975)Assume exponential attenuation of formComputing reflection direction R of L
N and L are unit length!
LL RR =2(N=2(N··L)L)··NN--LL
NN
--LL
(N(N··L)L)··NN
αncos
University ofUniversity ofBritish ColumbiaBritish Columbia
Specular Reflection (Phong Model)
Illumination equation:
- Specular reflection coefficient- Specularity exponent
I I k I k N L k R Va a p d sn= + ⋅ + ⋅( ( ) ( ) )
ksn
8
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 8
University ofUniversity ofBritish ColumbiaBritish Columbia
Specular Reflection (cont’d)
Exponent n of cosine controls concentration of attenuation function:
No physical basis BUT looks good
cosα cos8 α cos128 α
University ofUniversity ofBritish ColumbiaBritish Columbia
Specular
Blinn-Phong model (Jim Blinn, 1977)Variation with better physical interpretation
H: halfway vector; n:shininess
2/)( with );()()( VLHINHkI inn
sout +=⋅⋅⋅= xx
LL
NNVVHH
9
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 9
University ofUniversity ofBritish ColumbiaBritish Columbia
Illumination Equation
For multiple light sources:
- distance between surface and light source + distance between surface and viewer (Heuristic atmospheric attenuation)Other attenuations: e.g. quadratic
))()(( npspd
p p
paa VRkLNk
dI
kII ⋅+⋅+= ∑
pd
shadingmodel
University ofUniversity ofBritish ColumbiaBritish Columbia
Lighting in OpenGL
Light source: amount of RGB light emittedvalue represents percentage of full intensity,e.g., (1.0,0.5,0.5)every light source emits ambient, diffuse, and specularlight
Materials: amount of RGB light reflectedvalue represents percentage reflectede.g., (0.0,1.0,0.5)
10
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 10
University ofUniversity ofBritish ColumbiaBritish Columbia
In OpenGL
- surface color (RGB)
Modify by glMaterialfv(GL_FRONT_AND_BACK , pname, RGB[] )
pname - GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR
Light source properties (also RGB) glLightfv(GL_LIGHTi,pname,light[])
sda kkk ,,
University ofUniversity ofBritish ColumbiaBritish Columbia
Lighting in OpenGL
glLightfv(GL_LIGHT0, GL_AMBIENT, amb_light_rgba );glLightfv(GL_LIGHT0, GL_DIFFUSE, dif_light_rgba );glLightfv(GL_LIGHT0, GL_SPECULAR, spec_light_rgba );glLightfv(GL_LIGHT0, GL_POSITION, position);glEnable(GL_LIGHT0);
glMaterialfv( GL_FRONT, GL_AMBIENT, ambient_rgba );glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuse_rgba );glMaterialfv( GL_FRONT, GL_SPECULAR, specular_rgba );glMaterialfv( GL_FRONT, GL_SHININESS, n );
11
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 11
University ofUniversity ofBritish ColumbiaBritish Columbia
Flat Shading
Illumination value depends only on polygon normal
each polygon colored with uniform intensityNot adequate for polygons approximating smooth surfaceLooks non-smooth
worsened by Mach bands effect
University ofUniversity ofBritish ColumbiaBritish Columbia
Gourard Shading
Polyhedron - approximation of smooth surfaceAssign to each vertex normal of original surface at pointIf surface not available use estimate normal
Compute illumination intensity at vertices using those normals Linearly interpolate vertex intensities over interior pixels of polygon projection
n1 n3
n2
12
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 12
University ofUniversity ofBritish ColumbiaBritish Columbia
( , )x y
Gourard Shading (cont’d)
Assign pixel color during scan conversion
Can Gourard shading support specularreflection ?
c1
c2 c3
scanline Y=y
c c c4 1 1 1 21= + −α α( ) c c c5 2 1 2 31= + −α α( )
c( , ) ( )x y c c= + −α α3 4 3 51
University ofUniversity ofBritish ColumbiaBritish Columbia
Flat Shading
Example:
13
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 13
University ofUniversity ofBritish ColumbiaBritish Columbia
Gouraud Shading
Example:
University ofUniversity ofBritish ColumbiaBritish Columbia
n x y n nc x y Ill n x y
( , ) ( )( , ) ( ( , ))
= + −
=
α α3 4 3 51
Phong Shading
Interpolate (in image space) normal vectors instead of intensitiesApply illumination equation for each interior pixel with its own normal
n1
n2 n3
scanline Y=y
n n n4 1 1 1 21= + −α α( ) n n n5 2 1 2 31= + −α α( )
( , )x y
14
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 14
University ofUniversity ofBritish ColumbiaBritish Columbia
Shading
Phong shading is clearly more expensive (why ?)- but well worth the effort
Can achieve specular effects
Both Gourard & Phong schemes are performed in the image plane ⇒ view dependent
Can cause artifacts during animationshadingalgo
University ofUniversity ofBritish ColumbiaBritish Columbia
Materials
Bi-directional Reflectance Distribution Function (BRDF):
Describes fraction of light reflected for all combinations of incoming (light) and outgoing (viewing) directionsColor channels (R, G, B) are treated separately
Actually: wavelengths (see later in course)
15
Computer GraphicsComputer Graphics
Copyright 2004, Alla Sheffer, UBC
Illumination Models
Page 15
University ofUniversity ofBritish ColumbiaBritish Columbia
Materials
Bi-directional Reflectance Distribution Function (BRDF):
fr(l→v) is called BRDF(t,n,b) islocal coordinate frame(normal, tangent, binormal)
)()()()('),,,()(
xlnvlxx
inr
inoutoutininrout
IfIfI
⋅⋅⋅→=⋅θφθφ= nn
tt
bb
ll
vv
φφinin
θθinin
University ofUniversity ofBritish ColumbiaBritish Columbia
Materials
Polar plot of BRDFFix incoming light direction lPlot fr(l→v)· v for all viewing directions vWorks for 2D and 3D plotsExample: 2D polar plot for diffuse BRDF