View
220
Download
0
Embed Size (px)
Citation preview
Objectives Objectives
Learn to shade objects so their images appear three-Learn to shade objects so their images appear three-dimensionaldimensional
Introduce the types of light-material interactionsIntroduce the types of light-material interactions Build a simple reflection model---the Phong Build a simple reflection model---the Phong
model--- that can be used with real time graphics model--- that can be used with real time graphics hardwarehardware
CSC461: Lecture 22CSC461: Lecture 22 Lighting and Shading Lighting and Shading
Why we need shadingWhy we need shading Suppose we build a model of a sphere using Suppose we build a model of a sphere using
many polygons and color it with many polygons and color it with glColorglColor. . We get something likeWe get something like
But we wantBut we want
ShadingShading Why does the image of a real sphere look likeWhy does the image of a real sphere look like
Light-material interactions cause each point to have Light-material interactions cause each point to have a different color or shadea different color or shade
Need to consider Need to consider Light sourcesLight sources Material propertiesMaterial properties Location of viewerLocation of viewer Surface orientationSurface orientation
ScatteringScatteringLight strikes A Light strikes A
Some scatteredSome scattered Some absorbedSome absorbed
Some of scattered light strikes BSome of scattered light strikes B Some scatteredSome scattered Some absorbedSome absorbed
Some of this scatterdSome of this scatterdlight strikes Alight strikes Aand so onand so on
Rendering EquationRendering Equation
The infinite scattering and absorption of The infinite scattering and absorption of light can be described by the light can be described by the rendering rendering equation equation CannotCannot bebe solved in generalsolved in general Ray tracing is a special case for perfectly Ray tracing is a special case for perfectly
reflecting surfacesreflecting surfaces Rendering equation is global and includesRendering equation is global and includes
ShadowsShadows Multiple scattering from object to objectMultiple scattering from object to object
Global EffectsGlobal Effects
translucent surface
shadow
multiple reflection
Color SourcesColor Sources RGB model is usedRGB model is used Light is simulated with the color modelLight is simulated with the color model Three component intensity or Three component intensity or luminanceluminance
functionfunction
Each component of a light source can be Each component of a light source can be independently calculatedindependently calculated
b
g
r
I
I
I
I
Local vs Global RenderingLocal vs Global Rendering
Correct shading requires a global calculation Correct shading requires a global calculation involving all objects and light sourcesinvolving all objects and light sources Incompatible with pipeline model which shades Incompatible with pipeline model which shades
each polygon independently (local rendering)each polygon independently (local rendering) However, in computer graphics, especially real However, in computer graphics, especially real
time graphics, we are happy if things “look time graphics, we are happy if things “look right”right” Exist many techniques for approximating global Exist many techniques for approximating global
effectseffects
Light-Material InteractionLight-Material Interaction Light that strikes an object is partially Light that strikes an object is partially
absorbed and partially scattered (reflected)absorbed and partially scattered (reflected) The amount reflected determines the color The amount reflected determines the color
and brightness of the objectand brightness of the object A surface appears red under white light because A surface appears red under white light because
the red component of the light is reflected and the the red component of the light is reflected and the rest is absorbedrest is absorbed
The reflected light is scattered in a manner The reflected light is scattered in a manner that depends on the smoothness and that depends on the smoothness and orientation of the surfaceorientation of the surface
Light SourcesLight Sources
General light sources are difficult to work General light sources are difficult to work with because we must integrate light with because we must integrate light coming from all points on the source coming from all points on the source
Simple Light SourcesSimple Light Sources Point sourcePoint source
Model with position and colorModel with position and color Distant source = infinite distance away (parallel)Distant source = infinite distance away (parallel)
SpotlightSpotlight Restrict light from ideal point sourceRestrict light from ideal point source
Ambient light Ambient light Same amount of light everywhere in sceneSame amount of light everywhere in scene Can model contribution of many sources and Can model contribution of many sources and
reflecting surfacesreflecting surfaces
Surface TypesSurface Types The smoother the surface, the more the reflected The smoother the surface, the more the reflected
light resembles a mirrorlight resembles a mirror A very rough surface scatters light in all directionsA very rough surface scatters light in all directions
smooth surface rough surface
Phong ModelPhong Model A simple model that can be computed rapidlyA simple model that can be computed rapidly The light source model has three termsThe light source model has three terms
DiffuseDiffuse SpecularSpecular AmbientAmbient
Uses four vectors at the Uses four vectors at the point ppoint p
l: to light sourcel: to light source v: to viewerv: to viewer n: Normaln: Normal r: Perfect reflectorr: Perfect reflector
Light SourcesLight Sources In the Phong Model, we add the results from each In the Phong Model, we add the results from each
light sourcelight source Each light source has separate Each light source has separate diffusediffuse, , specularspecular, and , and ambientambient terms to allow for maximum flexibility even terms to allow for maximum flexibility even though this form does not have a physical though this form does not have a physical justificationjustification
Separate Separate redred, , greengreen and and blueblue components for each components for each termterm
Hence, 9 coefficients for each point source – Hence, 9 coefficients for each point source – illumination matrixillumination matrix Diffuse -- IDiffuse -- Idrdr, I, Idgdg, I, Idbdb Specular -- ISpecular -- Isrsr, I, Isgsg, I, Isbsb Ambient -- IAmbient -- Iarar, I, Iagag, I, Iabab
Material PropertiesMaterial Properties Material properties match light source Material properties match light source
propertiesproperties Nine absorption coefficients – reflection matrixNine absorption coefficients – reflection matrix
Diffuse -- kDiffuse -- kdrdr, k, kdgdg, k, kdbdb
Specular -- kSpecular -- ksrsr, k, ksgsg, k, ksbsb
Ambient --Ambient -- k karar, k, kagag, k, kabab
Shininess coefficient Shininess coefficient
Adding up the ComponentsAdding up the Components For each light source and each color component, For each light source and each color component,
the Phong model can be written (without the the Phong model can be written (without the distance terms) asdistance terms) as
I =kI =kdd I Idd ll · · n n ++ kkss I Iss ( (vv · · r r ))+ k+ kaa I Iaa
For each color component For each color component we add contributions from we add contributions from all sourcesall sources
ExamplesExamples
Only differences in these teapots are the parametersin the Phong model
Ambient ReflectionAmbient Reflection Ambient light is the result of multiple Ambient light is the result of multiple
interactions between (large) light sources and interactions between (large) light sources and the objects in the environmentthe objects in the environment
Amount and color depend on both the color of Amount and color depend on both the color of the light(s) and the material properties of the the light(s) and the material properties of the objectobject
All points have the same light intensityAll points have the same light intensity Ambient effect kAmbient effect kaa I Iaa for all points for all points
reflection coefficient intensity of ambient light
Diffuse Reflection -- Lambertian SurfaceDiffuse Reflection -- Lambertian Surface Perfectly diffuse reflector -- Light scattered equally Perfectly diffuse reflector -- Light scattered equally
in all directionsin all directions Characterized by rough surfaces Characterized by rough surfaces Lambertian surface – no preferred reflection angle Lambertian surface – no preferred reflection angle Modeled with Lambert’s law: Amount of light Modeled with Lambert’s law: Amount of light
reflected is proportional to the vertical component of reflected is proportional to the vertical component of incoming lightincoming light reflected light ~cos reflected light ~cos ii
cos cos ii = = ll · · n n if vectors normalizedif vectors normalized
There are also three coefficients, kThere are also three coefficients, krr, k, kbb, k, kgg that show how that show how
much of each color component is reflectedmuch of each color component is reflected
Diffuse effect: kDiffuse effect: kdd I Idd ll · · n n
Specular SurfacesSpecular Surfaces Most surfaces are neither ideal diffusers nor perfectly Most surfaces are neither ideal diffusers nor perfectly
specular specular Smooth surfaces show specular highlights due to Smooth surfaces show specular highlights due to
incoming light being reflected in directions incoming light being reflected in directions concentrated close to the direction of a perfect concentrated close to the direction of a perfect reflection or a mirrorreflection or a mirror
specularhighlight
Modeling Specular RelectionsModeling Specular Relections Phong proposed an approximate model: add a term to Phong proposed an approximate model: add a term to
the calculation of diffuse reflectionthe calculation of diffuse reflection The term drops off as the angle between the viewer The term drops off as the angle between the viewer
(v) and the ideal reflection (r) increases(v) and the ideal reflection (r) increases
Ir ~ ks Is cosks Is (r·v)α
shininess coef
absorption coef
incoming intensityreflectedintensity
The Shininess CoefficientThe Shininess Coefficient Values of Values of between 100 and 500 correspond to metals between 100 and 500 correspond to metals Values between 5 and 10 give surface that look like plasticValues between 5 and 10 give surface that look like plastic As As increases, the reflected light concentrates in a increases, the reflected light concentrates in a
narrower regionnarrower region As As goes to infinity, get a mirrorgoes to infinity, get a mirror
cos
90-90
Distance TermsDistance TermsThe light from a point source that reaches a The light from a point source that reaches a
surface is inversely proportional to the square surface is inversely proportional to the square of the distance between themof the distance between them
We can add a factor of theWe can add a factor of the form 1/(a + bd +cdform 1/(a + bd +cd22) to) to the diffuse and specular the diffuse and specular termstermsThe constant and linear terms soften the effect The constant and linear terms soften the effect
of the point sourceof the point source