Upload
others
View
18
Download
0
Embed Size (px)
Citation preview
Einführung in Visual Computing186.822
Lighting and Shading
Werner Purgathofer
Shading in the Rendering Pipeline
2raster image in pixel coordinates
clipping + homogenization
object capture/creation
modelingviewing
projection
rasterizationviewport transformation
shading
vertex stage(„vertex shader“)
pixel stage(„fragment shader“)
scene in normalized device coordinates
transformed vertices in clip space
scene objects in object space
Werner Purgathofer 3
light sourcesbasic model
ambient lightdiffuse shadingspecular highlights
shading interpolationGouraud ShadingPhong Shading
Illumination
Werner Purgathofer 4
directional lightpoint light source (sometimes directional)distributed light source (“area light source”)
Light Sources
Werner Purgathofer 5
Surface Lighting Effects
diffuse reflection
specular reflection
transparency
reflections fromother surfaces
Werner Purgathofer 6
Basic Illumination Models
empirical modelslighting calculations
surface properties (glossy, matte, opaque,…)background lighting conditionslight-source specificationreflection, absorption
ambient light (background light) Iaapproximation of global diffuse lighting effects
Werner Purgathofer 7
Ambient Light Reflectionconstant over a surfaceindependent of viewing directiondiffuse-reflection coefficient kd (0≤ kd ≤1)
adambdiff IkL =
Werner Purgathofer 8
shaded surfaces generate a spatial impression
the flatter light falls on a surface,the darker it will appear
therefore:we need the incident light direction
or the position of the (point) light source
Illumination and Shading
Werner Purgathofer 9
Lambert's Law
L = I ⋅ cos θwhen consideringthe material:
L = kd ⋅ I ⋅ cos θ
kd … diffuse coefficient
I … light source intensityL … pixel color
θθ
Werner Purgathofer 10
ideal diffuse reflectors (Lambertian reflectors)brightness depends on orientation of surface
Lambert’s cosine law
Lambertian (Diffuse) Reflection
Ldiff = kd ⋅ I ⋅ (n⋅l)l
n
θ cos θ= n∙l
Werner Purgathofer 11
varying kd
Diffuse Reflection Coefficient
result for varying values of kd ( Ia = 0 )
kd=0 kd=0.3 kd=0.7 kd=1
12
total diffuse reflection
(sometimes kafor ambient light)
Ambient plus Diffuse Reflection
Ldiff = kaIa + kdI(n⋅l)
ka=1
ka=0.6
ka=0.2
ka=0
kd=0 kd=0.3 kd=0.7 kd=1
Werner Purgathofer 13
total diffuse reflection
Ambient plus Diffuse Reflection
Ldiff = kaIa + kdI(n⋅l)(ambient only)
Werner Purgathofer 14
Specular Highlights
this area must be lighter than the shading model calculates, because the light source is reflected directly into the viewer's eye
Werner Purgathofer 15
reflection of incident light around specular-reflection angle
empirical Phong model
Specular Reflection Model
Lspec = ks ⋅ I ⋅ cospσ
θl
n
θr
σ v
(1)
Werner Purgathofer 16
Specular Reflection Coefficient p
0° 30° 60° 90°
1
0.5
0
σpcosσcos
(1)8
Werner Purgathofer 17
Specular Reflection Coefficient p
0° 30° 60° 90°
1
0.5
0
σpcosσcos
(1)864128256
Werner Purgathofer 18
Specular Reflection Coefficient p
0° 30° 60° 90°
1
0.5
0
σpcosσcos
Werner Purgathofer 19
Specular Reflection Coefficient p
σcos
σ64cos
σ256cos
σpcosp=1
p=2
p=4
p=16
p=64
Werner Purgathofer 20
Specular Reflection Coefficient
empirical Phong modelp large ⇒ shiny surfacep small ⇒ dull surface
Lspec = ks ⋅ I ⋅ cospσ
shiny surface (large p) dull surface (small p)
θl n
θr
θl n
θr
Werner Purgathofer / Computergraphik 1 21
Fresnel Specular Reflection Coefficient
Fresnel’s laws of reflectionspecular reflection coefficient W(θ)
σθ plspec IWL cos)(=
specular reflection coefficient as a function of angle of incidence for different materials
silver
gold
dielectric (glass)
W(θ)
θ
Werner Purgathofer 22
calculation of R:
Simple Specular Reflection
W(θ) ≈ constant for many opaque materials (ks)
r + l = (2n∙l)nr = (2n∙l)n – l
Lspec = ks∙I∙(v∙r)p
θl n
θr
σ v l
nr
n∙l
l
Werner Purgathofer 23
Specular Reflection Results
Lspec = ks∙I∙(v∙r)p
ks=1
ks=0.7
ks=0.3
ks=0
p=5 p=10 p=40 p=99
Werner Purgathofer 24
Simplified Specular Reflection
simplified Phong model with halfway vector h→
vlh+=
|| l + v ||
Lspec = ks∙I∙(v∙r)p Lspec = ks∙I∙(n∙h)p
this revised model is called“Blinn-Phong Shading”
ln
rσ v
αh
Werner Purgathofer 25
Diffuse and Specular Reflection
[ ]∑ ⋅+⋅+=N
i=1
pisidiaa hnklnkIIkL )()(
ambient ambient + diffuseambient + diffuse
+ specular
© Tong Lai Yu© James Tasker
Werner Purgathofer 26
Diffuse and Specular Reflection
[ ]∑ ⋅+⋅+=N
i=1
pisidiaa hnklnkIIkL )()(
ambient ambient + diffuseambient + diffuse
+ specular
Werner Purgathofer 27
Other Aspects
intensity attenuation with distanceanisotropic light sourcestransparency (Snell’s law)atmospheric effectsshadows…
Werner Purgathofer 28
application of illumination model to polygon renderingconstant-intensity shading (flat shading)
single intensity for each polygonflat Gouraud
Polygon-Rendering Methods
Werner Purgathofer 29
the shading of a polygon is not constant, because it normally is only an approximation of the real surface ⇒ interpolation
Gouraud shading: intensitiesPhong shading: normal vectors
Polygon Shading: Interpolation
Werner Purgathofer 30
intensity-interpolationdetermine average unit normal vector at each polygon vertexapply illumination model to each vertexlinearly interpolate vertex intensities
Gouraud Shading Overview
∑
∑
=
== N
kk
N
kk
V
n
nn
1
1
V
nV
n4
n3
n2n1
Werner Purgathofer 31
Gouraud Shading
L1 L3
L2
1. find normal vectors at corners and calculate shading (intensities) there: Li
Werner Purgathofer 32
1. find normal vectors at corners and calculate shading (intensities) there: Li
2. interpolate intensities along edges linearly: L, L’
Gouraud Shading
L1 L3
L2
L = t·L1 + (1–t)·L2 L’ = u·L2 + (1–u)·L3
Werner Purgathofer 33
1. find normal vectors at corners and calculate shading (intensities) there: Li
2. interpolate intensities along edges linearly: L, L’3. interpolate intensities along scanlines linearly: Lp
Gouraud Shading
L1 L3
L2
L = t·L1 + (1–t)·L2 L’ = u·L2 + (1–u)·L3
v·L + (1–v)·L’
Werner Purgathofer 34
Gouraud Shading
interpolating intensities
221
411
21
244 Lyy
yyLyy
yyL −
−+−
−= 5
45
44
45
5 LxxxxLxx
xxL ppp −
−+−
−=
scan line1
2
3
54 p21
41
yyyy
−−
21
24
yyyy
−−
Werner Purgathofer 35
Gouraud Shading
incremental update
221
11
21
2 Lyyyy
Lyyyy
L −−
+−−
=21
12
yyLL
LL −−
+=′
scan linesL1 L
L2
L´y
y−1
highlights can get lost or grow
corners on silhouette remain
Mach band effect is visible at some edges
darklight
dark
Werner Purgathofer 36
Problems of Gouraud Shading
darkdark
dark
Werner Purgathofer 37
Problems of Gouraud Shading
© Akiyoshi Kitaoka
Werner Purgathofer 38
Gouraud Shading Results
no intensity discontinuitiesMach bands due to linear intensity interpolationproblems with highlights
flat Gouraud
© Camillo Trevisan
Werner Purgathofer 39
Phong Shading
instead of intensities the normal vectors are interpolated, and for every point the shading calculation is performed separately
darklight
dark
darklight
dark
Werner Purgathofer 40
Phong Shading Principle
normal-vector interpolationdetermine average unit normal vector at each polygon vertexlinearly interpolate vertex normalsapply illumination model along each scan line
P
Werner Purgathofer 41
Phong Shading Overview
1. normal vectors at corner points2. interpolate normal vectors along the edges3. interpolate normal vectors along scanlines
& calculate shading (intensities) for every pixel
Werner Purgathofer 42
Phong Shading Normal Vectors
normal-vector interpolation
221
1 nyyyy
−−
+
121
2 nyyyy
n −−= +
scan line
n1
n
n2
y21
1
yyyy
−−
21
2
yyyy
−−
Werner Purgathofer 43
Phong Shading
incremental normal vector update along and between scan linescomparison to Gouraud shading
better highlightsless Mach bandingmore costly
© Camillo Trevisan
Werner Purgathofer / Computergraphik 1 44
Flat/Gouraud/Phong Comparison
© Paul Heckbert© Paul Heckbert