44
Einführung in Visual Computing 186.822 Lighting and Shading Werner Purgathofer

Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

  • Upload
    others

  • View
    18

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Einführung in Visual Computing186.822

Lighting and Shading

Werner Purgathofer

Page 2: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 3: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 3

light sourcesbasic model

ambient lightdiffuse shadingspecular highlights

shading interpolationGouraud ShadingPhong Shading

Illumination

Page 4: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 4

directional lightpoint light source (sometimes directional)distributed light source (“area light source”)

Light Sources

Page 5: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 5

Surface Lighting Effects

diffuse reflection

specular reflection

transparency

reflections fromother surfaces

Page 6: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 7: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 7

Ambient Light Reflectionconstant over a surfaceindependent of viewing directiondiffuse-reflection coefficient kd (0≤ kd ≤1)

adambdiff IkL =

Page 8: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 9: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

θθ

Page 10: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 11: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 12: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 13: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 13

total diffuse reflection

Ambient plus Diffuse Reflection

Ldiff = kaIa + kdI(n⋅l)(ambient only)

Page 14: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 15: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 16: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

(1)

Werner Purgathofer 16

Specular Reflection Coefficient p

0° 30° 60° 90°

1

0.5

0

σpcosσcos

Page 17: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

(1)8

Werner Purgathofer 17

Specular Reflection Coefficient p

0° 30° 60° 90°

1

0.5

0

σpcosσcos

Page 18: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

(1)864128256

Werner Purgathofer 18

Specular Reflection Coefficient p

0° 30° 60° 90°

1

0.5

0

σpcosσcos

Page 19: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 19

Specular Reflection Coefficient p

σcos

σ64cos

σ256cos

σpcosp=1

p=2

p=4

p=16

p=64

Page 20: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 21: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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(θ)

θ

Page 22: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 23: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 24: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 25: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 25

Diffuse and Specular Reflection

[ ]∑ ⋅+⋅+=N

i=1

pisidiaa hnklnkIIkL )()(

ambient ambient + diffuseambient + diffuse

+ specular

© Tong Lai Yu© James Tasker

Page 26: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 26

Diffuse and Specular Reflection

[ ]∑ ⋅+⋅+=N

i=1

pisidiaa hnklnkIIkL )()(

ambient ambient + diffuseambient + diffuse

+ specular

Page 27: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 27

Other Aspects

intensity attenuation with distanceanisotropic light sourcestransparency (Snell’s law)atmospheric effectsshadows…

Page 28: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 28

application of illumination model to polygon renderingconstant-intensity shading (flat shading)

single intensity for each polygonflat Gouraud

Polygon-Rendering Methods

Page 29: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 30: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 31: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 31

Gouraud Shading

L1 L3

L2

1. find normal vectors at corners and calculate shading (intensities) there: Li

Page 32: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 33: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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’

Page 34: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

−−

Page 35: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 36: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 37: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 37

Problems of Gouraud Shading

© Akiyoshi Kitaoka

Page 38: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 38

Gouraud Shading Results

no intensity discontinuitiesMach bands due to linear intensity interpolationproblems with highlights

flat Gouraud

© Camillo Trevisan

Page 39: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 40: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 41: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

Page 42: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

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

−−

Page 43: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer 43

Phong Shading

incremental normal vector update along and between scan linescomparison to Gouraud shading

better highlightsless Mach bandingmore costly

© Camillo Trevisan

Page 44: Lighting and Shading - TU Wien€¦ · Lighting and Shading Werner Purgathofer. Shading in the Rendering Pipeline raster image in pixel coordinates 2 clipping + homogenization. object

Werner Purgathofer / Computergraphik 1 44

Flat/Gouraud/Phong Comparison

© Paul Heckbert© Paul Heckbert