1 / 26

CS 445 / 645 Introduction to Computer Graphics

CS 445 / 645 Introduction to Computer Graphics. Lecture 18 Shading. Ray Tracing Assignment. Deadline extended until Tuesday the 13th. Ray Tracing Assignment. Barycentric coordinates (M ö bius, 1827) Consider a triangle defined by (A 1 , A 2 , A 3 )

maleah
Download Presentation

CS 445 / 645 Introduction to Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 445 / 645Introduction to Computer Graphics Lecture 18 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 (A1, A2, A3) • 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 (t1, t2, t3) corresponding to its position with respect to A1, A2, A3.

  4. Barycentric Coordinates • Solve for (t1, t2, t3) such that • t1 + t2 + t3 = 1 • t1A1 + t2A2 + t3A3 = P mathworld.com

  5. Barycentric Coordinates • An observation • t1, t2, and t3 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 • t1, t2, and t3 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 • || (A2 - A1) x (A3-A1) || = (area of A1A2A3)* 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 • A1, A2, and A3 form an affine space • If 0 ≤ t1, t2, t3 ≤ 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 pointsshould we use? • Keep in mind: • It’s a fairly expensive calculation • Several 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 normal • 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?

  11. For specular reflectance, direction to eye varies across the facet Is flat shading realistic for faceted object? • No: • For point sources, the direction to light 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 surfaceswe introduce vertex normals at eachvertex • Usually different from facet normal • Used onlyfor shading • Think of as a better approximation of therealsurface that the polygons approximate

  14. Vertex Normals • Vertex normals may be • Provided with the model • Computed from first principles • Approximated 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 vertices • Linearly interpolate the resulting colors over faces • Along edges • Along scanlines c1 + t1(c2-c1) C1 • This is what OpenGL does • Does this eliminate the facets? C3 C2 c1 + t1(c2-c1) + t3(c1 + t2(c3-c1)- c1 + t1(c2-c1)) c1 + t2(c3-c1)

  16. C1 C3 C2 Can’t shade that effect! Gouraud Shading • Artifacts • Often appears dull, chalky • Lacks accurate specular component • If included, will be averaged over entire polygon

  17. Gouraud Shading • Artifacts • Mach Banding • Artifact at discontinuities in intensity or intensity slope C1 C4 C3 C2 Discontinuity in rateof color changeoccurs 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 surface • Phong 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 pixel • Can use specular component N1 N4 Remember: Normals used in diffuse and specular terms Discontinuity in normal’s rate of change is harder to detect N3 N2

  20. Shortcomings of Shading • Polygonal silhouettes remain Gouraud Phong

  21. i i i i i i Perspective Distortion Linear interpolationin image space isnot accuratesampling of 3Dspace Imageplane Break up large polygonswith many smaller ones Polygon u u u u u u Z – into the scene Notice that linear interpolation in screen spacedoes not align with linear interpolation in world space Nonlinear color shift fromblue (left) to red (right)

  22. Perspective Distortion Imageplane Break up large polygonswith many smaller ones Z – into the scene Notice that linear interpolation in screen spacedoes not align with linear interpolation in world space

  23. A B i i C B A D D C Interpolate betweenCD and AD Interpolate betweenAB and AD Interpolation dependent on polygon orientation Rotate -90oand colorsame point

  24. Problems at Shared Vertices Vertex B is shared by the two rectangles on the right, but not by the one on the left C H D The first portion of the scanlineis interpolated between DE and ACThe second portion of the scanlineis interpolated between BC and GHA large discontinuity could arise B G F E A

  25. Bad Vertex Averaging

  26. Shading Models (Direct lighting) • Flat Shading • Compute Phong lighting once for entire polygon • Gouraud Shading • Compute Phong lighting at the vertices and interpolate lighting values across polygon • Phong Shading • Interpolate normals across polygon and perform Phong lighting across polygon

More Related