Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Advanced computer graphics - Shading


Published on

lecture in advanced computer graphics

Published in: Science
  • 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. ●●●
    Are you sure you want to  Yes  No
    Your message goes here

Advanced computer graphics - Shading

  1. 1. February 5, 2015 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
  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 reflectance 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
  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
  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
  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
  7. 7. February 5, 2015 7 Lambertian Surface
  8. 8. February 5, 2015 8 Diffuse Lighting Model
  9. 9. February 5, 2015 9 Ambient Term
  10. 10. February 5, 2015 10 • Want to add highlights for shiny surfaces • Highlight moves with eye location Phong Illumination
  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
  12. 12. February 5, 2015 12 Phong Illumination: Computing r • How can we compute the reflection vector r?
  13. 13. February 5, 2015 13
  14. 14. February 5, 2015 14
  15. 15. February 5, 2015 15 Complete Illumination Equation • The complete illumination equations models: ƒ • Ambient light ƒ • Diffuse reflections ƒ • Specular reflections
  16. 16. February 5, 2015 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
  18. 18. February 5, 2015 18
  19. 19. February 5, 2015 19 One illumination calculation per polygon, assign all pixels inside each polygon the same color Flat shading
  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 flat shading, each triangle of a mesh is filled with a single color. Flat Shading
  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.
  22. 22. February 5, 2015 Flat Shading
  23. 23. February 5, 2015 Flat Shading
  24. 24. February 5, 2015 24 Flat Shading
  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
  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
  27. 27. February 5, 2015 27 Gouraud Shading
  28. 28. February 5, 2015 28 Gouraud Shading
  29. 29. February 5, 2015 29 Gouraud Shading
  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
  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
  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
  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
  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
  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
  36. 36. February 5, 2015 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 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
  39. 39. February 5, 2015 39 Gouraud ShadingFlat Shading
  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
  41. 41. February 5, 2015 41 One lighting calculation per pixel Phong Shading
  42. 42. February 5, 2015 42 Phong Shading
  43. 43. February 5, 2015 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
  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
  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
  47. 47. February 5, 2015 47 Phong Shading
  48. 48. February 5, 2015 48 Phong Shading Gouraud Shading
  49. 49. February 5, 2015 49 Fog, or atmospheric attenuation allows us to simulate this affect. Fog is implemented by blending the calculated color of a pixel with a given background color ( usually grey or black ), in a mixing ratio that is somehow proportional to the distance between the camera and the object. Objects that are farther away get a greater fraction of the background color relative to the object's color, and hence "fade away" into the background. In this sense, fog can ( sort of ) be thought of as a shading effect. Fog is typically given a starting distance, an ending distance, and a color. The fog begins at the starting distance and all the colors slowly transition to the fog color towards the ending distance. At the ending distance all colors are the fog color. Fog Distance fog is a technique used in 3D computer graphics to enhance the perception of distance by simulating fog.
  50. 50. February 5, 2015 50 Here is a scene from battalion without fog. The monster sees a very sharp edge to the world Here is the same scene with fog. The monster sees a much softer horizon as objects further away tend towards the black color of the sky Fog
  51. 51. February 5, 2015 51 Along a particular ray from some object to your eye, fog particles suspended in the air "scatter" some of the light that would otherwise reach your eye. Pollutants, smoke, and other airborne particles can also absorb light, rather than scattering the light, thereby reducing the intensity of the light that reaches your eye. Uniform Fog
  52. 52. February 5, 2015 52 If light travels a unit of distance along some ray through a uniformly foggy atmosphere Cleave = Center - Creduction + Cincrease where: Cleave is the color intensity of the light leaving a unit segment along a ray, Center is the color intensity of the light entering a unit segment along a ray, Creduction is the color intensity of all the light absorbed or scattered away along the unit segment, and Cincrease is the color intensity of additional light redirected by the fog in the direction of the ray along the unit segment. Uniform Fog
  53. 53. February 5, 2015 53 The intensity of light absorbed or scattered away cannot be greater than the intensity of incoming light. Assuming a uniform fog density, there must be a fixed ratio between the color of incoming light and the color of light scattered away. So we have: where: h is a constant scale factor dependent on the fog density. Uniform Fog
  54. 54. February 5, 2015 54 Assuming a uniform fog color, the color of additional light scattered by the fog in the direction of the ray is: Cincrease = h x Cfog where: Cfog is the constant fog color. Now you can express the color of the light leaving the fogged unit distance in terms of the color of the entering light, a constant percentage of light scattering and extinction, and a constant fog color. This relationship is: Cleave = (1 - h) x Center + h x Cfog Uniform Fog
  55. 55. February 5, 2015