Effects of lighting and material properties of an object in OpenGl


Published on

Computer Graphics

Published in: Education, Technology, Business
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Effects of lighting and material properties of an object in OpenGl

  2. 2. INTRODUCTION OF SHADING MODELS • Shading is the process of computing the color for the components of a scene. • It is usually done by calculating the effect of light on each object in a scene to create an effective lighted presentation. • The shading process is thus based on the physics of light, and the way light scatters from various kinds of materials with various details of surface treatments. • OpenGL supports two shading models for polygons: flat shading and smooth shading. • Shading is performed during the rendering process by a program called a shader. • The Shading model is set up with a call to glShadeModel and can be either set to SMOOTH or FLAT model. •glShadeModel (GL SMOOTH) ;
  3. 3. FLAT SHADING • Flat shading of a polygon presents each polygon with a single color. • The term flat can be taken to mean that the color is flat (does not vary) across the polygon, or that the polygon is colored as though it is flat (planar) and thus does not change color as it is lighted. • Result of flat shading all of the polygon's vertices are colored with one color, allowing differentiation between adjacent polygons.
  4. 4. SMOOTH SHADING • Smooth shading of a polygon displays the pixels in the polygon with smoothly-changing colors across the surface of the polygon. • This requires that you provide information that defines a separate color for each vertex of your polygon . • To compute the color for each vertex separately you must define a separate normal vector for each vertex of the polygon so that the lighting model will produce different colors at each vertex.
  6. 6. CREATION OF LIGHT SOURCE IN OPENGL • With OpenGL, you can manipulate the lighting and objects in a scene to create many different kinds of effects. • OpenGL approximates light and lighting as if light can be broken into red, green, and blue components. Lighting model has to be enabled. glEnable (GL_LIGHTING) ; Lighting support needs the depth buffer to be enabled. glEnable (GL_DEPTH_TEST); The function glEnable can enable many features of OpenGL, the feature you want to enable is provided as an input parameter.
  7. 7. The above code enables the lighting,however we need lights as well. OpenGL has direct support for about 8 lights . To enable a light, call: glEnable (GL_LIGHT0) ; Likewise, LIGHT1 or 2::8 shall be enabled when you want to handle multiple lights. Similar to glEnable function, OpenGL also has glDisable function that disables the features set before by glEnable.
  8. 8. To set light position Glfloat lightpos[] = f1; 1; 1; 1g; glLightfv (GL_LIGHT0;GL POSITION; lightpos) ; glLightv(GL_LIGHT0, GL_POSITION, origin); To specify the visual behavior of the lighting model. two ways: glLightModelf(GLenum pname; GLfloat param); // scalar params glLightModelfv(GLenum pname; const GLfloat params); // vector suppose you want to have a GLOBAL Ambient light that casts on all Glfloat global ambient[] = f0:5f; 0:5f; 0:5f; 1:0fg // R,G,B,Alpha glLightModelfv (GL_LIGHT_MODEL AMBIENT; global ambient) ;
  9. 9. TYPES OF LIGHT SOURCES WHICH CAN BE USED TO LIGHT A SCENE • Directional light - produced by a light source an infinite distance from the scene., All of the light rays emanating from the light strike the polygons in the scene from a single parallel direction, and with equal intensity everywhere. • Sunlight is for all intents and purposes a directional light.In fig. directional light from the front of the owl. • Characterized by color, intensity, and direction. • Point light - a light that gives off equal amounts of light in all directions. Polygons, and parts of polygons which are closer to the light appear brighter than those that are further away. • In fig. point light slightly in front of the owl.
  10. 10. SPOTLIGHT • The simplest spotlight would just be a point light that is restricted to a certain angle around its primary axis of direction - Think of something like a flashlight or car headlight as opposed to a bare bulb hanging on a wire. • In fig. spotlight slightly in front of the owl aimed at the owl. • Light sources are point sources by default, meaning that they emit light uniformly in all directions. But OpenGL allows you to make them into spotlights, so they emit light in a restricted set of directions.
  12. 12. • Adding a light to a scene causes many variations in shading and creates more interesting images. Together, lighting and an object's material properties determine its appearance. A lighting model describes the way light interacts with an object, based on the light's characteristics and the object material's characteristics. • Figure shows a set of objects that were rendered using various lighting models. Notice how the different formulations resemble an assortment of real-world materials.
  13. 13. • Now consider The Basic model, modification of classic Phong model. In the Basic model, an object's surface color is the sum of emissive, ambient, diffuse, and specular lighting contributions. With multiple lights the affect of all the lights are additive. • Each contribution depends on the combination of the surface's material properties (such as shininess and material color) and the light source's properties (such as light color and position).
  15. 15. 1) EMISSIVE LIGHTING (NO LIGHTING ) • There are no lights in the scene • Each object is self-luminous (it lights itself, but does not give off light) • This is also known as "emissive" lighting in some systems . Truly "no" lighting would be a totally black screen and not very interesting. • Emissive lighting can have some interesting effects, such as neon signs. • The emissive term can simulate glowing , like car head lights. Unlike in the real world, an object's emissive glow does not actually illuminate other nearby objects in the scene. • An emissive object is not itself a light source—it does not illuminate other objects or cast shadows.
  16. 16. • the emissive term is that it is a color added after computing all the other lighting terms. • Each polygon has its own colour which is constant over its surface • That colour is not affected by anything like position or orientation else in the world • This is very fast, but not very realistic • position of viewer is not important • No 3-D information provided.
  17. 17. 2)DIFFUSED (R, G, B) • The diffuse term accounts for directed light reflected off a surface equally in all directions. • In general, diffuse surfaces are rough on a microscopic scale, with small nooks that reflect light in many directions. When incoming rays of light hit these nooks, the light bounces off in all directions, as shown in fig. Diffuse Light Scattering • The amount of light reflected is proportional to the angle of incidence of the light striking the surface.The diffuse contribution at any particular point on a surface is the same, regardless of where the viewpoint is.
  18. 18. 3)AMBIENT • Ambient light does not appear to come from any particular direction; rather, it appears to come from all directions. • Because of this, the ambient lighting term does not depend on the light source position. • The ambient term depends on a material's ambient reflectance, as well as the color of the ambient light that is incident on the material. • Like the emissive term, the ambient term on its own is just a constant color. Unlike the emissive color, however, the ambient term is affected by the global ambient lighting.
  19. 19. 4)SPECULAR • The specular term represents light scattered from a surface predominantly around mirror direction. Figure illustrates the concept of specular reflection. • Unlike the emissive, ambient, and diffuse lighting terms, the specular contribution depends on the location of the viewer. • reflection off of shiny surfaces - you see a highlight • shiny metal or plastic has high specular component .
  20. 20. 5)SHININESS (0.0 - 1.0) • Controls the contribution of the specular component. • The specular term is affected not only by the specular color properties of the light source and material, • but also by how shiny the surface is • Shinier materials have smaller, tighter highlights, • whereas less shiny materials have highlights that are more spread out. • Figure shows some examples of shininess, with the shininess exponent increasing from left to right
  21. 21. 6)TRANSPARENCY 0.0 - 1.0 • Material properties specified as RGBA values • A(alpha) value can make surface translucent • Default: all surfaces opaque regardless of A
  22. 22. • One important thing to note about all of the above is that each object is dealt with separately. That is, one object does not block light from reaching another object.
  24. 24. • There are two types of light properties you should consider while programming the lighting model in OpenGL. • The first type describes a light source and the second type describes the light reflected by the material of an object's surface. • For every type of light source you need to call the glLightfv function with parameters. • For example, To add a component of specular light to a light source, you • would make the following function call: • GLfloat specular[] = f1:0f; 1:0f; 1:0f; 1:0fg; • glLightv(GL_LIGHT0, GL_SPECULAR, BLACK); • glLightv(GL_LIGHT0, GL_AMBIENT, WHITE); • glLightv(GL_LIGHT0, GL_DIFFUSE, WHITE);
  25. 25. • • • • • • • • GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; GLfloat diffuse[] = {1.0, 0.8, 0.0, 1.0}; GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat shine = 100.0 glMaterialf(GL_FRONT, GL_AMBIENT, ambient); glMaterialf(GL_FRONT, GL_DIFFUSE, diffuse); glMaterialf(GL_FRONT, GL_SPECULAR, specular); glMaterialf(GL_FRONT, GL_SHININESS, shine); • The material property of an object,is usually the colour reflected by that object. The first parameter of the glMaterialfv command indicates which face of the polygon should reflect the light specfied by mcolor. • Apparently, there are two sides to a polygon - front and back. • OpenGl provides two ways to specify a polygon in 3D space in order to decide the front face. The clockwise or counterclockwise direction describes which side is the front and which is the back.
  26. 26. REFRENCES • http://http.developer.nvidia.com/CgTutorial/cg_tutorial_c hapter05.html • http://www.cs.uic.edu/~jbell/CourseNotes/ComputerGrap hics/LightingAndShading.html • http://www.cs.uml.edu/~haim/teaching/cg/resources/pres entations/427/AngelCG20_shading_OpenGL.pdf • http://www.cse.iitb.ac.in/~paragc/teaching/2009/cs475/n otes/opengl_lighting_texture_sumair.pdf
  27. 27. QUESTIONS…..???