CS 543 - Computer Graphics: Illumination and Shading I by Robert - - PDF document

cs 543 computer graphics illumination and shading i
SMART_READER_LITE
LIVE PREVIEW

CS 543 - Computer Graphics: Illumination and Shading I by Robert - - PDF document

CS 543 - Computer Graphics: Illumination and Shading I by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Illumination and Shading Problem: Model light/surface point interactions to determine final color and brightness


slide-1
SLIDE 1

1

CS 543 - Computer Graphics: Illumination and Shading I

by Robert W. Lindeman gogo@wpi.edu

(with help from Emmanuel Agu ;-) R.W. Lindeman - WPI Dept. of Computer Science 2

Illumination and Shading

Problem: Model light/surface point

interactions to determine final color and brightness

Apply the lighting model at a set of

points across the entire surface

Shading lighting

slide-2
SLIDE 2

2

R.W. Lindeman - WPI Dept. of Computer Science 3

Illumination Model

The governing principles for computing

the illumination

An illumination model usually considers

 Light attributes (intensity, color, position,

direction, shape)

 Object surface attributes (color, reflectivity,

transparency, etc.)

 Interaction among lights and objects

R.W. Lindeman - WPI Dept. of Computer Science 4

Basic Light Sources

 Light intensity can be independent or dependent

  • f the distance between object and the light

source

Point light Directional light Area light Spot light

slide-3
SLIDE 3

3

R.W. Lindeman - WPI Dept. of Computer Science 5

Local Illumination

Only consider the light, the observer

position, and the object material properties

OpenGL does this

θ

R.W. Lindeman - WPI Dept. of Computer Science 6

Global Illumination

Take into account the interaction of light

from all the surfaces in the scene

Example:

 Ray Tracing  Model light

rays bouncing around

  • bject 1
  • bject 2
  • bject 3
  • bject 4
slide-4
SLIDE 4

4

R.W. Lindeman - WPI Dept. of Computer Science 7

Global Illumination (cont.)

Example:

 Radiosity

 Model energy

moving from emitters (e.g., lights) into the scene

 View

independent

R.W. Lindeman - WPI Dept. of Computer Science 8

Simple Local Illumination

 The model used by OpenGL  Reduce the complex workings of light to three

components

 Ambient  Diffuse  Specular

 Final illumination at a point (vertex) =

ambient + diffuse + specular

 Materials reflect each component differently

 Use different material reflection coefficients  Ka, Kd, Ks

slide-5
SLIDE 5

5

R.W. Lindeman - WPI Dept. of Computer Science 9

Ambient Light Contribution

 Ambient light = background light  Light that is scattered by the environment

 It's just there

 Frequently assumed to be constant  Very simple approximation of global illumination  No direction: independent of light position, object

  • rientation, observer’s position/orientation
  • bject 1
  • bject 2
  • bject 3
  • bject 4

Ambient = I x Ka constant

R.W. Lindeman - WPI Dept. of Computer Science 10

Diffuse Light Contribution

Diffuse light: The illumination that a

surface receives from a light source that reflects equally in all direction

 Eye point does not matter

slide-6
SLIDE 6

6

R.W. Lindeman - WPI Dept. of Computer Science 11

Diffuse Light Calculation

Need to decide how much light the object

point receives from the light source

 Based on Lambert’s Law

Receive more light Receive less light

R.W. Lindeman - WPI Dept. of Computer Science 12

Diffuse Light Calculation (cont.)

 Lambert’s law: the radiant energy D that a small surface

patch receives from a light source is: Diffuse = Kd x I x cos(θ) Kd: diffuse reflection coefficient I: light intensity θ: angle between the light vector and the surface normal

N : surface normal light vector (vector from object to light) θ

slide-7
SLIDE 7

7

R.W. Lindeman - WPI Dept. of Computer Science 13

Diffuse Light Examples

Kd = 0.0 0.2 0.4 0.6 0.8 1.0 I = 1.0

R.W. Lindeman - WPI Dept. of Computer Science 14

Specular Light Contribution

The bright spot on the object The result of total reflection of the

incident light in a concentrate region

Sees no specular Sees lots of specular

slide-8
SLIDE 8

8

R.W. Lindeman - WPI Dept. of Computer Science 15

Specular Light Calculation

 How much reflection you can see depends on

where you are

 But for non-perfect surface you will still see specular

highlight when you move a little bit away from the ideal reflection direction

Φ is deviation of view angle from mirror direction  When φ is small, you see more specular highlight

R.W. Lindeman - WPI Dept. of Computer Science 16

Specular Light Calculation (cont.)

 Phong lighting model

 Not Phong shading model

 The effect of 'f' in the Phong model

Specular = Ks x I x cosf(φ)

f = 10 f = 30 f = 90 f = 270

slide-9
SLIDE 9

9

R.W. Lindeman - WPI Dept. of Computer Science 17

Specular Light Examples

Ks = 0.25 Ks = 0.5 Ks = 0.75 f = 3 f = 200 f = 6 f = 9 f = 25

R.W. Lindeman - WPI Dept. of Computer Science 18

Putting It All Together

 Illumination from a light Illum = ambient + diffuse + specular = Ka x I + Kd x I x cos(θ) + Ks x I x cosf(φ)  If there are N lights Total illumination for a point P = Σ (Illum)  Some more terms to be added (in OpenGL)

 Self emission  Global ambient  Light distance attenuation and spot light effect

slide-10
SLIDE 10

10

R.W. Lindeman - WPI Dept. of Computer Science 19

Putting It All Together (cont.)

 Illum = ambient + diffuse + specular

R.W. Lindeman - WPI Dept. of Computer Science 20

Ambient Lighting Example

slide-11
SLIDE 11

11

R.W. Lindeman - WPI Dept. of Computer Science 21

Diffuse Lighting Example

R.W. Lindeman - WPI Dept. of Computer Science 22

Specular Lighting Example

slide-12
SLIDE 12

12

R.W. Lindeman - WPI Dept. of Computer Science 23

Adding Color

 Sometimes light or surfaces are colored  Treat R,G and B components separately

 i.e., can specify different RGB values for either light

  • r material

 Illumination equation goes from Illum = ambient + diffuse + specular = Ka x I + Kd x I x cos(θ) + Ks x I x cosf(φ)

To:

Illumr= Kar x Ir + Kdr x Ir x cos(θ) + Ksr x Ir x cosf(φ) Illumg= Kag x Ig + Kdg x Ig x cos(θ) + Ksg x Ig x cosf(φ) Illumb= Kab x Ib + Kdb x Ib x cos(θ) + Ksb x Ib x cosf(φ)

R.W. Lindeman - WPI Dept. of Computer Science 24

Adding Color (cont.)

(excerpt from Hill, Fig. 8.17)

89.6 0.773911 0.773911 0.773911 0.2775 0.2775 0.2775 0.23125 0.23125 0.23125 Polished Silver 27.8974 0.992157 0.941176 0.807843 0.780392 0.568627 0.113725 0.329412 0.223529 0.027451 Brass 32 0.5 0.5 0.5 0.01 0.01 0.01 0.0 0.0 0.0 Black plastic Exponent f Specular Ksr, Ksg, Ksb Diffuse Kdr, Kdg, Kdb Ambient Kar, Kag, Kab Material

slide-13
SLIDE 13

13

R.W. Lindeman - WPI Dept. of Computer Science 25

Lighting in OpenGL

Adopt Phong lighting model

 Ambient + Specular + Diffuse lights  Lighting is computed at vertices

 Interpolate across surface (Gouraud/smooth

shading)

Setting up OpenGL lighting

 Light properties  Enable/disable lighting  Surface material properties  Provide correct surface normals  Set light model properties

R.W. Lindeman - WPI Dept. of Computer Science 26

Light Properties

Properties

Colors / Position and type / attenuation glLightfv( light, property, value )

(1) Constant: specify which light you want to set the property for e.g., GL_LIGHT0, GL_LIGHT1, GL_LIGHT2 ... you can create multiple lights (OpenGL allows at least 8 lights) (2) Constant: specify which light property you want to set e.g., GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION

(check the red book, or the Web, for more)

(3) The value you want to set to the property 1 2 3

slide-14
SLIDE 14

14

R.W. Lindeman - WPI Dept. of Computer Science 27

Property Example

Define colors and position a light

GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_position[] = { 0.0, 0.0, 1.0, 1.0 }; glLightfv( GL_LIGHT0, GL_AMBIENT, light_ambient ); glLightfv( GL_LIGHT0, GL_DIFFUSE, light_diffuse ); glLightfv( GL_LIGHT0, GL_SPECULAR, light_specular ); glLightfv( GL_LIGHT0, GL_POSITION, light_position ); Colors Position

What if I set Position to (0, 0, 1, 0)?

R.W. Lindeman - WPI Dept. of Computer Science 28

Types of Lights

OpenGL supports two types of lights

 Local light (point light)  Infinite light (directional light)

Determined by the light positions you

provide

 w = 0: Infinite light source  w != 0:Point light

 Position = (x/w, y/w, z/w)

GLfloat light_position[] = { x, y, z, w }; glLightfv( GL_LIGHT0, GL_POSITION, light_position );

slide-15
SLIDE 15

15

R.W. Lindeman - WPI Dept. of Computer Science 29

Turning on the Lights

Turn on/off the power (for all the lights)

 glEnable( GL_LIGHTING );  glDisable( GL_LIGHTING );

Turn on each light switch

 glEnable( GL_LIGHTn ) (n = 0, 1, 2, ...)

R.W. Lindeman - WPI Dept. of Computer Science 30

Controlling Light Position

 Modelview matrix affects a light’s position  Two options

 Option a:  Treat light like vertex  Do pushMatrix, translate, rotate, ...

glLightfv POSITION, popMatrix

 Then call gluLookAt  Light moves independently of camera  Option b:  Load identity matrix in modelview matrix  Call glLightfv then call gluLookAt  Light appears at the eye (like a miner’s lamp)

slide-16
SLIDE 16

16

R.W. Lindeman - WPI Dept. of Computer Science 31

Material Properties

 The color and surface properties of a material

(dull, shiny, etc.)

 How much the surface reflects the incident

lights

 ambient/diffuse/specular reflection coefficients

glMaterialfv( face, property, value );

face: Material property for which side of the polygon (e.g., GL_FRONT, GL_BACK, GL_FRONT_AND_BACK) property: What material property you want to set (e.g., GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_SHININESS, GL_EMISSION, etc.) value: The value to assign to the property

R.W. Lindeman - WPI Dept. of Computer Science 32

Material Example

Define ambient/diffuse/specular

reflection and shininess

GLfloat mat_amb_diff[] = { 1.0, 0.5, 0.8, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat shininess[] = { 5.0 }; Range: dull 0 – very shiny

128

glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff ); glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular ); glMaterialfv( GL_FRONT, GL_SHININESS, shininess );

Refl. coeff.

slide-17
SLIDE 17

17

R.W. Lindeman - WPI Dept. of Computer Science 33

Surface Normals

 Correct normals are essential for correct

lighting

 Associate a normal with each vertex glBegin(…); glNormal3f( u, v, n ); glVertex3f( x, y, z ); ... glEnd( );  All normals must be specified in unit length

 More on why in the next slide set!

R.W. Lindeman - WPI Dept. of Computer Science 34

Colored Wireframe

slide-18
SLIDE 18

18

R.W. Lindeman - WPI Dept. of Computer Science 35

Colored Hidden-Line Removal

R.W. Lindeman - WPI Dept. of Computer Science 36

Ambient Term Only

slide-19
SLIDE 19

19

R.W. Lindeman - WPI Dept. of Computer Science 37

Flat Shading

R.W. Lindeman - WPI Dept. of Computer Science 38

Diffuse Shading + Interp. Normals

slide-20
SLIDE 20

20

R.W. Lindeman - WPI Dept. of Computer Science 39

Gouraud Shading

R.W. Lindeman - WPI Dept. of Computer Science 40

Ambient + Diffuse + Specular

slide-21
SLIDE 21

21

R.W. Lindeman - WPI Dept. of Computer Science 41

Ambient + Diffuse + Specular + Interpolated Normals

R.W. Lindeman - WPI Dept. of Computer Science 42

Radiosity

slide-22
SLIDE 22

22

R.W. Lindeman - WPI Dept. of Computer Science 43

Texture Mapping

R.W. Lindeman - WPI Dept. of Computer Science 44

Texture Mapping + Ray Tracing