computer graphics: programming, problem solving, and visual communication steve cunningham...
TRANSCRIPT
Computer Graphics:Programming, Problem Solving,
and Visual Communication
Steve CunninghamCalifornia State University Stanislaus and Grinnell College
PowerPoint Instructor’s Resource
Lighting and Shading
Making images with a more naturalistic appearance
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
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
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
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
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
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
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
∑
Light Processes -- Diffuse
• Diffuse light depends on the direction of light because of area seen by light
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( )
Light Processes -- Specular
• Specular light depends on the angle between the eye and the reflection of a light
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
Colored Lights
• A white cube, shown with three lights of different colors, illustrates how the light determines the color
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
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
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
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
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
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
Lights and Visual Communication
• You can enable or disable lights as you want to provide emphasis or to show things in different ways
Lights and Visual Communication (2)
• Using lighting can be effective in communicating information, as this lighted map of South Africa shows
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
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
Shading Examples
• Flat shading on each polygon
• Smooth shading on each polygon
Shading Tradeoff
• Smooth shading on larger polygons vs flat shading on smaller polygons
• Tradeoff is both time and appearance
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
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
Other Techniques
• Bump mapping
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
A Radiosity Example
A Photon Mapping Example