Successfully reported this slideshow.
Upcoming SlideShare
×

2,678 views

Published on

Published in: Science
• Full Name
Comment goes here.

Are you sure you want to Yes No
• I wouldn't have suffered three years of gout misery if I'd known that... Thousands of people are now gout-free simply from eating foods found in their local supermarket - now I'm one of them! No meds, doctors or procedures - three years of pain gone in weeks. ●●● http://t.cn/A67Do9lh

Are you sure you want to  Yes  No

1. 1. February 5, 2015 1comp_dep_educ@yahoo.com University of Kufa
2. 2. February 5, 2015 2 Why we need shading  Suppose we build a model of a sphere using many polygons and color it. We get something like  But we want comp_dep_educ@yahoo.com
3. 3. February 5, 2015 3 Shading refers to the application of a reflection model over the surface of an object. To use the lighting and reﬂectance model to shade facets of a polygonal mesh — that is, to assign intensities to pixels to give the impression of opaque surfaces rather than wireframes. Shading is a way to paint the object with light What is Shading comp_dep_educ@yahoo.com
4. 4. February 5, 2015 4 In creating and interpreting images, we need to understand two things: • Geometry –Where scene points appear in the image (image locations) • Radiometry –How “bright” they are (image Computer Graphics values) Geometric enables us to know something about the scene location of a point imaged at pixel (u, v) Radiometric enables us to know what a pixel value implies about surface lightness and illumination Geometry and Radiometry comp_dep_educ@yahoo.com
5. 5. February 5, 2015 5 • For “matte” objects with no shininess • Diffuse/matte objects are called Lambertian • In general, shading does not vary with viewpoint ƒExample: a piece of paper • Reflected light is scattered equally in all directions Diffuse Objects comp_dep_educ@yahoo.com
6. 6. February 5, 2015 6 Lambertian Surface Obeys Lambert’s Law (from physics): The color, c, of a surface is proportional to the cosine of the angle between the surface normal and the direction of the light source Lambertian Surface comp_dep_educ@yahoo.com
7. 7. February 5, 2015 7 Lambertian Surface comp_dep_educ@yahoo.com
8. 8. February 5, 2015 comp_dep_educ@yahoo.com 8 Diffuse Lighting Model
9. 9. February 5, 2015 comp_dep_educ@yahoo.com 9 Ambient Term
10. 10. February 5, 2015 10 • Want to add highlights for shiny surfaces • Highlight moves with eye location Phong Illumination comp_dep_educ@yahoo.com
11. 11. February 5, 2015 11 • The exponent p controls the “sharpness” of the highlight: larger p produces sharper highlight Phong Exponent  Values of p between 100 and 200 correspond to metals  Values between 5 and 10 give surface that look like plastic The Shininess Coefficient comp_dep_educ@yahoo.com
12. 12. February 5, 2015 12 Phong Illumination: Computing r • How can we compute the reflection vector r? comp_dep_educ@yahoo.com
13. 13. February 5, 2015 comp_dep_educ@yahoo.com 13
14. 14. February 5, 2015 comp_dep_educ@yahoo.com 14
15. 15. February 5, 2015 15 Complete Illumination Equation • The complete illumination equations models: ƒ • Ambient light ƒ • Diffuse reflections ƒ • Specular reflections comp_dep_educ@yahoo.com
16. 16. February 5, 2015 comp_dep_educ@yahoo.com 16 Shadows & Multiple Lights
17. 17. February 5, 2015 17 • Illumination of a point on a surface: • Technical detail: clamp all colors at 1 • Illumination of an entire surface = SHADING! ƒ • Very expensive to compute at every visible point. We have 3 typical options - Per polygon (Flat shading): entire polygon gets same color - Per vertex (Gourad Shading): compute illumination at each vertex and interpolate vertex colors - Per pixel (Phong Shading): interpolate vertex normals and compute illumination for each pixel Illumination vs. Shading comp_dep_educ@yahoo.com
18. 18. February 5, 2015 comp_dep_educ@yahoo.com 18
19. 19. February 5, 2015 19 One illumination calculation per polygon, assign all pixels inside each polygon the same color Flat shading comp_dep_educ@yahoo.com
20. 20. February 5, 2015 20 The simplest shading algorithm, called flat shading, consists of using an illumination model to determine the corresponding intensity value for the incident light, then shade the entire polygon according to this value. Flat shading is also known as constant shading or constant intensity shading. Its main advantage is that it is easy it implement. Flat shading produces satisfactory results under the following conditions: 1. The subject is illuminated by ambient light and there are no surface textures or shadows. 2. In the case of curved objects, when the surface changes gradually and the light source and viewer are far from the surface. 3. In general, when there are large numbers of plane surfaces. Figure shows three cases of flat shading of a conical surface. The more polygons, the better the rendering. With ﬂat shading, each triangle of a mesh is ﬁlled with a single color. Flat Shading comp_dep_educ@yahoo.com
21. 21. February 5, 2015 21 • each entire polygon is drawn with the same color. • need to know one normal for the entire polygon. • fast . • lighting equation used once per polygon. Flat shading Given a single normal to the plane the lighting equations and the material properties are used to generate a single color. The polygon is filled with that color. comp_dep_educ@yahoo.com
22. 22. February 5, 2015 22comp_dep_educ@yahoo.com Flat Shading
23. 23. February 5, 2015 23comp_dep_educ@yahoo.com Flat Shading
24. 24. February 5, 2015 24 Flat Shading comp_dep_educ@yahoo.com
25. 25. February 5, 2015 25 The major limitation of flat shading is that each polygon is rendered in a single color. Very often the only way of improving the rendering is by increasing the number of polygons, as shown in the previous Figure. An alternative scheme is based on using more than one shade in each polygon, which is accomplished by interpolating the values calculated for the vertices to the polygon's interior points. This type of manipulation, called interpolative or incremental shading, under some circumstances is capable of producing a more satisfactory shade rendering with a smaller number of polygons. Two incremental shading methods, called Gouraud and Phong shading, are almost in 3D rendering software. Interpolative (incremental) Shading comp_dep_educ@yahoo.com
26. 26. February 5, 2015 26 This shading algorithm was first described by H. Gouraud in 1971. It is also called bilinear intensity interpolation. Gouraud shading is easier to understand in the context of the scan-line algorithm used in hidden surface removal, For now, assume that each pixel is examined according to its horizontal (scan-line) placement, usually left to right. Following figure shows a triangular polygon with vertices at A, B, and C. Gouraud Shading comp_dep_educ@yahoo.com
27. 27. February 5, 2015 comp_dep_educ@yahoo.com 27 Gouraud Shading
28. 28. February 5, 2015 comp_dep_educ@yahoo.com 28 Gouraud Shading
29. 29. February 5, 2015 29 Gouraud Shading comp_dep_educ@yahoo.com
30. 30. February 5, 2015 30 The intensity value at each of these vertices is based on the reflection model. As scan-line processing proceeds, the intensity of pixel p1 is determined by interpolating the intensities at vertices A and B, according to the formula In the next slide, the intensity of p1 is closer to the intensity of vertex A than that of vertex B. The intensity of p2 is determined similarly, by interpolating the intensities of vertices A and C. Gouraud Shading comp_dep_educ@yahoo.com
31. 31. February 5, 2015 31 To find the intensity of Ip, we need to know the intensity of Ia and Ib. To find the intensity of Ia we need to know the intensity of I1 and I2. To find the intensity of Ib we need to know the intensity of I1 and I3. Ia = (Ys - Y2) / (Y1 - Y2) * I1 + (Y1 - Ys) / (Y1 - Y2) * I2 Ib = (Ys - Y3) / (Y1 - Y3) * I1 + (Y1 - Ys) / (Y1 - Y3) * I3 Ip = (Xb - Xp) / (Xb - Xa) * Ia + (Xp - Xa) / (Xb - Xa) * Ib Whether we are interpolating normal's or colors the procedure is the same: The process is continued for each pixel in the polygon, and for each polygon in the scene. Gouraud Shading comp_dep_educ@yahoo.com
32. 32. February 5, 2015 32 Gouraud shading also has limitations. • One of the most important ones is the loss of highlights on surfaces and highlights that are displayed with unusual shapes. Following figure shows a polygon with an interior highlight. Since Gouraud shading is based on the intensity of the pixels located at the polygon edges, this highlight is missed. In this case pixel p3 is rendered by interpolating the values of p1 and p2, which produces a darker color than the one required. • Another error associated with Gouraud shading is the appearance of bright or dark streaks, called Mach bands. Gouraud shading comp_dep_educ@yahoo.com
33. 33. February 5, 2015 33 • colors are interpolated across the polygon. • need to know a normal for each vertex of the polygon. • slower than flat shading. • lighting equation used at each vertex. Gouraud Shading Given a normal at each vertex of the polygon, the color at each vertex is determined from the lighting equations and the material properties. Linear interpolation of the color values at each vertex are used to generate color values for each pixel on the edges. Linear interpolation across each scan line is used to then fill in the color of the polygon. Gouraud Shading Properties comp_dep_educ@yahoo.com
34. 34. February 5, 2015 34 - The intensity value is calculated once for each vertex of a polygon. - The intensity values for the inside of the polygon are obtained by interpolating the vertex values. - Eliminates the intensity discontinuity problem. - Still not model the specular reflection correctly. - The interpolation of color values can cause bright or dark intensity streaks, called the Mach- bands, to appear on the surface. Gouraud Shading comp_dep_educ@yahoo.com
35. 35. February 5, 2015 35 Gouraud Shading Limitations - Mach Bands  The rate of change of pixel intensity is even across any polygon, but changes as boundaries are crossed  This ‘discontinuity’ is accentuated by the human visual system, so that we see either light or dark lines at the polygon edges - known as Mach banding comp_dep_educ@yahoo.com
36. 36. February 5, 2015 comp_dep_educ@yahoo.com 36 The individual bands should appear as gradients, and they may even appear to be curved. In fact, they are all solid colors. Now look at this one: If you look closely at the area above the center two arrows, you should see a thin bright line (left-middle arrow) and a thin dark line (right- middle arrow). Once again, this is despite the fact that each of the three areas (dark, light, and in between) are solid colors. Mach Bands
37. 37. February 5, 2015 comp_dep_educ@yahoo.com 37 In the graph on the bottom, the black line represents the actual luminance of the figure. The red line reflects the perceived luminance. The red line’s deviation from the black line represents the Mach Band phenomena, and the little spikes over and above the black line represent the bright and dark lines you see in the second figure above. Mach Bands
38. 38. February 5, 2015 38 Gouraud Shading comp_dep_educ@yahoo.com
40. 40. February 5, 2015 40 Phong shading is the most popular shading algorithm in use today. This method was developed by Phong Bui-Toung. Pong shading, also called normal-vector interpolation, is based on calculating pixel intensities by means of the approximated normal vector at the point in the polygon. Although more calculation expensive, Phong shading improves the rendering of bright points and highlights that are mis-rendered in Gouraud shading. Phong Shading comp_dep_educ@yahoo.com
41. 41. February 5, 2015 41 One lighting calculation per pixel comp_dep_educ@yahoo.com Phong Shading
42. 42. February 5, 2015 comp_dep_educ@yahoo.com 42 Phong Shading
43. 43. February 5, 2015 comp_dep_educ@yahoo.com 43 Phong Shading
44. 44. February 5, 2015 44 - Instead of interpolating the intensity values, the normal vectors are being interpolated between the vertices. - The intensity value is then calculated at each pixel using the interpolated normal vector. - This method greatly reduces the Mach-band problem but it requires more computational time. Phong Shading comp_dep_educ@yahoo.com
45. 45. February 5, 2015 45 • Compute normal, ni, at each vertex (if not already given) • Interpolate normals during scan conversion • Compute color with the interpolated normals ƒ - Expensive: compute illumination for every visible point on a surface ƒ - Captures highlights in the middle of a polygon ƒ - Looks smoother across edges Phong Shading comp_dep_educ@yahoo.com
46. 46. February 5, 2015 46 •normals are interpolated across the polygon. •need to know a normal for each vertex of the polygon. •better at dealing with highlights than Goraud shading. •slower than Goraud shading. •lighting equation used at each pixel. Where Goraud shading uses normals at the vertices and then interpolates the resulting colors across the polygon, Phong shading goes further and interpolates than normals. Linear interpolation of the normal values at each vertex are used to generate normal values for the pixels on the edges. Linear interpolation across each scan line is used to then generate normals at each pixel across the scan line. Phong Shading comp_dep_educ@yahoo.com
47. 47. February 5, 2015 47 Phong Shading comp_dep_educ@yahoo.com