52
1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok [email protected]

1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok [email protected]

  • View
    234

  • Download
    1

Embed Size (px)

Citation preview

Page 1: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

1

7M836 Animation & Rendering

Illumination models, light sources, reflection shading

Arjan Kok

[email protected]

Page 2: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

2

Graphics pipeline

Geometric model Viewing

Camera parameters

Light sources,materials

Shading

Visible surface determination

Rasterize

Raster display

Page 3: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

3

Illumination

• Illumination model• Illumination (and therefore color) of point on surface is

determined by simulation of light in scene• Illumination model is approximation of real light

transport

• Shading method• determines for which points illumination is computed• determines how illumination for other points is

computed

Page 4: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

4

Illumination models

• Model(s) needed for

• Emission of light

• Distribution of light in scene

• Desired model requirement

• Accurate

• Efficient to compute

Page 5: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

5

Illumination models

• Local illumination

• Direct illumination

• Emission of light sources

• Scattering at surfaces

• Global illumination

• Shadows

• Refraction

• Interreflection

• (Ray tracing + Radiosity)

Page 6: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

6

Light source

• IL (x, y, z, θ, φ, λ)

• Intensity of energy

• of light source L

• arriving at point (x, y, z)

• from direction (θ, φ)

• with wavelength λ

• Complex

• Simpler model needed

(x,y,z)

Page 7: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

7

Point light source

• Emits light equally in all directions

• Parameters

• Intensity I0

• Position P (px,py,pz)

• Attenuation factor(kc, kl, kq) for distance (d) to light source

• 2

qlc

0L dkdkk

II

d

P

0L II

Page 8: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

8

Point light source

Page 9: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

9

Direction light source

• Emits light in one direction

• Can be regarded as point light source at infinity

• E.g. sun

• Parameters

• Intenslity I0

• Direction D (dx,dy,dz)

• IL = I0

D

Page 10: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

10

Directional light source

Page 11: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

11

Spot light source

• Point light source with direction

• E.g. Spot light

• Parameters

• Intensity I0

• Position P (px,py,pz)

• Direction D (dx,dy,dz)

• “Hotspot” angle θ

• Maximum angle φ

• Exponent e

d

PD

γθ

φ

Page 12: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

12

Spot light source

• if γ ≤ θ

• if θ < γ ≤ φ

• if φ < γ

• Attenuation factor

)2

(cosII e

0L

0IL θ φ

0L II

2

qlc dkdkk1

Page 13: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

13

Spot light source

Page 14: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

14

Spot light source

Page 15: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

15

Other light sources

• Linear light sources

• Area sources

• Spherical lights

• …

Page 16: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

16

Reflection

• Rs (θ, φ, γ, ψ, λ)

• Amount of energy,

• arriving from direction (θ, φ),

• that is reflected in direction (γ, ψ)

• with wavelength λ

• Ideal

• Describe this function for all combinations of θ, φ, γ, ψ and λ

• Impossible, simpler model(s) needed

(θ, φ)(γ, ψ)

λ

Page 17: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

17

Reflection model

• Total intensity on point reflected in certain direction is determined by:

• Diffusely reflected light

• Specularly reflected light

• Emission (for light sources)

• Reflection of ambient light

• Intensity not computed for all wavelengths λ, only for R, G and B

Page 18: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

18

Diffuse reflection

• Incoming light is reflected equally in all directions

• Amount of reflected light depends only on angle of incident light

viewer

surface

Page 19: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

19

Diffuse reflection

• Lambert’ law: Reflected energy from a surface is proportional to the cosine of the angle of direction of incoming light and normal of surface

• Id = kdILcos(θ)

• kd is diffuse reflection coefficient

viewer

surface

Page 20: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

20

Specular reflection

• Models reflections of shiny surfaces

Page 21: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

21

Specular reflection

• Shininess depends on roughness surface

• Incident light is reflected unequally in all directions

• Reflection strongest near mirror angle

very shiny less shiny

Page 22: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

22

Specular reflection / Phong

• Light intensity observed by viewer depends on angle of incident light and angle to viewer

• Phong model: Is = ksILcosn(α)

• ks is specular reflection coefficient

• n is specular reflection exponent

α

Page 23: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

23

Specular reflection / Phongin

crea

sing

n

increasing ks

Page 24: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

24

Emission

• Emission IE represents light that is emanated directly by surface

• Used for light sources

Emission ≠ 0

Page 25: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

25

Ambient light

• Even thought parts of scene are not directly lit by light sources, they can still be visible

• Because of indirect illumination• “Ambient” light IA is an approach to this indirect

illumination• Ambient light is independent of light sources and viewer

position• Conbtribution of ambient light I = kAIA

• kA is ambient reflection coefficient• IA is ambient intensitity (constant over scene)

• Indirect illumination can be computed much better: e.g. radiosity

Page 26: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

26

Total illumination Phong model

• Total intensity Itotal at point P seen by viewer is

i

i

n

SiDiAAEtotal )(cosk)cos(kIIkII

α0

θ0

θ1

α1

Page 27: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

27

Total illumination Phong model

• In previous formula kA, kD dependent on wavelength (different values for R, G and B)

• Often division into color and reflection coefficient of surface

where:• 0 ≤ kA, kD, kS ≤ 1• CA is ambient reflected color of surface• CD is diffuse reflected color of surface• Cs is specular reflected color of surface

i

i

n

ssiDDiAAAEtotaal cosCkcosCkIICkII

Page 28: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

28

Only emission and ambient

Page 29: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

29

Including diffuse reflection

Page 30: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

30

Including specular reflection

Page 31: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

31

Illumination model

• More advanced models:

• Allows for angle between incident light and surface normal for specular reflection (Fresnel’s law)

• Better models for surface roughness

• Beter model for wavelength dependent reflection

Page 32: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

32

Shading

• Illumination model computes illumination for a point on surface

• But how do we compute the illumination for all points on all (visible) surfaces?

• Shading methods:

• Flat shading

• Gouraud shading

• Phong shading

Page 33: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

33

Flat shading

• Determine illumination for one point on polygon

• Use this illumination for all points on polygon

• Disadvantages:

• Does not account for changing direction to light source over polygon

• Does not account for changing direction to eye over polygon

• Discontinuity at polygon boundaries (when curved surface approximated by polygon mesh

Page 34: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

34

Flat shading

Page 35: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

35

Gouraud shading

• Based on interpolation of illumination values

• Compute illumination for vertices of polygon

• Algorithm

• for all vertices of polygon

• get vertex normal

• compute vertex illumination using this normal

• for all pixels in projection of polygon

• compute pixel illumination by interpolation of vertex illumination

Page 36: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

36

Gouraud shading

I1

I2

I3

ys

IA IB

21A II1I

21B II1I

21

s1

yyyy

31

s1

yyyy

IP

BAP II)1(I

BA

PA

xxxx

Page 37: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

37

Gouraud shading

Page 38: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

38

Gouraud shading

• Advantages

• Interpolation is simple, hardware implementation

• Continuous shading over curved surfaces possible

• Disadvantages

• Subtle illumination effects (e.g. highlights) require high subdivision of surface in very small polygons

Page 39: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

39

Phong shading

• Based on normal interpolation

• Compute illumination for each point of polygon

• Algorithm

• for each vertex of polygon

• get vertex normal

• for each pixel in projection of polygon

• compute point normal by interpolation of vertex normals

• compute illumination using interpolated normal

Page 40: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

40

Phong shading

Page 41: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

41

Phong shading

• Advantages

• Nice highlights

• Disadvantages

• Computational expensive

• Normal interpolation and application of illumination model for each pixel

Page 42: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

42

Shading samengevat

Page 43: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

43

Shading

• Flat shading

• 1x application of illumination model per polygon

• 1 color per polygon

• Gouraud shading

• 1x application of illumination model per vertex

• Interpolated colors

• Phong shading

• 1x application of illumination model per pixel

• Nice highlightsIncrease computation time

Increase quality

Page 44: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

44

Grafische pijplijn

Geometric model Viewing

Camera parameters

Light sources,materials

Shading

Visible surface determination

Rasterize

Raster display

Page 45: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

45

Z-buffer & Gouraud shading

modelingtransformation

viewingtransformation

trivialaccept/reject

z-bufferprojection

lighting

clipping display

Page 46: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

46

Z-buffer & Phong shading

modelingtransformation

viewingtransformation

trivialaccept/reject

z-bufferlighting

projectionclipping display

Page 47: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

47

What is still missing?

• Shadows

• Area light sources

• “Real” mirroring

• Transparency

• Indirect diffuse reflection

• Influence of atmosphere

Page 48: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

48

Shadow

• Illumination with shadows

• Si = 0 if light of source i is blocked= 1 if light of source i is not blocked

• Several methods to compute shadow

• Shadow buffer

• Ray casting

• Shadow volumes

• ..

i

i

n

ssiDDiiAAAEtotaal cosCkcosCkSIICkII

Page 49: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

49

Shadow buffer

• Based on z-buffer algorithm

• Rendering in 2 steps

• Z-buffer from light source (= shadow buffer) to compute shadows

• During “normal” rendering, when computing illumination of point read from shadow buffer if point is lit by light source

Page 50: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

50

Shadow buffer – step 1

• “Render” scene with light source position as viewpoint and store depth results in depth buffer

• sbuffer(x,y) = minimum z-value after projection of all polygons on (x,y)

3 3 5 _5_

z

3

0

5

Page 51: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

51

Shadow buffer – step 2

• At rendering, when computing illumination of point (x,y,z), transform point into light source coordinate system, resulting in point (x’,y’,z’)

• Si = 1 als z’ <= sbuffer(x’,y’)= 0 als z’ > sbuffer(x’,y’)

3 3 5 _5_

S=0

S=1 S=1

S=1

Page 52: 1 7M836 Animation & Rendering Illumination models, light sources, reflection shading Arjan Kok a.j.f.kok@tue.nl

52

What is still missing?

• Area light sources

• “Real” mirroring

• Transparency

• Indirect diffuse reflection

• Influence of atmosphere