Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading.

Similar presentations


Presentation on theme: "CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading."— Presentation transcript:

1 CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading

2 Lighting Review Lighting Models AmbientAmbient –Normals don’t matter Lambert/DiffuseLambert/Diffuse –Angle between surface normal and light Phong/SpecularPhong/Specular –Surface normal, light, and viewpoint Lighting Models AmbientAmbient –Normals don’t matter Lambert/DiffuseLambert/Diffuse –Angle between surface normal and light Phong/SpecularPhong/Specular –Surface normal, light, and viewpoint

3 Applying Illumination We now have an illumination model for a point on a surface Assuming that our surface is defined as a mesh of polygonal facets, which points should we use? Keep in mind: It’s a fairly expensive calculationIt’s a fairly expensive calculation Several possible answers, each with different implications for the visual quality of the resultSeveral possible answers, each with different implications for the visual quality of the result We now have an illumination model for a point on a surface Assuming that our surface is defined as a mesh of polygonal facets, which points should we use? Keep in mind: It’s a fairly expensive calculationIt’s a fairly expensive calculation Several possible answers, each with different implications for the visual quality of the resultSeveral possible answers, each with different implications for the visual quality of the result

4 Applying Illumination 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 across the facet. Why?If the light is directional, the diffuse reflectance is constant across the facet. Why? 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 across the facet. Why?If the light is directional, the diffuse reflectance is constant across the facet. Why?

5 Flat Shading The simplest approach, flat shading, calculates illumination at a single point for each polygon: If an object really is faceted, is this accurate? The simplest approach, flat shading, calculates illumination at a single point for each polygon: If an object really is faceted, is this accurate?

6 Is flat shading realistic for faceted object? No: For point sources, the direction to light varies across the facetFor point sources, the direction to light varies across the facetNo: – For specular reflectance, direction to eye varies across the facet

7 Flat Shading We can refine it a bit by evaluating the Phong lighting model at each pixel of each polygon, but the result is still clearly faceted: To get smoother-looking surfaces we introduce vertex normals at each vertex Usually different from facet normalUsually different from facet normal Used only for shadingUsed only for shading Think of as a better approximation of the real surface that the polygons approximateThink of as a better approximation of the real surface that the polygons approximate We can refine it a bit by evaluating the Phong lighting model at each pixel of each polygon, but the result is still clearly faceted: To get smoother-looking surfaces we introduce vertex normals at each vertex Usually different from facet normalUsually different from facet normal Used only for shadingUsed only for shading Think of as a better approximation of the real surface that the polygons approximateThink of as a better approximation of the real surface that the polygons approximate

8 Vertex Normals Vertex normals may be Provided with the modelProvided with the model Computed from first principlesComputed from first principles Approximated by averaging the normals of the facets that share the vertexApproximated by averaging the normals of the facets that share the vertex Vertex normals may be Provided with the modelProvided with the model Computed from first principlesComputed from first principles Approximated by averaging the normals of the facets that share the vertexApproximated by averaging the normals of the facets that share the vertex

9 Gouraud Shading This 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 edges –Along scanlines This 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 edges –Along scanlines C1C1 C2C2 C3C3 c 1 + t 1 (c 2 -c 1 ) c 1 + t 2 (c 3 -c 1 ) c 1 + t 1 (c 2 -c 1 ) + t 3 (c 1 + t 2 (c 3 -c 1 )- c 1 + t 1 (c 2 -c 1 )) –This is what OpenGL does l Does this eliminate the facets?

10 Gouraud Shading Artifacts Often appears dull, chalkyOften appears dull, chalky Lacks accurate specular componentLacks accurate specular component –If included, will be averaged over entire polygon Artifacts Often appears dull, chalkyOften appears dull, chalky Lacks accurate specular componentLacks accurate specular component –If included, will be averaged over entire polygon C1C1 C2C2 C3C3 Can’t shade that effect!

11 Gouraud Shading C1C1 C2C2 C3C3 l Artifacts –Mach Banding n Artifact at discontinuities in intensity or intensity slope C4C4 Discontinuity in rate of color change occurs here

12 Phong Shading Phong shading is not the same as Phong lighting, though they are sometimes mixed up Phong lighting: the empirical model we’ve been discussing to calculate illumination at a point on a surfacePhong lighting: the empirical model we’ve been discussing to calculate illumination at a point on a surface Phong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixelPhong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixel –Same input as Gouraud shading –Usually very smooth-looking results: –But, considerably more expensive Phong shading is not the same as Phong lighting, though they are sometimes mixed up Phong lighting: the empirical model we’ve been discussing to calculate illumination at a point on a surfacePhong lighting: the empirical model we’ve been discussing to calculate illumination at a point on a surface Phong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixelPhong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixel –Same input as Gouraud shading –Usually very smooth-looking results: –But, considerably more expensive

13 Phong Shading Linearly 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 normals Compute lighting equations at each pixelCompute lighting equations at each pixel Can use specular componentCan use specular component N1N1 N2N2 N3N3 N4N4 Remember: Normals used in diffuse and specular terms Discontinuity in normal’s rate of change is harder to detect

14 Shortcomings of Shading Polygonal silhouettes remain Gouraud Phong

15 Perspective Distortion         Z – into the scene Image plane Notice that linear interpolation in screen space does not align with linear interpolation in world space Break up large polygons with many smaller ones

16 Perspective Distortion Notice that linear interpolation in screen space does not align with linear interpolation in world space Z – into the scene Image plane Break up large polygons with many smaller ones

17 Interpolation dependent on polygon orientation  A D C B Interpolate between AB and AD  B A D C Interpolate between CD and AD Rotate -90 o and color same point

18 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 G The first portion of the scanline is interpolated between DE and AC The second portion of the scanline is interpolated between BC and GH A large discontinuity could arise

19 Bad Vertex Averaging

20 Shading Models (Direct lighting) Flat Shading Compute Phong lighting once for entire polygonCompute Phong lighting once for entire polygon Gouraud Shading Compute Phong lighting at the vertices and interpolate lighting values across polygonCompute Phong lighting at the vertices and interpolate lighting values across polygon Phong Shading Compute averaged vertex normalsCompute averaged vertex normals Interpolate normals across polygon and perform Phong lighting across polygonInterpolate normals across polygon and perform Phong lighting across polygon Flat Shading Compute Phong lighting once for entire polygonCompute Phong lighting once for entire polygon Gouraud Shading Compute Phong lighting at the vertices and interpolate lighting values across polygonCompute Phong lighting at the vertices and interpolate lighting values across polygon Phong Shading Compute averaged vertex normalsCompute averaged vertex normals Interpolate normals across polygon and perform Phong lighting across polygonInterpolate normals across polygon and perform Phong lighting across polygon

21 Global Illumination We’ve glossed over how light really works And we will continue to do so… One step better Global Illumination 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 global sceneThe notion that a point is illuminated by more than light from local lights; it is illuminated by all the emitters and reflectors in the global scene We’ve glossed over how light really works And we will continue to do so… One step better Global Illumination 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 global sceneThe notion that a point is illuminated by more than light from local lights; it is illuminated by all the emitters and reflectors in the global scene

22 The ‘Rendering Equation’ Jim Kajiya (Current head of Microsoft Research) developed this in 1986 I(x, x’) is the total intensity from point x’ to x g(x, x’) = 0 when x/x’ are occluded and 1/d 2 otherwise (d = distance between x and 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’ S is all points on all surfaces Jim Kajiya (Current head of Microsoft Research) developed this in 1986 I(x, x’) is the total intensity from point x’ to x g(x, x’) = 0 when x/x’ are occluded and 1/d 2 otherwise (d = distance between x and 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’ S is all points on all surfaces

23 The ‘Rendering Equation’ The light that hits x from x’ is the direct illumination from x’ and all the light reflected by x’ from all x’’ 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 illumination from x’ and all the light reflected by x’ from all x’’ 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

24 Shading Models (Indirect lighting) Ray Tracing Radiosity

25 Recursive Ray Tracing Cast a ray from the viewer’s eye through each pixel Compute intersection of this ray with objects from scene Closest intersecting object determines color Cast a ray from the viewer’s eye through each pixel Compute intersection of this ray with objects from scene Closest intersecting object determines color

26 Recursive Ray Tracing Cast a ray from intersected object to light sources and determine shadow/lighting conditions Also spawn secondary rays Reflection rays and refraction raysReflection rays and refraction rays Use surface normal as guide (angle of incidence equals angle of reflection)Use surface normal as guide (angle of incidence equals angle of reflection) If another object is hit, determine the light it illuminates by recursing through ray tracingIf another object is hit, determine the light it illuminates by recursing through ray tracing Cast a ray from intersected object to light sources and determine shadow/lighting conditions Also spawn secondary rays Reflection rays and refraction raysReflection rays and refraction rays Use surface normal as guide (angle of incidence equals angle of reflection)Use surface normal as guide (angle of incidence equals angle of reflection) If another object is hit, determine the light it illuminates by recursing through ray tracingIf another object is hit, determine the light it illuminates by recursing through ray tracing

27 Recursive Ray Tracing 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 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: 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 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

28 Recursive Ray Tracing Still producing PhD’s after all these years Many opportunities to improve efficiency and accuracy of ray tracing Reduce the number of rays castReduce the number of rays cast Accurately capture shadows caused by non-lights (ray tracing from the light source)Accurately capture shadows caused by non-lights (ray tracing from the light source) Expensive to recompute as eyepoint changesExpensive to recompute as eyepoint changes Still producing PhD’s after all these years Many opportunities to improve efficiency and accuracy of ray tracing Reduce the number of rays castReduce the number of rays cast Accurately capture shadows caused by non-lights (ray tracing from the light source)Accurately capture shadows caused by non-lights (ray tracing from the light source) Expensive to recompute as eyepoint changesExpensive to recompute as eyepoint changes

29 Image Synthesis Class Prof. Humphreys is looking for students 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 students Modeled after Stanford course (let’s beat ‘em) See: http://graphics.stanford.edu/courses/cs348b-competition/See: http://graphics.stanford.edu/courses/cs348b-competition/

30 Radiosity Ray tracing models specular reflection and refractive transparency, but still uses an ambient term to account for other lighting effects Radiosity is the rate at which energy is emitted or reflected by a surface By conserving light energy in a volume, these radiosity effects can be traced Ray tracing models specular reflection and refractive transparency, but still uses an ambient term to account for other lighting effects Radiosity is the rate at which energy is emitted or reflected by a surface By conserving light energy in a volume, these radiosity effects can be traced


Download ppt "CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading."

Similar presentations


Ads by Google