5.1 Lighting and Shading Hao Li http://cs420.hao-li.com 1 - - PowerPoint PPT Presentation

5 1 lighting and shading
SMART_READER_LITE
LIVE PREVIEW

5.1 Lighting and Shading Hao Li http://cs420.hao-li.com 1 - - PowerPoint PPT Presentation

Fall 2015 CSCI 420: Computer Graphics 5.1 Lighting and Shading Hao Li http://cs420.hao-li.com 1 Debunking Lunar Landing Conspiracies with Global Illumination https://www.youtube.com/watch?v=O9y_AVYMEUs 2 Single Light Source for Global


slide-1
SLIDE 1

CSCI 420: Computer Graphics

Hao Li

http://cs420.hao-li.com

Fall 2015

5.1 Lighting and Shading

1

slide-2
SLIDE 2

Debunking Lunar Landing Conspiracies with Global Illumination

https://www.youtube.com/watch?v=O9y_AVYMEUs

2

slide-3
SLIDE 3

Single Light Source for Global Illumination

https://www.youtube.com/watch?v=O9y_AVYMEUs

3

slide-4
SLIDE 4

Lighting

4

slide-5
SLIDE 5

Outline

  • Global and Local Illumination
  • Normal Vectors
  • Light Sources
  • Phong Illumination Model

5

slide-6
SLIDE 6

Global Illumination

  • Ray tracing
  • Radiosity
  • Photon Mapping
  • Follow light rays through a scene
  • Accurate, but expensive (off-line)

6

Tobias R. Metoc

slide-7
SLIDE 7

Raytracing Example

7

Martin Moeck, Siemens Lighting

slide-8
SLIDE 8

Radiosity Example

8

Restaurant Interior. Guillermo Leal, Evolucion Visual

slide-9
SLIDE 9

Local Illumination

  • Approximate model
  • Local interaction between 


light, surface, viewer

  • Phong model (this lecture): 


fast, supported in OpenGL

  • GPU shaders
  • Pixar Renderman (offline)

9

camera

n

light source

slide-10
SLIDE 10

Local Illumination

  • Approximate model
  • Local interaction between 


light, surface, viewer

  • Color determined only based on

surface normal, relative camera position and relative light position

  • What effects does this ignore?

10

camera

n

light source

v l

slide-11
SLIDE 11

Outline

  • Global and Local Illumination
  • Normal Vectors
  • Light Sources
  • Phong Illumination Model

11

slide-12
SLIDE 12

Normal Vectors

  • Must calculate and specify the normal vector
  • Even in OpenGL!
  • Two examples: plane and sphere

12

slide-13
SLIDE 13

Normals of a Plane, Method I

13

  • Method I: given by
  • Let be a known point on the plane
  • Let be an arbitrary point on the plane
  • Recall: if and only if orthogonal to
  • .
  • Consequently
  • Normalize to

ax + by + cz + d = 0 p0 p u · v = 0 v n · (p − p0) = n · p − n · p0 = 0 n0 = [ a b c ]T n = n0 |n0| u

slide-14
SLIDE 14

Normals of a Plane, Method II

14

  • Method II: plane given by
  • Points must not be collinear
  • Recall: orthogonal to and
  • .
  • Order of cross product determines orientation
  • Normalize to n = n0

|n0| p0, p1, p2 u × v u v n0 = (p1 − p0) × (p2 − p0)

slide-15
SLIDE 15

Normals of Sphere

15

  • Implicit Equation
  • Vector form:
  • Normal given by gradient vector
  • Normalize

f(x, y, z) = x2 + y2 + z2 − 1 = 0 f(p) = p · p − 1 = 0 n0 |n0| = 2p 2 = p

slide-16
SLIDE 16

Reflected Vector

16

l · n = cos(θ) = n · r r = αl + βn Solution : α = −1 and β = 2(l · n) r = 2(l · n)n − l

  • Perfect reflection: angle of incident equals angle of reflection
  • Also: , , and lie in the same plane
  • Assume , guarantee

l n r |l| = |n| = 1 |r| = 1

slide-17
SLIDE 17

Outline

  • Global and Local Illumination
  • Normal Vectors
  • Light Sources
  • Phong Illumination Model

17

slide-18
SLIDE 18

Light Sources and Material Properties

  • Appearance depends on
  • Light sources, their locations and properties
  • Material (surface) properties:
  • Viewer position

18

slide-19
SLIDE 19

Types of Light Sources

  • Ambient light: no identifiable source or direction
  • Point source: given only by point
  • Distant light: given only by direction
  • Spotlight: from source in direction
  • Cut-off angle defines a cone of light
  • Attenuation function (brighter in center)

19

slide-20
SLIDE 20

Point Source

20

  • Given by a point
  • Light emitted equally in all directions
  • Intensity decreases with square of distance

p0

slide-21
SLIDE 21

Limitations of Point Sources

21

  • Shading and shadows inaccurate
  • Example: penumbra (partial “soft” shadow)
  • Similar problems with highlights
  • Compensate with attenuation
  • Softens lighting
  • Better with ray tracing
  • Better with radiosity

1 a + bq + cq2 q = distance|p − p0| a, b, c constants

slide-22
SLIDE 22

Distant Light Source

22

  • Given by a direction vector
  • Simplifies some calculations
  • In OpenGL:
  • Point source
  • Distant source

⇥ x y z 1 ⇤T ⇥ x y z 0 ⇤T

slide-23
SLIDE 23

Spotlight

  • Most complex light source in OpenGL
  • Light still emanates from point
  • Cut-off by cone determined by angle θ

23

slide-24
SLIDE 24

Global Ambient Light

  • Independent of light source
  • Lights entire scene
  • Computationally inexpensive
  • Simply add to every pixel on


every object

  • Not very interesting on its own


A cheap hack to make the scene brighter

24

[ GR GG GB ]

slide-25
SLIDE 25

Outline

  • Global and Local Illumination
  • Normal Vectors
  • Light Sources
  • Phong Illumination Model

25

slide-26
SLIDE 26

Phong Lighting

26

slide-27
SLIDE 27

Phong Illumination Overview

  • Calculate color for arbitrary point on surface
  • Compromise between realism and efficiency
  • Local computation (no visibility calculations)
  • Basic inputs are material properties and :

27

l, n, v

= unit vector to light source = surface normal = unit vector to viewer = reflection of at (determined by and )

l n v r l p l n

slide-28
SLIDE 28

Phong Illumination Overview

28

  • 1. Start with global ambient light
  • 2. Add contributions from each light source
  • 3. Clamp the final result to [0, 1]
  • Calculate each color channel (R,G,B) separately
  • Light source contributions decomposed into
  • Ambient reflection
  • Diffuse reflection
  • Specular reflection
  • Based on ambient, diffuse, and specular

lighting and material properties [ GR GG GB ]

slide-29
SLIDE 29

Ambient Reflection

  • Intensity of ambient light is uniform at every point
  • Ambient reflection coefficient ka (material), 0 ≤ ka ≤ 1
  • May be different for every surface and r,g,b
  • Determines reflected fraction of ambient light
  • La = ambient component of light source


(can be set to different value for each light source)

  • Note: La is not a physically meaningful quantity

29

Ia = kaLa

slide-30
SLIDE 30

Diffuse Reflection

  • Diffuse reflector scatters light
  • Assume equally all direction
  • Called Lambertian surface
  • Diffuse reflection coefficient kd (material), 0 ≤ kd ≤ 1
  • Angle of incoming light is important

30

slide-31
SLIDE 31

Lambert’s Law

  • Intensity depends on angle of incoming light.

31

slide-32
SLIDE 32

Diffuse Light Intensity Depends On Angle Of Incoming Light

32

n l θ

= distance to light source, = diffuse component of light

q Ld

  • Recall

= unit vector to light = unit surface normal = angle to normal

  • .
  • .
  • With attenuation:

l n θ cos(θ) = l · n Id = kdLd(l · n)

slide-33
SLIDE 33

Specular Reflection

  • Specular reflection coefficient ks (material), 0 ≤ ks ≤ 1
  • Shiny surfaces have high specular coefficient
  • Used to model specular highlights
  • Does not give mirror effect 


(need other techniques)

33

specular reflection specular highlights

slide-34
SLIDE 34

Specular Reflection

34

  • Recall

= unit vector to camera = unit reflected vector = angle between and

  • .
  • .
  • is specular component of light
  • is shininess coefficient
  • Can add distance term as well

v r φ cos(φ) = v · r v r Is = ksLs(cos φ)α Ls α n l r v φ

slide-35
SLIDE 35

Shininess Coefficient

  • .
  • is the shininess 


coefficient

35

Is = ksLs(cos φ)α α (cos φ)α φ

Higher gives narrower curves

α α = 1

low α high α

Source: 


  • Univ. of Calgary
slide-36
SLIDE 36

Summary of Phong Model

36

= unit vector to light = surface normal

l n

= reflected about = vector to viewer

r v l n

  • Light components for each color:
  • Ambient ( ), diffuse ( ), specular ( )
  • Material coefficients for each color:
  • Ambient ( ), diffuse ( ), specular ( )
  • Distance q for surface point from light source

La

Ld

Ls ks kd ka

slide-37
SLIDE 37

Summary of Phong Model

37

slide-38
SLIDE 38

BRDF

  • Bidirectional Reflection Distribution Function
  • Must measure for

real materials

  • Isotropic vs. anisotropic
  • Mathematically complex
  • Programmable

pixel shading

38

Lighting properties of a human face were 
 captured and face re-rendered; Institute for Creative Technologies

slide-39
SLIDE 39

Summary

  • Global and Local Illumination
  • Normal Vectors
  • Light Sources
  • Phong Illumination Model

39

slide-40
SLIDE 40

http://cs420.hao-li.com

Thanks!

40