computer graphics: programming, problem solving, and visual communication steve cunningham...

32
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College PowerPoint Instructor’s Resource

Upload: rachel-bennett

Post on 13-Dec-2015

224 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Computer Graphics:Programming, Problem Solving,

and Visual Communication

Steve CunninghamCalifornia State University Stanislaus and Grinnell College

PowerPoint Instructor’s Resource

Page 2: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Lighting and Shading

Making images with a more naturalistic appearance

Page 3: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Two Parts to This Chapter

• Lighting– Defining lights and materials to compute

the colors for objects

• Shading– Defining how colors change across a

polygon as it is displayed

Page 4: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Lighting Model

• We will use the local lighting model: all light comes from lights defined within the scene

• Light is seen to have three components:– Ambient light– Diffuse light– Specular light

• All light uses the RGB color model

Page 5: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Ambient Light

• This is light that is simply present in the scene, without reference to any source

• Ambient light models the overall light that is reflected among objects

• It is represented by a simple color value

Page 6: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Diffuse Light

• Diffuse light is light that comes directly from a light source and is then sent to the viewer by the object

• Its color depends on the nature of the object– The light is absorbed by the object’s

material and only certain wavelengths are re-radiated

Page 7: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Specular Light

• Specular light is light that is reflected from a light source directly by an object

• It does not interact with the object and is generally the color of the light source

• The main characteristic of specular light is that it makes things look shiny

Page 8: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Each Light

• Has a position in space

• Has a color for each kind of light– Ambient color– Diffuse color– Specular color

• May have other properties– Spotlight– Directional light

Page 9: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Light Processes -- Ambient

• Light is simply present but involves objects• Total ambient light A is a scene-defined ambient

value L0 plus the sum of the individual ambient lights

• Individual light contributions come from ambient light LA and material ambient value CA

A = L0 + LA *CAlights

Page 10: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Light Processes -- Diffuse

• Diffuse light depends on the direction of light because of area seen by light

Page 11: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Light Processes -- Diffuse (2)

• The area visible to light depends on the cosine of the angle to the light -- the dot product of the light and normal vectors

• The eye direction does not matter!

• With light diffuse value LD and materials diffuse value CD total diffuse light D is given by

D = LDlights

∑ ∗CD ∗ L • N( )

Page 12: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Light Processes -- Specular

• Specular light depends on the angle between the eye and the reflection of a light

Page 13: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Light Processes -- Specular (2)

• Specular light also depends on the shininess M of the surface; this is modeled by a cosine function

• Since the cosine is the dot product E•R, for light specular value LS, material value CS, and material shininess M, we have

cosM Θ( )

S = LS ∗CSlights

∑ ∗ E • R( )M

Page 14: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Colored Lights

• A white cube, shown with three lights of different colors, illustrates how the light determines the color

Page 15: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Normals

• Normals are part of the geometry in the scene graph shape node

• Can be computed as the cross product of two adjacent edges

• If several polygons meet at a vertex, the normals for each polygon can be averaged

• Normals can also be computed exactly from directional derivatives if the object geometry is analytic

Page 16: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Effect of Shininess

• Higher values of the shininess coefficient M lead to smaller and brighter shiny spots

• From lower (left) to higher(right) values, we have

Page 17: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Defining Materials

• To define the material properties for your objects, you simply define the color for each lighting component and the value of the shininess

• These are all RGBA colors

• Materials are part of the appearance in the shape node

Page 18: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

How Do You Use Lighting?

• In order to use lighting, you must have two things– You must have normals for each vertex of

your objects– You must define the material for each object

• When you enable lighting, the lighting calculations we saw above will be done to create the color for each object

Page 19: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Light Properties

• Position - point in space

• Color - RGB values for each light component

• Directional (option) - direction of light

• Spotlight (option) - direction and cutoff

• Attenuation (option) - dropoff of values with distance

Page 20: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Lights in the Scene Graph

• As far as the scene graph is concerned, a light is just another piece of geometry

• However, the position and direction of a light are affected by any transformations in effect when they are set, so the usual practice is to define lights at the top of the scene graph, before any modeling transformations

Page 21: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Lights and Visual Communication

• You can enable or disable lights as you want to provide emphasis or to show things in different ways

Page 22: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Lights and Visual Communication (2)

• Using lighting can be effective in communicating information, as this lighted map of South Africa shows

Page 23: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Shading

• Computing the color of each part of a graphic object, especially a polygon

• We have properties at each vertex, and shading uses these to compute the color at each pixel in the object

• OpenGL offers only flat and smooth shading

• Other kinds are possible with more work

Page 24: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Flat and Smooth Shading

• Flat shading simply applies a single color to an entire polygon– Color can be set or can be computed from

shading

• Smooth shading interpolates vertex colors across the polygon– Vertex colors can be set or computed

Page 25: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Shading Examples

• Flat shading on each polygon

• Smooth shading on each polygon

Page 26: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Shading Tradeoff

• Smooth shading on larger polygons vs flat shading on smaller polygons

• Tradeoff is both time and appearance

Page 27: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Other Shading Models

• Phong shading: interpolate the normals across a polygon and compute the color for each pixel directly

• Smooth (left) and Phong (right) compared

Page 28: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Anisotropic Shading

• Our original lighting model required that the reflection was the same in all directions

• In some real materials it is not, and anisotropic shading deals with that

Page 29: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Other Techniques

• Bump mapping

Page 30: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

Global Illumination

• For simple computer graphics, we usually only deal with local illumination and let all light come only from lights

• Global illumination considers not only how light comes into a scene, but also how light is reflected within a scene

• More complex, but more realistic

• Two main algorithms: radiosity and photon mapping

Page 31: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

A Radiosity Example

Page 32: Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College

A Photon Mapping Example