Title: CSL 859: Advanced Computer Graphics
1CSL 859 Advanced Computer Graphics
- Dept of Computer Sc. Engg.
- IIT Delhi
2Lighting in OpenGL
- Per-vertex
- per-pixel with Cg
- Light and Material Properties
- glLightfv RGBA
- Color of light RGBA in 0255
- glMaterialfv RGBA
- Color of material RGBA in 0255
- glColor3f RGBA
- Uses glColorMaterial
3Spectrum
4Color Perception
- Energy?
- Q h/?
- Some colors are perceived brighter
5Definitions
- Energy per unit wavelength?
- Spectral Energy (Q in an interval ??)/?? ? dQ/d?
- Irradiance, H
- Spectral Power reaching surface per unit area
- Radiance
- ?H/?s, per unit solid angle
6Surface Radiance
l
?
n
Surface Radiance L
7Radiance Non-Attenuation
Both detectors see the same Radiance
8Surface Radiance
l
dA
?
?
n
dA cos?
Surface Radiance L
9BRDF
- Bi-directional Reflectance Function
- ?io Lo / Hlight
-i
o
10Types of BRDFs
- Isotropic
- Reflectance independent of rotation about a given
surface normal - Smooth plastics
- Anisotropic
- Reflectance changes with rotation around a given
surface normal - Brushed metal, satin, hair
11Luminous Efficiency
- Lumens per watt (lm/W)
- Photopic efficiency lt 683 lm/W
- _at_ Monochromatic light with ? 555 nm (green).
- Scotopic efficiency lt 1700 lm/W
- _at_ ? 507 nm
12Tri-Stimulus Theory
- Metamers appear the same
- Eyes have sensors
- Rods (low resolution, Peripheral, Many)
- Cones (High res, in fovea, few, 3 types)
- Maximum response at 420 nm (blue),
- Maximum response at 534 nm (Bluish-Green),
- Maximum response at 564 nm (Yellowish-Green).
- Integrating (Filtering) Sensors
13CIE Color Standard
- Three components
- X Y Z
- Y has luminance (perceived brightness)
- X and Z have brightness
- C X Y Z
- Represented as
- x X/(XYZ), y Y/(XYZ), Y
- x and y have chromaticity, Y has luminance
14CIE Chromaticity Diagram
15Color Spaces
- HSV
- RGB
- CMYK
- HDR
- Tone Mapping
16Hue, Saturation, Value
17Color in Hardware
- RED is not the same on every monitor
- Not even the same everytime on the same HW
- User knobs, Ambient lighting
- 01, in a normalized space
- No limit in reality
- 1 gt Maximum screen brightness
- 0 gt Minimum screen brightness
- Why R, G, B?
- Engineering convenience
- Gamma correction
- Gamma can be commonly set by the user
18Hardware Color Mapping
- Normalize each component to 01
- Fixed number of steps
- Monitor dependent
- Typically 255
- Values 0..255 -gt v -gt intensity
- Displayed I a (Maximum I) vy
19Geometry of Local Lighting
- Vertex normals make it smooth
- Lights in Camera space
- Already specified so in OpenGL
L
n
l
v
20Diffuse Reflection
- Reflection uniformly in all directions
- Matte (Non-shiny) appearance
- Eg, chalk
- Most materials are not ideally diffuse
21Specular Reflection
- Light reflects in a single direction
- Shiny
- Eg, silvered mirror
- Most materials are not ideally specular
22Diffuse/Specular Reflection
- Most materials are a combination of diffuse and
specular - Reflection distribution function
- Need not be in a plane
- Need not be isotropic
23Diffuse Reflection
- Lamberts law
- Amount of incident light per unit area is
proportional to the cosine of the angle between
the normal and the light rays
l3
l2
n
l1
surface
24Diffuse Reflection
- Unit vector l points to the light source
cl
n
l
fdiff
25Directional Light
- Distant light source
- A unit length direction vector d and a color c
- l -d
- Color shining on the surface cl c
26Point Lights
- Radiates light equally in all directions
- Intensity from a point light source drops off
proportionally to the inverse square of the
distance from the light
p
cpnt
l
n
cl
v
fdiff
27Attenuation
- Sometimes, inverse square falloff behavior is
hacked approximated - A common damping of distance attenuation is
28Multiple Lights
- Additive
- Interference does happen
- E.g., soap bubbles
29Ambient Light
- Poor mans global illumination
- Same amount everywhere
- Often, famb is set to equal fdif
30Blinns Model
- Smooth gt well defined small highlights,
- Rough gt Blurred, larger
- Surface roughness modeled by microfacets
- Distribution of microfacet normals
- Polished
- Smooth
- Rough
- Rougher
31Specular Highlights
- To compute the highlight intensity, we start by
finding the unit length halfway vector h, which
is halfway between the vector l pointing to the
light and the vector e pointing to the eye
(camera)
n
h
cl
e
l
fspec
32Specular Highlights
- The halfway vector h represents the direction
that a mirror-like microfacet would have to be
aligned in order to cause the maximum highlight
intensity
n
h
cl
e
l
fspec
33Specular Highlights
- The microfacet normals generally point in the
direction of the macro surface normal - The further h is from n, fewer facets are likely
to align with h - The Blinn lighting model
- s is shininess or specular exponent
34Specular Highlights
- Higher exponent more narrow the highlight
35Shininess
n 1
n 5
n 10
n 50
36Specular Highlights
- To account for highlights, we simply add an
additional contribution to our total lighting
equation - Blinn lighting model.
37Classic Lighting Models
- Lambert
- Blinn
- Phong
- Considers angle between normal and viewer
- Cook-Torrance
n
n
h
cl
cl
e
e
l
l
fspec
fspec
Phong
Blinn
38Cook Torrance
- Contributors
- Torrance Sparrow (1967)
- Blinn (1977)
- Models of Light Reflection for Computer
Synthesized Pictures, SIGGRAPH77 - Cook Torrance (1982)
- A Reflectance Model for Computer Graphics, ACM
TOG 1(1) - Thermodynamics and geometric optics
- Explains off-cpecular peaks
- No electromagnetics
- Fails for very smooth surfaces
39Cook Torrance
- Ei Ii (N.L) d?i
- R Ir/Ei
- Ir R Ii (N.L) d?i
- R sRs dRd, s d 1.
- IrA RA IiA f
- f 1/? ? (N.L) d?i
- Shortcut, f 1
40Intensity of Reflected Light
- IR IiARA ?l (Iil (NLl) ??il(sRs dRD))
l Individual lights Iil Average intensity of
the incident light N Surface unit normal Ll
Unit vector in the direction of light l ??il
solid angle of a beam of incident light
41Cook-Torrance Model
F Fresnel term D Facet slope distribution
Fraction of facets oriented along H
(Roughness) G Geometrical attenuation factor
(occlusion) V Unit vector in the direction of
the viewer
42Roughness
- Blinn
- D ce-(?/m)2
- ? angle between H and N
- (H angular bisector of V and L)
- m root mean square (rms) slope of the facets
- Beckmann
- D 1/(m2cos4?) e-(tan2?/m2)
43Beckmann vs Blinn
m 0.2
m 0.6
44Geometric Attenuation
- 0 lt G lt 1
- No occlusion to full occlusion
45Geometric Attenuation
46Fresnel Factor
- Wavelength dependent.
- Refractive Index
- Mirror-like at grazing angles
47Some Examples
Material s d m
Carbon .3 .7 .4
Rubber .4 .6 .3
Obsidian .8 .2 .15
Lunar Dust 0 1 X
Olive drab .3 .7 .5
Rust .2 .8 .35
48Some Examples
- Metal refractive index absorption coeff.
- Silver 0.177 3.638
- Copper 0.617 2.63
- Steel 2.485 3.433
49Results of Cook-Torrance
Copper vase
50Compared to Phong
30o Incidence
70o Incidence
Torrance et al.
Phong
51Shading
- Gouraud
- Light vertices
- Interpolate colors
- glShadeModel(GL_SMOOTH)
- Phong
- Per-pixel (Phong) lighting
- Interpolate normals
- Need pixel-programs
52Advanced Lighting
- Shadows
- Accurate reflection models
- Procedural shaders
- Global Illumination
- Volumetric effects (fog, translucency)
- Lens imperfections
- Exposure ( dynamic range)
53Shadow Map
Scene
54Shadow Map
- Find x,y in the light space
- Unproject camera, then Project light
- But x and y may not be integers
- Find nearest integers?
- Read Depth buffer
- Compare projected z with stored z.