CS488 Shading and Illumination Luc R ENAMBOT Introduction Through - - PowerPoint PPT Presentation

cs488 shading and illumination
SMART_READER_LITE
LIVE PREVIEW

CS488 Shading and Illumination Luc R ENAMBOT Introduction Through - - PowerPoint PPT Presentation

CS488 Shading and Illumination Luc R ENAMBOT Introduction Through the first half of the class, polygons were represented by the line segments connecting their vertices, or by filling them with a solid color. This is not very realistic


slide-1
SLIDE 1

CS488 Shading and Illumination

Luc RENAMBOT

slide-2
SLIDE 2

Introduction

  • Through the first half of the class, polygons

were represented by the line segments connecting their vertices, or by filling them with a solid color. This is not very realistic looking

  • Now we are going to talk about how

different lighting models are used to make computer graphics look more realistic

2

slide-3
SLIDE 3

General Principles

  • Trying to recreate reality is difficult
  • Lighting calculations can take a

VERY long time.

  • The techniques described here are heuristics which

produce appropriate results, but they do not work in the same way reality works - because that would take too long to compute, at least for interactive graphics

  • Instead of just specifying a single color for a polygon we

will instead specify the properties of the material that the polygon is supposed to be made out of, and the properties of the light or lights shining onto that material.

3

slide-4
SLIDE 4

Illumination Models

  • No Lighting
  • There are no lights in the scene
  • Each polygon is self-luminous (it lights itself, but does not

give off light)

  • Each polygon has its own color which is constant over

its surface

  • That color is not affected by anything else in the world
  • That color is not affected by the position or orientation
  • f the polygon in the world
  • This is very fast, but not very realistic
  • position of viewer is not important

4

slide-5
SLIDE 5

No Lighting

  • I = Ki
  • I: intensity
  • Ki: object's intrinsic intensity, 0.0 - 1.0 for

each of R, G, and B

5

slide-6
SLIDE 6

Ambient Model

  • Non-directional light source
  • Simulates light that has been reflected so many times from so many surfaces it

appears to come equally from all directions

  • Intensity is constant over polygon's surface
  • Intensity is not affected by anything else in the world
  • Intensity is not affected by the position or orientation of the polygon in the

world

  • Position of viewer is not important
  • I = Ia Ka
  • I: intensity
  • Ia: intensity of Ambient light
  • Ka: object's ambient reflection coefficient, 0.0 - 1.0 for each of R, G, and B

6

slide-7
SLIDE 7

Types of Light Sources

  • Point light - a light that gives off equal amounts of

light in all directions. Polygons, and parts of polygons which are closer to the light appear brighter than those that are further away

  • Directional light - if a point light is moved to infinity,

all of the light rays emanating from the light strike the polygons in the scene from a single direction

  • Spotlight - light that radiates light in a cone with

more light in the center of the cone, gradually tapering off towards the sides of the cone

7

slide-8
SLIDE 8

Examples

  • Model of an
  • wl:
  • Bounding

boxes of the components

  • f the owl

8

slide-9
SLIDE 9

Self-luminous owl

9

slide-10
SLIDE 10

Directional light from the front of the owl

10

slide-11
SLIDE 11

Point light slightly in front of the owl

11

slide-12
SLIDE 12

Spotlight slightly in front of the owl aimed at the owl

12

slide-13
SLIDE 13

Diffuse Reflection

  • Lambertian Reflection
  • Using a point light:
  • Comes from a specific direction
  • Reflects off of dull surfaces
  • Light reflected with equal intensity in all directions
  • Brightness depends on theta - angle between

surface normal (N) and the direction to the light source (L)

  • Position of viewer is not important

13

slide-14
SLIDE 14

Illumination

  • Usually three components:
  • I = ambient + diffuse + specular

14

slide-15
SLIDE 15

Diffuse Reflection

  • I = Ip Kd cos(theta) or I = Ip Kd(N' * L')
  • I: intensity
  • Ip: intensity of point light
  • Kd: object's diffuse reflection reflection

coefficient, 0.0 - 1.0 for each of R, G, and B

  • N': normalized surface normal
  • L': normalized direction to light source

15

slide-16
SLIDE 16

Diffuse Reflection

  • Using a directional light
  • I = Ip Kd cos(theta) or I = Ip Kd(N' * L')
  • theta is constant
  • L' is constant
  • Directional lights are faster than point lights

because L' does not need to be recomputed for each polygon

16

slide-17
SLIDE 17

Adding Ambient Light

  • It is rare that we have an object in the real

world illuminated only by a single light

  • There is always some ambient light. To make

sure all sides of an object get at least a little light we add some ambient light:

  • I = Ia Ka + Ip Kd(N' * L')

17

slide-18
SLIDE 18

Attenuation

  • Currently there is no distinction made

between an object close to a point light and an

  • bject far away from that light
  • It helps to introduce a term based on distance

from the light

  • Source attenuation factor: Fatt.
  • I = Ia Ka + Fatt Ip Kd(N' * L')
  • Coming up with an appropriate value for Fatt

is rather tricky

18

slide-19
SLIDE 19

Specular Reflection

  • Reflection off of shiny surfaces - you see a

highlight

  • Shiny metal or plastic has high specular

component

  • Chalk or carpet has very low specular

component

  • Position of the viewer IS important in specular

reflection

19

slide-20
SLIDE 20

Specular Reflection

  • Depends on perfect reflection direction, viewer

direction, and surface normal

  • I = Ip cos^n(a) W(theta)
  • I: intensity
  • Ip: intensity of point light
  • n: specular-reflection exponent (higher is

sharper falloff)

  • W: gives specular component of non-specular

materials

20

slide-21
SLIDE 21

Reflection

21

slide-22
SLIDE 22

Falloff

22

slide-23
SLIDE 23

Specular Reflection

23

slide-24
SLIDE 24

Putting It All Together

  • I = Ia Ka + Ip Kd(N' * L') + Ip cos^n(a) W(theta)
  • Multiple Lights
  • With multiple lights the affect of all the lights

are additive

24

slide-25
SLIDE 25

OpenGL

  • A polygon can have the following material

properties:

  • ambientColor (R, G, B)
  • diffuseColor (R, G, B)
  • specularColor (R, G, B)
  • emissiveColor (R, G, B)
  • transparency 0.0 - 1.0
  • shininess 0.0 - 1.0

25

slide-26
SLIDE 26

OpenGL

  • glLightfv(GL_LIGHT0, GL_AMBIENT, amb_light_rgba );
  • glLightfv(GL_LIGHT0, GL_DIFFUSE, dif_light_rgba );
  • glLightfv(GL_LIGHT0, GL_SPECULAR, spec_light_rgba );
  • glLightfv(GL_LIGHT0, GL_POSITION, position);
  • glEnable(GL_LIGHT0);
  • glMaterialfv( GL_FRONT, GL_AMBIENT, ambient_rgba );
  • glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuse_rgba );
  • glMaterialfv( GL_FRONT, GL_SPECULAR, specular_rgba );
  • glMaterialfv( GL_FRONT, GL_SHININESS, n );

26

slide-27
SLIDE 27

OpenGL

  • These properties describe how light is reflected off the

surface of the polygon

  • A polygon with diffuse color (1, 0, 0) reflects all of the red

light it is hit with, and absorbs all of the blue and green

  • If this red polygon is hit with a white light it will appear red.
  • If it with a blue light, or a green light, or an aqua light it will

appear black (as those lights have no red component.)

  • If it is hit with a yellow light or a purple light it will appear

red (as the polygon will reflect the red component of the light)

27

slide-28
SLIDE 28

Examples

28

Ball Light Image Ball Light Image white red purple blue red white yellow aqua red green

slide-29
SLIDE 29

Fog

  • Atmospheric affects give us a sense of depth
  • Fog useful to simulate this effect
  • Characterized by
  • a starting distance,
  • an ending distance,
  • a color
  • The fog begins at the starting distance and all the colors

slowly transition to the fog color towards the ending distance.

  • At the ending distance all colors are the fog color

29

slide-30
SLIDE 30

Examples

30

slide-31
SLIDE 31

OpenGL Fog

  • Specify:
  • Color of the fog as R, G, and B values
  • Function for how to map the intermediate

distances (linear, exponential, exponential squared

  • Where the fog begins and where the fog ends

if using linear mapping

  • Density of the fog if using one of the two

exponentials mappings

31

slide-32
SLIDE 32

OpenGL Fog

32

Without fog With fog

slide-33
SLIDE 33

OpenGL Calls

  • glEnable (GL_FOG);
  • glFogi (GL_FOG_MODE, GL_LINEAR);
  • glFogfv (GL_FOG_COLOR, fogColor);
  • glFogf (GL_FOG_DENSITY, density);
  • glFogf (GL_FOG_START, 1);
  • glFogf (GL_FOG_END, 10);
  • glHint (GL_FOG_HINT, GL_NICEST);

33

slide-34
SLIDE 34

Shading Models

  • We often use polygons to simulate curved
  • surfaces. If these cases we want the colors of

the polygons to flow smoothly into each

  • ther
  • Flat shading
  • Goraud shading (interpolation shading)
  • Phong shading

34

slide-35
SLIDE 35

Flat Shading

  • Each entire polygon is drawn with the same color
  • Need to know one normal for the entire polygon
  • Fast
  • Lighting equation used once per polygon

35

slide-36
SLIDE 36

Flat Shading

36

slide-37
SLIDE 37

Gouraud Shading

  • Colors are interpolated across the polygon
  • Need to know a normal for each vertex of

the polygon

  • Slower than flat shading
  • Lighting equation used at each vertex

37

slide-38
SLIDE 38

Gouraud Shading

38

slide-39
SLIDE 39

Phong Shading

  • Normals are interpolated across the polygon
  • Need to know a normal for each vertex of

the polygon

  • Better at dealing with highlights than

Gouraud shading

  • Slower than Gouraud shading
  • Lighting equation used at each pixel

39

slide-40
SLIDE 40

Phong Shading

40

slide-41
SLIDE 41

Phong Shading

41

Ia = (Ys - Y2) / (Y1 - Y2) * I1 + (Y1 - Ys) / (Y1 - Y2) * I2 Ib = (Ys - Y3) / (Y1 - Y3) * I1 + (Y1 - Ys) / (Y1 - Y3) * I3 Ip = (Xb - Xp) / (Xb - Xa) * Ia + (Xp - Xa) / (Xb - Xa) * Ib

slide-42
SLIDE 42

Anti-Aliasing

  • Lines and the edges of polygons still look jagged at this

point.

  • This is especially noticeable when moving through a static

scene looking at sharp edges

  • This is known as aliasing, and is caused by the conversion

from the mathematical edge to a discrete set of pixels. We saw near the beginning of the course how to scan convert a line into the frame buffer, but at that point we only deal with placing the pixel or not placing the pixel.

42

slide-43
SLIDE 43

Anti-Aliasing

  • The mathematical line will likely not exactly cover pixel

boundaries - some pixels will be mostly covered by the line (or edge), and others only slightly. Instead of making a yes/ no decision we can assign a value to this coverage (from say 0 to 1) for each pixel and then use these values to blend the colour of the line (or edge) with the existing contents

  • f the frame buffer
  • In OpenGL you give hints setting the hints for

GL_POINT_SMOOTH_HINT, GL_LINE_SMOOTH_HINT, GL_POLYGON_SMOOTH_HINT

43

slide-44
SLIDE 44

Anti Aliasing

44

slide-45
SLIDE 45

Texture Mapping

  • Texture mapping is the process of

taking a 2D image and mapping onto a polygon in the scene

  • This texture acts like a painting,

adding 2D detail to the 2D polygon

  • Instead of filling a polygon with a

color in the scan conversion process with fill the pixels of the polygon with the pixels of the texture (texels)

45

slide-46
SLIDE 46

Texture Mapping

  • Also used to:
  • add detail
  • add 'roughness'
  • add patterns
  • i.e. bump-mapping

46

slide-47
SLIDE 47

Environment Mapping

47

slide-48
SLIDE 48

Example

48

slide-49
SLIDE 49

Example

49

slide-50
SLIDE 50

Next...

  • More Shading and Illumination

50