Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface...

67
Shading 03/19/2003

Transcript of Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface...

Page 1: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Shading

03/19/2003

Page 2: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Lighting Principles

• Lighting based on how objects reflect light– Surface characteristics– Light color and direction– Global lighting settings

• OpenGL uses an additive color model

• Phong lighting model

Page 3: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Lighting Principles

• Light that is directly reflected off the surface creates a specular highlight

• Light that is absorbed into the material before it is reflected creates the color we see. (Diffuse color)

• Material's appearance is the result of a combination of several light and material properties

Page 4: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Surface Normals

• Color determined by several factors– Surface normal and color– Light position– Eye position

N

Page 5: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Specifying Material Properties

• glMaterialfv( face, property, value );• Material properties

– GL_EMISSION– GL_AMBIENT– GL_DIFFUSE– GL_SPECULAR– GL_SHININESS

• Primitives have material properties for front and back sides

Page 6: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Setting Material Properties

GLfloat green[] = { 0.0, 1.0, 0.0, 1.0 };GLfloat red[] = { 1.0, 0.0, 0.0, 1.0 };GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );

glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, red );

glMaterialfv( GL_FRONT, GL_SPECULAR, white );

glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 100.0 );

Page 7: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Determining Vertex Color

• vertex color = the material emission at that vertex +

the global ambient light scaled by the material's ambient property at that vertex +

the ambient, diffuse, and specular contributions from all the light sources, properly attenuated

Page 8: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Material Properties

Parameter Name Default Value Meaning GL_AMBIENT (0.2, 0.2, 0.2, 1.0) ambient color of material GL_DIFFUSE (0.8, 0.8, 0.8, 1.0) diffuse color of material GL_AMBIENT_AND_DIFFUSE ambient and diffuse

color of material GL_SPECULAR (0.0, 0.0, 0.0, 1.0) specular color of material GL_SHININESS 0.0 specular exponent GL_EMISSION (0.0, 0.0, 0.0, 1.0) emissive color of material

Page 9: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Ambient Reflection of Material

• Ambient reflectance affects the overall color of the object. – Diffuse reflectance is brightest where an object is directly

illuminated.– Ambient reflectance is most noticeable where an object

receives no direct illumination.

• An object's total ambient reflectance is affected by the global ambient light and ambient light from individual light sources.

• Like diffuse reflectance, ambient reflectance isn't affected by the position of the viewpoint.

Page 10: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 11: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Lighted, smooth-shaded teapots drawn with different material properties that approximate real materials. The first column has materials that resemble (from top to bottom) emerald, jade, obsidian, pearl, ruby, and turquoise. The second column resembles brass, bronze, chrome, copper, gold, and silver. The third column represents various colors of plastic: black, cyan, green, red, white, and yellow. The fourth column is drawn with similar colors of rubber.

Page 12: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Specular Reflectance

• If gray, the highlight is the color of the light• If non gray, the highlight is a combination

of the light and the specular color• Characteristics of specular highlight set

with shininess exponent (0.0-128.0) – High value - concentrated specular reflection– Low value - larger less concentrated (more

diffuse) specular reflection

Page 13: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Specular Reflectance

• Specular reflection from an object produces highlights.

• The amount of specular reflection seen by a viewer does depend on the location of the viewpoint – It's brightest along the direct angle of reflection.

Page 14: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Diffuse Reflectance• Plays the most important role in determining what

you perceive the color of an object to be. • Affected by the color of the incident diffuse light

and the angle of the incident light relative to the normal direction. (It's most intense where the incident light falls perpendicular to the surface.)

• Position of the viewpoint doesn't affect diffuse reflectance at all.

Page 15: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Ambient Reflectance• Affects the overall color of the object.• Diffuse reflectance is brightest where an object is

directly illuminated, ambient reflectance is most noticeable where an object receives no direct illumination.

• Object’s total ambient reflectance is affected by the global ambient light and ambient light from individual light sources.

• Diffuse reflectance, ambient reflectance isn't affected by the position of the viewpoint.

Page 16: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Emissive Reflectance• Make an object appear to be giving off light of

that color.• Most real-world objects (except lights) don't emit

light, you'll probably use this feature mostly to simulate lamps and other light sources in a scene.

• Give appearance of slightly glowing.– They're not actually acting as light sources.

– Create a light source and position it at the same location as the sphere to create that effect.

Page 17: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Twelve spheres, each with different material parameters. The row properties are as

follows: row 1 - No ambient reflectionrow 2 - Grey ambient reflection

row 3 - Blue ambient reflection. Column 1 - uses a blue diffuse material color with no specular propertiesColumn 2 - The secondcolumn adds white specular reflection with a low shininess exponentColumn 3 - The third column uses a high shininess exponent and thus has a more concentrated highlight. Column 4 - The fourth column uses the blue diffuse color and, instead of specular reflection, adds an emissive component.

Page 18: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Light Sources

• glLightfv( light, property, value );– light specifies which light– multiple lights, starting with GL_LIGHT0

• Infinite and local lights• Local lights can also be spot lights (the local light will shine in a direction and its light will be limited to a cone centered around that direction vector.– GL_SPOT_DIRECTION– GL_SPOT_CUTOFF– GL_SPOT_EXPONENT

Page 19: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Light in OpenGL

• Ambient Light

• Emitted Light

• Diffuse Light

• Specular Light

Page 20: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Global Ambient Light

• Uniform light level• Light has been scattered so much that you

can't tell where it comes from• Appears to come from all directions• Constant throughout the scene• A kludge• Ambient light is scattered equally in all

directions after hitting an object

Page 21: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Emitted Light

• The simplest light.

• It originates from an object and is unaffected by any light sources.

Page 22: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Diffuse Light

• Comes from one direction• So it's brighter if it comes squarely down on a

surface than if it barely glances off the surface• After hitting a surface, it's scattered equally in all

directions, so it appears equally bright, no matter where the eye is located

• Any light coming from a particular position or direction probably has a diffuse component.

Page 23: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Specular Light

• Comes from a particular direction

• Bounces off the surface in a preferred direction

• A well-collimated laser beam bouncing off a high-quality mirror produces almost 100 percent specular reflection

• specularity as shininess.

Page 24: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Specifying Light Sources in OpenGL

• Light sources have a number of properties, such as color, position, and direction.

• void glLight{if}[v](GLenum light, GLenum pname, TYPEparam);

• Creates the light specified by light, which can be GL_LIGHT0, GL_LIGHT1, ... , or GL_LIGHT7.

• The characteristic of the light being set is defined by pname

Page 25: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Position

• Directional light source – Located infinitely far away from the scene

– Rays of light can be considered parallel by the time they reach an object

– Sun

• Positional light source – Located near to the scene

– The direction from which the light rays come

– Desk lamp

Page 26: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Objects drawn with gray material parameters and colored light sources. (left) An infinite light source is used; (right) A local light source is used. With the infinite light source, the highlight (specular reflection) is centered on both the cone and the sphere because the angle between the object and the line of sight is ignored. With a local light source, the angle is taken into account, so the highlights are located appropriately on both objects.

Page 27: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Attenuation

• For real-world lights– the intensity of light decreases as distance from

the light increases

• OpenGL attenuates a light source by multiplying the contribution of that source by an attenuation factor:

Page 28: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Light Sources

• Light color properties– GL_AMBIENT– GL_DIFFUSE– GL_SPECULAR

• Light attenuation– GL_CONSTANT_ATTENUATION– GL_LINEAR_ATTENUATION– GL_QUADRATIC_ATTENUATION

Page 29: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Parameter Name Default Value MeaningGL_AMBIENT (0.0, 0.0, 0.0, 1.0) ambient RGBA

intensity of lightGL_DIFFUSE (1.0, 1.0, 1.0, 1.0) diffuse RGBA intensity of lightGL_SPECULAR (1.0, 1.0, 1.0, 1.0) specular RGBA intensity of lightGL_POSITION (0.0, 0.0, 1.0, 0.0) (x, y, z, w) position of lightGL_SPOT_DIRECTION

(0.0, 0.0, -1.0) (x, y, z) direction of spotlightGL_SPOT_EXPONENT 0.0 spotlight exponentGL_SPOT_CUTOFF 180.0 spotlight cutoff angleGL_CONSTANT_ATTENUATION

1.0 constant attenuation factorGL_LINEAR_ATTENUATION 0.0 linear attenuation factorGL_QUADRATIC_ATTENUATION 0.0 quadratic attenuation factor

Page 30: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Lighting Example

GLfloat white[] = { 1, 1, 1, 0 };

GLfloat magenta[] = { 0.8, 0, 0.8, 0 };

GLfloat pos[] = { 2.5, 6, 3.5, 1.0 };

glLightfv( GL_LIGHT0,

GL_AMBIENT_AND_DIFFUSE, magenta );

glLightfv( GL_LIGHT0,GL_SPECULAR,white);

glLightfv( GL_LIGHT0, GL_POSITION, pos );

glEnable( GL_LIGHT0 );

glEnable( GL_LIGHTING );

Page 31: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Enabling Lighting

• Turn on lighting calculations– glEnable( GL_LIGHTING );

• Turn on each light– glEnable( GL_LIGHTn );

Page 32: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Polygon Rendering

• Shading calculations require a tremendous amount of processing.

• Based on polygon normals or vertex normals and pixel color.

Page 33: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Wireframe

• Shows underlying structure

• No surfaces are visible

• No shading necessary

Page 34: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Flat

• Polygon is shaded with a single color.

• Same geometric polygon normal used for each vertex.

• If polygon normal points toward a light, the surface is illuminated

Page 35: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Faceted

• Polygon normal is the same for all vertices.

• If polygon normal points toward a light, the surface is illuminated

Page 36: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Smooth Render Style

• Uses vertex normals

• Colors are calculated for vertices

• Colors are interpolated between the vertices for edge colors

• Colors are interpolated across rendered scan lines

Page 37: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Gouraud Shading

• May be done in hardware

• Uses vertex normals

• Interpolated vertex normals to calculate light at every pixel

Page 38: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Phong Shading

• Calculates surface normals at vertices

• Interpolates surface normals between vertices

• Calculates color of surface

Page 39: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Phong Shading

• Almost always done off line

• Better quality than Gouraud

• Increased rendering time

Page 40: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Lighting Principles Review

• Light that is directly reflected off the surface creates a specular highlight

• Light that is absorbed into the material before it is reflected creates the color we see. (Diffuse color)

• Material's appearance is the result of a combination of several light and material properties

Page 41: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Rendering• Process of producing a two dimensional

image from 3D model

• Rendering Approaches– LOCAL

• Gouraud Shading

• Phong Shading

– GLOBAL• Ray Tracing

• Radiosity

Page 42: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Local Illumination

• Local– Contribution from the light that goes directly

from the light source and is reflected from the surface

– Shading of any surface is independent from the shading of all other surfaces

Page 43: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Global Illumination

• Contribution from the light that goes directly from the light source and is reflected from the surface

• Contribution from the light that is reflected from other surfaces to the current surface

Page 44: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Local Illumination Algorithms

• Scan line rendering

• Wireframe

• Faceted or flat shading

• Gouraud shading

• Phong shading

Page 45: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Photorealism VsLighting Visualization

• Photorealism

– Mimic reality but not physically real (ambient light)

– Look real

– Approximate interplay of lighting

• Lighting visualization

– Used when lighting must match real world

– Calculates scene lighting from reality

– Distinguishes between natural and electric lights

Page 46: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Gouraud

• Uses vertex normals

• Colors are calculated for vertices

• Colors are interpolated between the polygon edges

• May be done in hardware

Page 47: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Phong Shading

• Uses vertex normals

• Interpolated vertex normals to calculate light at every pixel

• Almost always done off line

Page 48: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Ray Tracing

• Ray tracing involves following paths or trees of line segments through the scene to compute the effects of typical light paths.

Page 49: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Ray Tracing Advantages

• Shadows

• Shiny objects

• Arbitrary geometry types, anything that you can intersect with a ray

Page 50: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Ray Tracing Disadvantages

• No distance fall-off of light

• Sharp shadows,

• Sharp specular reflections

Page 51: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Radiosity

• The rate at which energy leaves a surface

• Energy per time per unit area

• "radiosity equation" describes the amount of energy which can be emitted from a surface, as the sum of the energy inherent in the surface (a light source, for example) and the energy which strikes the surface, being emitted from some

other surface.

Page 52: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.

Radiosity

Page 53: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 54: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 55: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 56: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 57: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 58: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 59: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 60: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 61: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 62: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 63: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 64: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 65: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 66: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Page 67: Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.