Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 Ray Tracing Assignment Deadline extended until Tuesday the 13th

3 Ray Tracing Assignment Barycentric coordinates (Möbius, 1827) Consider a triangle defined by (A 1, A 2, A 3 )Consider a triangle defined by (A 1, A 2, A 3 ) –These points are defined relative to world origin –A point within triangle could also be defined as (x, y, z) relative to world origin A point can be defined as (t 1, t 2, t 3 ) corresponding to its position with respect to A 1, A 2, A 3.A point can be defined as (t 1, t 2, t 3 ) corresponding to its position with respect to A 1, A 2, A 3. Barycentric coordinates (Möbius, 1827) Consider a triangle defined by (A 1, A 2, A 3 )Consider a triangle defined by (A 1, A 2, A 3 ) –These points are defined relative to world origin –A point within triangle could also be defined as (x, y, z) relative to world origin A point can be defined as (t 1, t 2, t 3 ) corresponding to its position with respect to A 1, A 2, A 3.A point can be defined as (t 1, t 2, t 3 ) corresponding to its position with respect to A 1, A 2, A 3.

4 Barycentric Coordinates Solve for (t 1, t 2, t 3 ) such that –t 1 + t 2 + t 3 = 1 –t 1 A 1 + t 2 A 2 + t 3 A 3 = P Solve for (t 1, t 2, t 3 ) such that –t 1 + t 2 + t 3 = 1 –t 1 A 1 + t 2 A 2 + t 3 A 3 = P mathworld.com

5 Barycentric Coordinates An observation t 1, t 2, and t 3 are weights such that when they are used to represent the mass at the vertices of the triangle, P is at its center of masst 1, t 2, and t 3 are weights such that when they are used to represent the mass at the vertices of the triangle, P is at its center of mass t 1, t 2, and t 3 are weights that represent the ratio of the area of each of the three subtriangles to the area of the wholet 1, t 2, and t 3 are weights that represent the ratio of the area of each of the three subtriangles to the area of the whole An observation t 1, t 2, and t 3 are weights such that when they are used to represent the mass at the vertices of the triangle, P is at its center of masst 1, t 2, and t 3 are weights such that when they are used to represent the mass at the vertices of the triangle, P is at its center of mass t 1, t 2, and t 3 are weights that represent the ratio of the area of each of the three subtriangles to the area of the wholet 1, t 2, and t 3 are weights that represent the ratio of the area of each of the three subtriangles to the area of the whole

6 Barycentric coordinates The cross product computes a triangle’s area || (A 2 - A 1 ) x (A 3 -A 1 ) || = (area of A 1 A 2 A 3 ) * 2|| (A 2 - A 1 ) x (A 3 -A 1 ) || = (area of A 1 A 2 A 3 ) * 2 Where || x || = the area of the triangle x… the cross product The cross product computes a triangle’s area || (A 2 - A 1 ) x (A 3 -A 1 ) || = (area of A 1 A 2 A 3 ) * 2|| (A 2 - A 1 ) x (A 3 -A 1 ) || = (area of A 1 A 2 A 3 ) * 2 Where || x || = the area of the triangle x… the cross product

7 Barycentric Coordinates All points of triangle are unique, all points in space can be represented with barycentric coordinates A 1, A 2, and A 3 form an affine spaceA 1, A 2, and A 3 form an affine space If 0 ≤ t 1, t 2, t 3 ≤ 1, the point is in the triangleIf 0 ≤ t 1, t 2, t 3 ≤ 1, the point is in the triangle All points of triangle are unique, all points in space can be represented with barycentric coordinates A 1, A 2, and A 3 form an affine spaceA 1, A 2, and A 3 form an affine space If 0 ≤ t 1, t 2, t 3 ≤ 1, the point is in the triangleIf 0 ≤ t 1, t 2, t 3 ≤ 1, the point is in the triangle

8 Applying Illumination We 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 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

9 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?

10 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?

11 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

12 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:

13 Vertex Normals 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 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

14 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

15 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?

16 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!

17 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 http://www.edcenter.sdsu.edu/slides/GA/visteacher/sld048.htm

18 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

19 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

20 Shortcomings of Shading Polygonal silhouettes remain Gouraud Phong

21 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 Nonlinear color shift from blue (left) to red (right) Linear interpolation in image space is not accurate sampling of 3D space Polygon

22 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

23 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

24 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

25 Bad Vertex Averaging

26 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 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 Interpolate normals across polygon and perform Phong lighting across polygonInterpolate normals across polygon and perform Phong lighting across polygon


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

Similar presentations


Ads by Google