Marc Alexa, TU Berlin
CG
1
Computer Graphics I
Lighting, Shading
Marc Alexa, TU Berlin
CG
2
3D Graphics Pipeline
§ Application
§ Geometry
• Perspective Transformation, canonical view volume
• Clipping
• Culling
• Approximation of light transport
• Projection
§ Rasterization
§ Output
Marc Alexa, TU Berlin
CG
3
Local shading model
§ Shading
• Calculating the lightness (gray-value) of primitives
• Model typically considers
– Light source (position, direction, intensity, spectral properties), and
– Surface properties (geometry, reflection behavior) of objects.
• Simulation of light transport
• Real time computation requires simplified models
• Shading models are based on physical laws of optics and human
perception
Marc Alexa, TU Berlin
CG
4
Light / object interaction
§ Light in CG is modeled with 3 quantities
§ Interaction with object surface = change of the three
quantities
• Material properties = type of change and dependence on geometry
of situation
§ We limit interaction to reflection, only
Marc Alexa, TU Berlin
CG
5
Light sources
§ Directed / parallel light source
– Position is point at infinity: (x,y,z,0)T
§ Point light source
– Finite position: (x,y,z,1)T
§ Spot
– Position, direction, opening angle
§ Ambient light
Marc Alexa, TU Berlin
CG
6
Ambient light
§ Scene with only ambient light
Marc Alexa, TU Berlin
CG
7
Directed light
§ Scene with ambient light and parallel light source
Marc Alexa, TU Berlin
CG
8
Point light
§ Scene with ambient light and point light source
Marc Alexa, TU Berlin
CG
9
Types of reflection
§ Specular (mirror-like) = reflection without
diffusion in different directions
§ Diffuse reflection equally distributed light
energy in all directions
§ Mixed diffuse and specular reflection is a
combination of the two
Marc Alexa, TU Berlin
CG
10
Reflection distribution
§ Most surfaces have complex reflection behavior
• Varying with incident and reflection angle of light
• Modelled as combination of three basic types
+ + =
specular + glossy + diffuse = distribution
Marc Alexa, TU Berlin
CG
11
Representing light intensity
§ Light power is called flux and measured in Watts (W)
§ Flux per solid angle = intensity (W/sr)
§ Flux per area
• Light received by surface = irradiance (W/m2)
• Light leaving a surface = radiosity (W/m2)
§ Photometry = units related to human vision by integrating over the
human spectral sensitivity
• Luminous flux (power) measured in Lumen (lm)
• Luminous flux per solid angle: luminous intensity, measured in Candela (cd = lm/sr)
• Luminous flux per area: illuminance, measured in Lux (lx = lm/m2)
Marc Alexa, TU Berlin
CG
12
Light rays in computer graphics
§ In CG we model light travelling along rays
§ Intensity of light is constant along ray
§ Appropriate physical unit: Flux per solid angle per area
• Radiometry: Radiance (W/sr m2)
• Photometry: Luminance (lm/sr m2 = cd/m2 = lx/sr)
Marc Alexa, TU Berlin
CG
13
Bidrectional reflectance distribution
function (BRDF)
§ Description of reflection behavior
§ Proportion of reflected radiance L to irradiance E
§ Incoming light: index i
§ Reflected light: Index r
( ) ( )( )
( )
( ) ( )ò W
==
iiiii
rrr
iii
rrr
iirr dL
L
E
L
qqfl
qfl
qfl
qfl
qfqflr
l
l
l
l
cos,,
,,
,,
,,
,,,,
,
,
,
,
Marc Alexa, TU Berlin
CG
14
BRDF
Properties
1. Reciprocity
• ρλ remains unchanged, if incidence and reflection angle are swapped
2. ρλ is generally anisotropic
• Rotating the surface around the surface normal changes the reflection
• Prominent example would be cloth.
3. Superposition
• Light from multiple directions behaves linearly
• Integration over all incident directions yields
( )ò
W
W=
i
iiir dLL qr ll cos,,
Marc Alexa, TU Berlin
CG
15
BRDF
Simplification in CG
§ Reflection is always positive
§ In Computer Graphics we mostly use another quantity
§ Proportion of reflected and incoming irradiance
• This quantity is dimensionless and between 0 and 1
• We apply it to radiance (which is physically implausible)
r
E
E
rr
r
l
l
l
l= £ £
,
,
, 0 1
Marc Alexa, TU Berlin
CG
16
BRDF
Surfaces
§ On a microscopic scale all surface are
rough
§ Shadowing
§ “Masking” of reflected light
Shadow Shadow
Masked light
Marc Alexa, TU Berlin
CG
17
Ideal diffuse reflection
§ Simplest case: reflected radiance is independent of reflection
direction
• Lambert reflection
§ Incident light (irradiance) depends on angle θ of light source
to normal vector of surface
§ This angle expresses the illuminated surface in direction of
the light source
• Falls off as the cosine of the angle
• Lambert’s cosine law
dI LdA= 1 1cosq
Marc Alexa, TU Berlin
CG
18
Lambert’s cosine law
Marc Alexa, TU Berlin
CG
19
Ideal Diffuse Reflection
Computation
§ Angle between light source and surface normal is incidence
angle:
Idiffuse = kd Ilight cos θ
§ using vectors
Idiffuse = kd Ilight (n • l)
nl
θ
kd : diffuse component
”color of surface”
Marc Alexa, TU Berlin
CG
20
Ideal specular reflection
§ Ideal specular reflection is described by the following rules:
• Incident and reflected ray subtend the same angle with the surface
normal
• Incident and reflected ray, and the surface normal are in a common
plane
• In polar coordinates:
q qr i= and f f pr i= +
Marc Alexa, TU Berlin
CG
21
Ideal specular reflection
Geometry of mirror reflection
qi qr
L
P
P
R
S
L
N
θ
S
P = N ( N · L )
2 P = R + L
2 P – L = R
2 (N ( N · L )) - L = R
Marc Alexa, TU Berlin
CG
22
Ideal specular reflection
Geometry of mirror reflection Geometry of refraction
qi qr
q1
q2
Medium 1
Medium 2
Marc Alexa, TU Berlin
CG
23
Refraction
§ Incident ray, surface normal, and refracted ray are in one
plane
§ Sine of incident angle is proportional to sine of refraction
angle
§ The proportion depends on the two media
§ n1 resp. n2 are the indices of refraction
• The index of refraction is defined as the speed of light in the medium
relative to the speed of light in vacuum.
n n n
n
const1 1 2 2 1
2
2
1
sin sin sin
sin
.q q q
q
= Û = =
Marc Alexa, TU Berlin
CG
24
Refraction
Total internal reflection
§ Light travels to medium with lower index of refraction n2 < n1
• Angle to normal increases
• There is an incidence angle θT so that refraction angle is 90º
• Law of refraction gives:
§ For angles larger than θT
• Light cannot propagate into other
medium
• All light is reflected at the interface
• Total internal reflection
sin .q T
n
n
= 2
1
qT
Medium 1
Medium 2
Marc Alexa, TU Berlin
CG
25
Specular-diffuse reflection
§ Ideal reflectors (Lambert or specular) are rare
§ One really should determine ρλ(λ,ϕr,θr,ϕi,θi)
§ But we observe in many cases
• A maximum in the direction of the specular reflection
• Fall-off towards increasing angles from this direction
§ In CG we often treat this part, which is dependent on the
viewer, independent of the purely diffuse reflection
Marc Alexa, TU Berlin
CG
26
Specular-diffuse reflection
Specular (mirror-like)
Mixed
Diffuse
Marc Alexa, TU Berlin
CG
27
Phong model
§ The view-dependent part is modelled as
§ rs,0 is a constant between 0 and 1
§ g is the angle between viewing direction and the ideally
reflected illumination
§ The exponent (shininess) models how quickly the reflection
decreases with larger angles
r rs s
m= , cos0 g
g
!
L
!
N
!
R
!
E
Marc Alexa, TU Berlin
CG
28
Phong model
§ diffusely reflected radiance
§ diffuse reflection
§ radiance of incident light
§ angle between viewer and ideally reflected illumination
§ shininess
Lspec
rs
L
g
m
g
!
L
!
N
!
R
!
E( ) ( )
ïî
ï
í
ì >××××=
sonst
ERfallsERLr
m
s
0
0,
!!!!
( )
ïî
ï
í
ì <××=
sonst
fallsLrL
m
s
spec
0
2
,cos pgg
Marc Alexa, TU Berlin
CG
29
Phong model: exponent m (shininess)
§ Phong reflection decreases with increasing angle between
viewer and ideally reflected illumination
§ What the visual impact?
Marc Alexa, TU Berlin
CG
30
Phong examples
Variation of light direction L
Variation of m
Marc Alexa, TU Berlin
CG
31
Blinn-Phong-model
§ Blinn suggest to use the bisector to avoid computing the
reflected ray
§ Exponent n is quantitatively
but not qualitatively different
from m
€
Lspec =
rs ⋅L ⋅
H ⋅
N ( )n, falls
H ⋅
N ( ) > 0
0 sonst
#
$
%
& %
!
! !
! !H E L
E L
=
+
+
Viewer E
b
b
g
g
2
!
L
!
N !H
!
R
!
E
Light source L
bisector
Normal vector
Reflected ray
Marc Alexa, TU Berlin
CG
32
Local shading models
§ Different parts
• Ambient
– Light source position, surface normals, viewer are all irrelevant
• Lambert / ideal diffuse
– Only angle between light source and surface normal
• Phong / specular
– Surface normal, direction to light source, and viewing parameters all influence
the result
Marc Alexa, TU Berlin
CG
33
Interpolation on primitives
§ Luminance across primitives is computed during rasterization based on
vertex values
§ We may distinguish:
§ Flat Shading
• Luminance is based on normal of primitive and constant for the primitive
§ Gouraud Shading
• Surface normals in the vertices of the primitive result in vertex luminances
• Vertex luminance is interpolated linearly across primitive
§ Phong Shading
• Surface normals in vertices are (linearly) interpolated across primitive
• Luminance is computed in each point based on interpolated surface normal
Marc Alexa, TU Berlin
CG
34
Interpolation on primitives
Differences
Marc Alexa, TU Berlin
CG
35
Gouraud Shading – Quality
§ Quality of Gouraud-Shading depends on size of primitives
§ Fundmantel problem:
Extreme values of luminance
(brightest and darkest point)
are always in the vertices
Marc Alexa, TU Berlin
CG
36
Phong Shading
§ Linear interpolation of normals (and not luminance)
§ Shading model is evaluated at every point
• Slower
• But extrema inside primitives are possible
P0 Pa Pb Pc P1
N0 Na Nb Nc N1
学霸联盟