CS 445 / 645 Introduction to Computer Graphics Lecture 23 Bézier Curves Lecture 23 Bézier Curves.
CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading.
-
Upload
berenice-mckenzie -
Category
Documents
-
view
228 -
download
3
Transcript of CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading.
CS 445 / 645Introduction to Computer Graphics
Lecture 15Lecture 15
ShadingShading
Lecture 15Lecture 15
ShadingShading
Lighting Review
Lighting ModelsLighting Models
• Ambient Ambient
– Normals don’t matterNormals don’t matter
• Lambert/Diffuse Lambert/Diffuse
– Angle between surface normal and lightAngle between surface normal and light
• Phong/Specular Phong/Specular
– Surface normal, light, and viewpointSurface normal, light, and viewpoint
Lighting ModelsLighting Models
• Ambient Ambient
– Normals don’t matterNormals don’t matter
• Lambert/Diffuse Lambert/Diffuse
– Angle between surface normal and lightAngle between surface normal and light
• Phong/Specular Phong/Specular
– Surface normal, light, and viewpointSurface normal, light, and viewpoint
Applying Illumination
We now have an illumination model for a point on We now have an illumination model for a point on a surfacea surface
Assuming that our surface is defined as a mesh of Assuming that our surface is defined as a mesh of polygonal facets, polygonal facets, which pointswhich points should we use? should we use?
Keep in mind:Keep in mind:
• It’s a fairly expensive calculationIt’s a fairly expensive calculation
• Several possible answers, each with different implications Several possible answers, each with different implications for the visual quality of the resultfor the visual quality of the result
We now have an illumination model for a point on We now have an illumination model for a point on a surfacea surface
Assuming that our surface is defined as a mesh of Assuming that our surface is defined as a mesh of polygonal facets, polygonal facets, which pointswhich points should we use? should we use?
Keep in mind:Keep in mind:
• It’s a fairly expensive calculationIt’s a fairly expensive calculation
• Several possible answers, each with different implications Several possible answers, each with different implications for the visual quality of the resultfor the visual quality of the result
Applying Illumination
With polygonal/triangular models:With polygonal/triangular models:
• Each facet has a constant surface normalEach facet has a constant surface normal
• If the light is directional, the diffuse reflectance is constant If the light is directional, the diffuse reflectance is constant across the facet. across the facet. Why?Why?
With polygonal/triangular models:With polygonal/triangular models:
• Each facet has a constant surface normalEach facet has a constant surface normal
• If the light is directional, the diffuse reflectance is constant If the light is directional, the diffuse reflectance is constant across the facet. across the facet. Why?Why?
Flat ShadingThe simplest approach, The simplest approach, flat shadingflat shading,, calculates illumination at a single point for calculates illumination at a single point for
each polygon:each polygon:
If an object really If an object really isis faceted, is this accurate? faceted, is this accurate?
The simplest approach, The simplest approach, flat shadingflat shading,, calculates illumination at a single point for calculates illumination at a single point for each polygon:each polygon:
If an object really If an object really isis faceted, is this accurate? faceted, is this accurate?
Is flat shading realistic for faceted object?
No:No:
• For point sources, the direction to light varies across the facetFor point sources, the direction to light varies across the facet
– For specular reflectance, direction to eye varies across the facet
Flat Shading
We can refine it a bit by evaluating the Phong We can refine it a bit by evaluating the Phong lighting model at each pixel of each polygon, lighting model at each pixel of each polygon, but the result is still clearly faceted:but the result is still clearly faceted:
To get smoother-looking surfacesTo get smoother-looking surfaceswe introduce we introduce vertex normalsvertex normals at each at eachvertexvertex• Usually different from facet normalUsually different from facet normal
• Used Used onlyonly for shadingfor shading
• Think of as a better approximation of theThink of as a better approximation of the realreal surface that surface that the polygons approximatethe polygons approximate
We can refine it a bit by evaluating the Phong We can refine it a bit by evaluating the Phong lighting model at each pixel of each polygon, lighting model at each pixel of each polygon, but the result is still clearly faceted:but the result is still clearly faceted:
To get smoother-looking surfacesTo get smoother-looking surfaceswe introduce we introduce vertex normalsvertex normals at each at eachvertexvertex• Usually different from facet normalUsually different from facet normal
• Used Used onlyonly for shadingfor shading
• Think of as a better approximation of theThink of as a better approximation of the realreal surface that surface that the polygons approximatethe polygons approximate
Vertex Normals
Vertex normals may be Vertex normals may be
• Provided with the modelProvided with the model
• Computed from first principles Computed from first principles
• Approximated by Approximated by averaging the normals averaging the normals of the facets that of the facets that share the vertexshare the vertex
Vertex normals may be Vertex normals may be
• Provided with the modelProvided with the model
• Computed from first principles Computed from first principles
• Approximated by Approximated by averaging the normals averaging the normals of the facets that of the facets that share the vertexshare the vertex
Gouraud Shading
This is the most common approachThis is the most common approach• Perform Phong lighting at the verticesPerform Phong lighting at the vertices
• Linearly interpolate the resulting colors over facesLinearly interpolate the resulting colors over faces
– Along edgesAlong edges
– Along scanlinesAlong scanlines
This is the most common approachThis is the most common approach• Perform Phong lighting at the verticesPerform Phong lighting at the vertices
• Linearly interpolate the resulting colors over facesLinearly interpolate the resulting colors over faces
– Along edgesAlong edges
– Along scanlinesAlong scanlinesC1
C2
C3
c1 + t1(c2-c1)
c1 + t2(c3-c1)c1 + t1(c2-c1) + t3(c1 + t2(c3-c1)- c1 + t1(c2-c1))
– This is what OpenGL does
Does this eliminate the facets?
Gouraud Shading
ArtifactsArtifacts
• Often appears dull, chalkyOften appears dull, chalky
• Lacks accurate specular componentLacks accurate specular component
– If included, will be averaged over entire polygonIf included, will be averaged over entire polygon
ArtifactsArtifacts
• Often appears dull, chalkyOften appears dull, chalky
• Lacks accurate specular componentLacks accurate specular component
– If included, will be averaged over entire polygonIf included, will be averaged over entire polygonC1
C2
C3
Can’t shade that effect!
Gouraud Shading
C1
C2
C3
Artifacts– Mach Banding
Artifact at discontinuities in intensity or intensity slope
C4
Discontinuity in rateof color change
occurs here
Phong Shading
Phong shadingPhong shading is is notnot the same as Phong lighting, the same as Phong lighting, though they are sometimes mixed upthough they are sometimes mixed up• Phong lighting:Phong lighting: the empirical model we’ve been discussing the empirical model we’ve been discussing
to calculate illumination at a point on a surfaceto calculate illumination at a point on a surface
• Phong shading:Phong shading: linearly interpolating the surface normal linearly interpolating the surface normal across the facet, applying the Phong lighting model at across the facet, applying the Phong lighting model at every pixelevery pixel
– Same input as Gouraud shadingSame input as Gouraud shading
– Usually very smooth-looking results:Usually very smooth-looking results:
– But, considerably more expensiveBut, considerably more expensive
Phong shadingPhong shading is is notnot the same as Phong lighting, the same as Phong lighting, though they are sometimes mixed upthough they are sometimes mixed up• Phong lighting:Phong lighting: the empirical model we’ve been discussing the empirical model we’ve been discussing
to calculate illumination at a point on a surfaceto calculate illumination at a point on a surface
• Phong shading:Phong shading: linearly interpolating the surface normal linearly interpolating the surface normal across the facet, applying the Phong lighting model at across the facet, applying the Phong lighting model at every pixelevery pixel
– Same input as Gouraud shadingSame input as Gouraud shading
– Usually very smooth-looking results:Usually very smooth-looking results:
– But, considerably more expensiveBut, considerably more expensive
Phong Shading
Linearly interpolate the vertex normalsLinearly interpolate the vertex normals
• Compute lighting equations at each pixelCompute lighting equations at each pixel
• Can use specular componentCan use specular component
Linearly interpolate the vertex normalsLinearly interpolate the vertex normals
• Compute lighting equations at each pixelCompute lighting equations at each pixel
• Can use specular componentCan use specular componentN1
N2
N3
N4
lights
i
n
isidiambientatotal
shinyRVkLNkIIkI
#
1
ˆˆˆˆ
Remember: Normals used in diffuse and specular terms
Discontinuity in normal’s rate of change is harder to detect
Shortcomings of Shading
Polygonal silhouettes remainPolygonal silhouettes remainPolygonal silhouettes remainPolygonal silhouettes remain
Gouraud Phong
Perspective Distortion
Z – into the scene
Imageplane
Notice that linear interpolation in screen spacedoes not align with linear interpolation in world space
Break up large polygonswith many smaller ones
Perspective Distortion
Notice that linear interpolation in screen spacedoes not align with linear interpolation in world space
Z – into the scene
Imageplane Break up large polygons
with many smaller ones
Interpolation dependent on polygon orientation
A
D
C
B
Interpolate betweenAB and AD
B
A
D
C
Interpolate betweenCD and AD
Rotate -90o
and colorsame point
Problems at Shared Vertices
B
A
C
Vertex B is shared by the two rectangles on the right, but not by the one on the left
E
D
F
H
GThe first portion of the scanlineis interpolated between DE and AC
The second portion of the scanlineis interpolated between BC and GH
A large discontinuity could arise
Bad Vertex Averaging
Shading Models (Direct lighting)
Flat ShadingFlat Shading
• Compute Phong lighting once for entire polygonCompute Phong lighting once for entire polygon
Gouraud ShadingGouraud Shading
• Compute Phong lighting at the vertices and interpolate lighting values Compute Phong lighting at the vertices and interpolate lighting values across polygonacross polygon
Phong ShadingPhong Shading
• Compute averaged vertex normalsCompute averaged vertex normals
• Interpolate normals across polygon and perform Phong lighting across Interpolate normals across polygon and perform Phong lighting across polygonpolygon
Flat ShadingFlat Shading
• Compute Phong lighting once for entire polygonCompute Phong lighting once for entire polygon
Gouraud ShadingGouraud Shading
• Compute Phong lighting at the vertices and interpolate lighting values Compute Phong lighting at the vertices and interpolate lighting values across polygonacross polygon
Phong ShadingPhong Shading
• Compute averaged vertex normalsCompute averaged vertex normals
• Interpolate normals across polygon and perform Phong lighting across Interpolate normals across polygon and perform Phong lighting across polygonpolygon
Global Illumination
We’ve glossed over how light really worksWe’ve glossed over how light really works
And we will continue to do so…And we will continue to do so…
One step betterOne step better
Global IlluminationGlobal Illumination
• The notion that a point is illuminated by more than light from local The notion that a point is illuminated by more than light from local lights; it is illuminated by all the emitters and reflectors in the lights; it is illuminated by all the emitters and reflectors in the global sceneglobal scene
We’ve glossed over how light really worksWe’ve glossed over how light really works
And we will continue to do so…And we will continue to do so…
One step betterOne step better
Global IlluminationGlobal Illumination
• The notion that a point is illuminated by more than light from local The notion that a point is illuminated by more than light from local lights; it is illuminated by all the emitters and reflectors in the lights; it is illuminated by all the emitters and reflectors in the global sceneglobal scene
The ‘Rendering Equation’Jim Kajiya (Current head of Microsoft Research) developed this in Jim Kajiya (Current head of Microsoft Research) developed this in
19861986
I(x, x’) is the total intensity from point x’ to xI(x, x’) is the total intensity from point x’ to x
g(x, x’) = 0 when x/x’ are occluded and 1/dg(x, x’) = 0 when x/x’ are occluded and 1/d22 otherwise (d = distance otherwise (d = distance between x and x’)between x and x’)
(x, x’) is the intensity emitted by x’ to x(x, x’) is the intensity emitted by x’ to x
(x, x’,x’’) is the intensity of light reflected from x’’ to x through x’(x, x’,x’’) is the intensity of light reflected from x’’ to x through x’
S is all points on all surfacesS is all points on all surfaces
Jim Kajiya (Current head of Microsoft Research) developed this in Jim Kajiya (Current head of Microsoft Research) developed this in 19861986
I(x, x’) is the total intensity from point x’ to xI(x, x’) is the total intensity from point x’ to x
g(x, x’) = 0 when x/x’ are occluded and 1/dg(x, x’) = 0 when x/x’ are occluded and 1/d22 otherwise (d = distance otherwise (d = distance between x and x’)between x and x’)
(x, x’) is the intensity emitted by x’ to x(x, x’) is the intensity emitted by x’ to x
(x, x’,x’’) is the intensity of light reflected from x’’ to x through x’(x, x’,x’’) is the intensity of light reflected from x’’ to x through x’
S is all points on all surfacesS is all points on all surfaces
S
dxxxIxxxxxxxgxxI '''',''',',',',',
The ‘Rendering Equation’
The light that hits x from x’ is the direct The light that hits x from x’ is the direct illumination from x’ and all the light reflected by illumination from x’ and all the light reflected by x’ from all x’’x’ from all x’’
To implement:To implement:
• Must handle recursion effectivelyMust handle recursion effectively
• Must support diffuse and specular lightMust support diffuse and specular light
• Must model object shadowingMust model object shadowing
The light that hits x from x’ is the direct The light that hits x from x’ is the direct illumination from x’ and all the light reflected by illumination from x’ and all the light reflected by x’ from all x’’x’ from all x’’
To implement:To implement:
• Must handle recursion effectivelyMust handle recursion effectively
• Must support diffuse and specular lightMust support diffuse and specular light
• Must model object shadowingMust model object shadowing
Shading Models (Indirect lighting)
Ray Tracing RadiosityRay Tracing RadiosityRay Tracing RadiosityRay Tracing Radiosity
Recursive Ray Tracing
Cast a ray from the Cast a ray from the viewer’s eye through viewer’s eye through each pixeleach pixel
Compute intersection of Compute intersection of this ray with objects this ray with objects from scenefrom scene
Closest intersecting Closest intersecting object determines colorobject determines color
Cast a ray from the Cast a ray from the viewer’s eye through viewer’s eye through each pixeleach pixel
Compute intersection of Compute intersection of this ray with objects this ray with objects from scenefrom scene
Closest intersecting Closest intersecting object determines colorobject determines color
Recursive Ray TracingCast a ray from intersected object to Cast a ray from intersected object to
light sources and determine light sources and determine shadow/lighting conditionsshadow/lighting conditions
Also spawn secondary raysAlso spawn secondary rays
• Reflection rays and refraction raysReflection rays and refraction rays
• Use surface normal as guide (angle of Use surface normal as guide (angle of incidence equals angle of reflection)incidence equals angle of reflection)
• If another object is hit, determine the light it If another object is hit, determine the light it illuminates by recursing through ray tracingilluminates by recursing through ray tracing
Cast a ray from intersected object to Cast a ray from intersected object to light sources and determine light sources and determine shadow/lighting conditionsshadow/lighting conditions
Also spawn secondary raysAlso spawn secondary rays
• Reflection rays and refraction raysReflection rays and refraction rays
• Use surface normal as guide (angle of Use surface normal as guide (angle of incidence equals angle of reflection)incidence equals angle of reflection)
• If another object is hit, determine the light it If another object is hit, determine the light it illuminates by recursing through ray tracingilluminates by recursing through ray tracing
Recursive Ray Tracing
Stop recursing when:Stop recursing when:
• ray fails to intersect an objectray fails to intersect an object
• user-specified maximum depth is reacheduser-specified maximum depth is reached
• system runs out of memorysystem runs out of memory
Common numerical accuracy errorCommon numerical accuracy error
• Spawn secondary ray from intersection pointSpawn secondary ray from intersection point
• Secondary ray intersects another polygon on same objectSecondary ray intersects another polygon on same object
Stop recursing when:Stop recursing when:
• ray fails to intersect an objectray fails to intersect an object
• user-specified maximum depth is reacheduser-specified maximum depth is reached
• system runs out of memorysystem runs out of memory
Common numerical accuracy errorCommon numerical accuracy error
• Spawn secondary ray from intersection pointSpawn secondary ray from intersection point
• Secondary ray intersects another polygon on same objectSecondary ray intersects another polygon on same object
Recursive Ray Tracing
Still producing PhD’s after all these yearsStill producing PhD’s after all these years
Many opportunities to improve efficiency and Many opportunities to improve efficiency and accuracy of ray tracingaccuracy of ray tracing
• Reduce the number of rays castReduce the number of rays cast
• Accurately capture shadows caused by non-lights (ray Accurately capture shadows caused by non-lights (ray tracing from the light source)tracing from the light source)
• Expensive to recompute as eyepoint changesExpensive to recompute as eyepoint changes
Still producing PhD’s after all these yearsStill producing PhD’s after all these years
Many opportunities to improve efficiency and Many opportunities to improve efficiency and accuracy of ray tracingaccuracy of ray tracing
• Reduce the number of rays castReduce the number of rays cast
• Accurately capture shadows caused by non-lights (ray Accurately capture shadows caused by non-lights (ray tracing from the light source)tracing from the light source)
• Expensive to recompute as eyepoint changesExpensive to recompute as eyepoint changes
Image Synthesis Class
Prof. Humphreys is looking for studentsProf. Humphreys is looking for students
Modeled after Stanford course (let’s beat ‘em)Modeled after Stanford course (let’s beat ‘em)• See: http://graphics.stanford.edu/courses/cs348b-competition/See: http://graphics.stanford.edu/courses/cs348b-competition/
Prof. Humphreys is looking for studentsProf. Humphreys is looking for students
Modeled after Stanford course (let’s beat ‘em)Modeled after Stanford course (let’s beat ‘em)• See: http://graphics.stanford.edu/courses/cs348b-competition/See: http://graphics.stanford.edu/courses/cs348b-competition/
Radiosity
Ray tracing models specular Ray tracing models specular reflection and refractive transparency, but reflection and refractive transparency, but still uses an ambient term to account for still uses an ambient term to account for other lighting effectsother lighting effects
Radiosity is the rate at which energy is Radiosity is the rate at which energy is emitted or reflected by a surfaceemitted or reflected by a surface
By conserving light energy in a volume, By conserving light energy in a volume, these radiosity effects can be tracedthese radiosity effects can be traced
Ray tracing models specular Ray tracing models specular reflection and refractive transparency, but reflection and refractive transparency, but still uses an ambient term to account for still uses an ambient term to account for other lighting effectsother lighting effects
Radiosity is the rate at which energy is Radiosity is the rate at which energy is emitted or reflected by a surfaceemitted or reflected by a surface
By conserving light energy in a volume, By conserving light energy in a volume, these radiosity effects can be tracedthese radiosity effects can be traced