1 / 59

2IV60 Computer graphics set 8: Illumination Models and Surface-Rendering Methods

2IV60 Computer graphics set 8: Illumination Models and Surface-Rendering Methods. Jack van Wijk TU/e. OpenGL Illumination example. Glfloat lightPos [] = {2.0, 0.0, 3.0, 0.0}; Glfloat whiteColor [] = {1.0, 1.0, 1.0, 1.0}; Glfloat pinkColor [] = {1.0, 0.5, 0.5, 1.0};

Télécharger la présentation

2IV60 Computer graphics set 8: Illumination Models and Surface-Rendering Methods

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. 2IV60 Computer graphicsset 8: Illumination Models and Surface-Rendering Methods Jack van Wijk TU/e

  2. OpenGL Illumination example GlfloatlightPos[] = {2.0, 0.0, 3.0, 0.0}; GlfloatwhiteColor[] = {1.0, 1.0, 1.0, 1.0}; GlfloatpinkColor[] = {1.0, 0.5, 0.5, 1.0}; glShadeModel(GL_SMOOTH); // Use smooth shading glEnable(GL_LIGHTING); // Enable lighting glEnable(GL_LIGHT0); // Enable light source #0 glLightfv(GL_LIGHT0, GL_POSITION, lightPos); // position LS 0 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteColor); // set color LS 0 glMaterialfv(GL_FRONT, GL_DIFFUSE, pinkColor); // set surface // color glBegin(GL_TRIANGLES); glNormal3fv(n1); glVertex3fv(v1); // draw triangle, give glNormal3fv(n2); glVertex3fv(v2); // first normal, followed glNormal3fv(n3); glVertex3fv(v3); // by vertex glEnd(); What is going on here?

  3. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model, or Shading Model Surface rendering: Apply the Illumination model to color all pixels of the surface. H&B 17:531-532

  4. Introduction 2 Example: • Illumination model gives color vertices, • Surface is displayed via interpolation of these colors. H&B 17:531-532

  5. Introduction 3 Illumination: • Physics: • Material properties, light sources, relative positions, properties medium • Psychology: • Perception, what do we see • Color! • Often approximating models H&B 17:531-532

  6. Light sources 1 Light source: object that radiates energy. Sun, lamp, globe, sky… Intensity I = (Ired , Igreen , Iblue) If Ired = Igreen = Iblue : white light H&B 17-1:532-536

  7. Light sources 2 Simple model: point light source • position P and intensity I • Light rays along straight lines • Good approximation for small light sources H&B 17-1:532-536

  8. Light sources 3 Simpler yet: point light source at infinity • Direction V and intensity I • Sunlight V H&B 17-1:532-536

  9. Light sources 4 Damping: intensity of light decreases with distance Energy is distributed over area sphere, hence Il = I / d2, with d distance to light source. In practice often too ‘agressive’, hence Il = I / (a0 +a1d+a2d2) If light source at infinity: No damping with distance d H&B 17-1:532-536

  10. Q a l light cone Vlight Light sources 5 Directed light source, spotlight: Light is primarily send in direction of Vlight . P H&B 17-1:532-536

  11. Q a l light cone Vlight Light sources 6 More subtle: Let I decrease with increasing angle a. P H&B 17-1:532-536

  12. reflection transmission Surface illumination 1 • When light hits a surface, three things can happen: absorption H&B 17-2:536-537

  13. Surface illumination 2 • Suppose, a light source radiates white light, consisting of red, green and blue light. If only red light is reflected, then we see a red surface. reflection absorption transmission H&B 17-2:536-537

  14. Surface illumination 3 • Diffuse reflection: Light is uniformly reflected in all directions • Specular reflection: Light is stronger reflected in one direction. specular reflection diffuse reflection H&B 17-2:536-537

  15. Surface illumination 4 • Ambientlight: light from the environment. Undirected light, models reflected light of other objects. H&B 17-2:536-537

  16. Basic illumination model 1 Basic illumination model: • Ambient light; • Point light sources; • Ambient reflection; • Diffuse reflection; • Specular reflection. H&B 17-3:537-546

  17. Basic illumination model 2 • Ambientlight: environment light. Undirected light, models reflected light of other objects. H&B 17-3:537-546

  18. dA  dA/cos  Basic illumination model 3 Perfect diffuse reflector: light is reflected uniformly in all directions. H&B 17-3:537-546

  19. dA Basic illumination model 4 Perfect diffuse reflector: light is reflected uniformly in all directions. . • Lambert’s law: • Reflected energy is • proportional with cos , where • denotes the angle between the • normal N and a vector to the light • source L. N L   dA/cos  H&B 17-3:537-546

  20. Basic illumination model 5 Perfect diffuse reflector: light is reflected uniformly in all directions. Psource N Il L Psurf H&B 17-3:537-546

  21. Basic illumination model 6 Perfect specular reflector: light is only reflected in one direction. Angle of incidence is angle of reflection. N L R q q H&B 17-3:537-546

  22. Basic illumination model 7 Imperfect specular reflector: light is distributed in the direction of the angle of reflection, dependent on the roughness of the surface. N N L L R R q q q q glad ruw H&B 17-3:537-546

  23. Basic illumination model 8 Phong model: empirical model for specular reflection N L R V q q  H&B 17-3:537-546

  24. Basic illumination model 9 Phong model: empirical model for specular reflection N L R V q q  H&B 17-3:537-546

  25. L V N.L Basic illumination model 10 Phong model: calculating the vectors N L R H&B 17-3:537-546

  26. Basic illumination model 11 Phong model: variant with halfway vector H. Use a instead of f. N H L R a V  If light source and viewer far away: H  constant. H&B 17-3:537-546

  27. Basic illumination model 12 All together: H&B 17-3:537-546

  28. Basic illumination model 13 Color (reprise): Light intensity I and reflection coefficients k: (r,g,b) triplets So for instance: Plastic: kd is colored (r,g,b), ks is grey (w,w,w) Metal: kd and ks same color Basic model: simple but effective. It can be done much better though… H&B 17-3:537-546

  29. Transparancy 1 Transparant object: • reflected and transmitted light • refraction • scattering H&B 17-4:546-549

  30. Transparancy 2 Snell’s law of refraction: N L R qi qi T qr H&B 17-4:546-549

  31. Transparancy 3 Thin surface: • double refraction • shift of light ray H&B 17-4:546-549

  32. Poor result for silhouette edges… Transparancy 3 Very thin surface: • Discard shift H&B 17-4:546-549

  33. Atmospheric effects 1 Atmospheric effects: • dust, smoke, vapor • colors are dimmed • objects less well visible H&B 10-5:549-550

  34. = 0.25 + [ 1  0.25 ] Atmospheric effects 2 H&B 10-5:549-550

  35. Rendering polygons 1 Basic illumination model: Can be used per point, but that’s somewhat expensive More efficient: Illumination model gives color for some points; Surface is filled in using interpolation of these colors. H&B 17-10:559-564

  36. Rendering polygons 2 Constant-intensity rendering aka flat surface rendering: • Determine color for center of polygon; • Fill the polygon with a constant color. • Ok if: • Object consists of planar faces, and • Light sources are far away, and • Eye point is far away, • or • Polygons are about a pixel in size. H&B 17-10:559-564

  37. Rendering polygons 2 Constant-intensity rendering aka flat surface rendering: • Determine color for center of polygon; • Fill the polygon with a constant color. Highlights not visible, Facetted appearance, increased by Mach banding effect. H&B 17-10:559-564

  38. Mach banding • Human perception: edges are given emphasis, contrast is increased near edges. Angel (2000) H&B 17-10:559-564

  39. N2 N3 N1 V N4 Rendering polygons 2 Gouraud surface rendering: • Determine average normal on vertices; • Determine color for vertices; • Interpolate the colors per polygon (incrementally). H&B 17-10:559-564

  40. Rendering polygons 3 Gouraud surface rendering: • Much better result for curved surfaces • Errors near highlights • Linear interpolation still gives Mach banding • Silhouettes are still not smooth Gouraud Flat

  41. Fast Phong surface rendering: Like Phong surface rendering, but use 2nd order approximation of color over polygon: Rendering polygons 4 Phong surface rendering: • Determine average normal per vertex; • Interpolate normals per polygon (incrementally); • Calculate color per pixel. H&B 17-10:559-564

  42. Rendering polygons 5 Phong surface rendering: • Even better result for curved surfaces • No errors at high lights • No Mach banding • Silhouettes remain coarse • More expensive than flat or Gouraud shading H&B 17-10:559-564

  43. Rendering polygons 5 Flat Gouraud Phong H&B 17-10:559-564

  44. OpenGL Illumination GlfloatlightPos[] = {2.0, 0.0, 3.0, 0.0}; GlfloatwhiteColor[] = {1.0, 1.0, 1.0, 1.0}; GlfloatpinkColor[] = {1.0, 0.5, 0.5, 1.0}; glShadeModel(GL_SMOOTH); // Use smooth shading glEnable(GL_LIGHTING); // Enable lighting glEnable(GL_LIGHT0); // Enable light source #0 glLightfv(GL_LIGHT0, GL_POSITION, lightPos); // position LS 0 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteColor); // set color LS 0 glMaterialfv(GL_FRONT, GL_DIFFUSE, pinkColor); // set surface // color glBegin(GL_TRIANGLES); glNormal3fv(n1); glVertex3fv(v1); // draw triangle, give glNormal3fv(n2); glVertex3fv(v2); // first normal, followed glNormal3fv(n3); glVertex3fv(v3); // by vertex glEnd(); H&B 17-11:564-574

  45. OpenGL Light-sources 1 First, enable lighting in general: glEnable(GL_LIGHTING); OpenGL provides (at least) eight light-sources: lightName = GL_LIGHT0, GL_LIGHT1, … , GL_LIGHT7 Enable the one(s) you need with: glEnable(lightName); Set properties with glLight*(lightName, lightProperty, propertyValue); * = i, f, iv, or fv (i: integer, f: float, v vector) H&B 17-11:564-574

  46. OpenGL Light-sources 2 • Position light-source: • GlfloatsunlightPos[] = {2.0, 0.0, 3.0, 0.0}; • GlfloatlamplightPos[] = {2.0, 0.0, 3.0, 1.0}; • glLightfv(GL_LIGHT1, GL_POSITION, sunlightPos); • glLightfv(GL_LIGHT2, GL_POSITION, lamplightPos); • Fourth coordinate = 0: source at infinity • Fourth coordinate = 1: local source • Specified in world-coordinates, according to the currentModelView specification – just like geometry. Hence, take care when you specify the position. • Light from above looks more natural H&B 17-11:564-574

  47. OpenGL Light-sources 3 • Color light-source: • GlfloatgreyColor[] = {0.3, 0.3, 0.3, 1.0}; • GlfloatpinkColor[] = {1.0, 0.7, 0.7, 1.0}; • GlfloatwhiteColor[] = {1.0, 1.0, 1.0, 1.0}; • glLightfv(GL_LIGHT1, GL_AMBIENT, greyColor); • glLightfv(GL_LIGHT1, GL_DIFFUSE, pinkColor); • glLightfv(GL_LIGHT1, GL_SPECULAR, whiteColor); • OpenGL light-source has three color properties, dependent on reflection surface. Not realistic, can be used for special effects. • If you don’t have ambient light, things often appear black. • Colors are always 4-vectors here: Fourth coordinate is alpha. Most cases: set it to 1.0. • More settings: See book H&B 17-11:564-574

More Related