1Computer Graphics for Scientists and EngineersLighting in OpenGL
2Graphics: Conceptual ModelReal ObjectRealObjectHuman EyeHuman EyeDisplayDeviceGraphics SystemSyntheticModelSyntheticCamer...
3Lights, Surfaces, and ImagingProj. PlaneViewerObjects
4Lights, Surfaces, and ImagingProj. PlaneViewerLightSourceObjects
5Modes of Interaction of Light with MaterialsSpecularSurfaceDiffuseSurface TranslucentSurfaceNote: Any given surface can h...
6Illuminating SurfaceszxyI(θ,φ,λ)I(x, y,z,θ,φ,λ)We can define illumination function:To obtain total light, must integrate ...
7Simplified ModelExact model can easily get complicated!Three simplifications help.1. We can consider four classes of ligh...
8Light SourcesAmbient light- no identifiable source or direction- hack for replacing true global illumination= (light boun...
9Ambient LightSimulates situations where light sources are designed to produceuniform lighting throughout a scene.Characte...
10Point SourcesAn ideal point source radiates equally in all directions. It canbe characterized by:I(p0) =Ir (p0 )Ig(p0)Ib...
11Light SourcesTypes of light sources- glLightfv(GL_LIGHT0,GL_POSITION,light[])- directional/parallel lights= real-life ex...
12SpotlightsSpotlights are point sources for which the angle through whichlight has been emitted has been limited.θlsI = k...
13Distant SourcesMost shading calculations require the direction from the point ona surface to the light source. As light ...
14ReflectionRough Surface:Light is reflected equally inall directions.DiffuseSmooth Surface:Light is reflected at an angle...
15Vectors Used byPhong Lighting Modelp is an arbitrary point on a surface.n is the unit normal to the surface at p.l is a ...
16Elements of the Phong Lighting ModelRi =Rira Riga RibaRird Rigd RibdRirsRigsRibsAt each point p thereis a refl...
17Elements of the Phong Lighting ModelAmbient ReflectionIa= kaLa0 ≤ ka ≤1The intensity of ambient light is the same at eve...
18Elements of the Phong Lighting ModelDiffuse ReflectionIntensity of illumination is dependent upon the incidence angleof ...
19Elements of the Phong Lighting ModelSpecular ReflectionFor a shiny surface, most light is reflected around vector r,corr...
20The Complete Lighting ModelglobalambglobalambmaassddniLkELkLkLkcdbdaI+++⋅+⋅++= ∑−=)])()((1[ 210αvrnlDistance(Attenuation...
21Calculation of NormalsNormal exists at every point for mathematically defined smoothsurfaces.Exists for each polygon in ...
22Calculation of NormalsMathematically Defined Surface: SphereSphere is defined implicitly by equation:f ( x, y, z) = x2+ ...
23Specification of the Normal in OpenGLSpecification of the current normal is modal and associated withvertices.glNormal3f...
24Shading in OpenGL:Flat ShadingOpenGL uses the normal of the first vertex of a singlepolygon to determine the color.Reque...
25Mach Band Effect(Mach, 1865)Color Science, Concepts and MethodsWyszecki, Stiles
26Mach Band Effect
27Mach Band Effect
28Shading in OpenGL:Smooth ShadingRequested by: glShadeModel(GL_SMOOTH);Lighting calculations will be done at each vertex ...
29Gouraud Shading
30Lighting Implementation in OpenGL
31Lighted Sphere Demo and Source Code
32Enable Depth BufferFor Hidden Surface Removal//before enablingwhile (1) {get_viewing_point_from_mouse_position();glClear...
33Specifying Light Sources in OpenGLGeneral form: glLightf(source, parameter, value);glLightfv(source, parameter, *array);...
34Specifying Light Sources in OpenGLGeneral form: glLightf(source, parameter, value);glLightfv(source, parameter, *array);...
35Specifying Light Sources in OpenGLGeneral form: glLightf(source, parameter, value);glLightfv(source, parameter, *array);...
36Enabling the Lights and LightingEnabling a specific light source: glEnable(GL_LIGHTi );Enabling the lighting model: glEn...
37Specifying Materials in OpenGLGeneral form: glMaterialf(face, parameter,value);glMaterialfv(face, parameter,*array);face...
381. Ambient light in ascene with 3 spheres.2. Diffuse lighthitting the surface of3 spheres. Notice,the spheres lookmatte ...
39By S.Vanitha, Chennai
Upcoming SlideShare
Loading in …5
×

Light effect

906 views
742 views

Published on

This content will help the scientists and Engineers to get indepth knowledge in Lighting in Computer Graphics.

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
906
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Light effect

  1. 1. 1Computer Graphics for Scientists and EngineersLighting in OpenGL
  2. 2. 2Graphics: Conceptual ModelReal ObjectRealObjectHuman EyeHuman EyeDisplayDeviceGraphics SystemSyntheticModelSyntheticCameraReal LightSyntheticLight Source
  3. 3. 3Lights, Surfaces, and ImagingProj. PlaneViewerObjects
  4. 4. 4Lights, Surfaces, and ImagingProj. PlaneViewerLightSourceObjects
  5. 5. 5Modes of Interaction of Light with MaterialsSpecularSurfaceDiffuseSurface TranslucentSurfaceNote: Any given surface can have some of all three properties.
  6. 6. 6Illuminating SurfaceszxyI(θ,φ,λ)I(x, y,z,θ,φ,λ)We can define illumination function:To obtain total light, must integrate over total surface.Itotal (λ) = I(x,y,z,θ,φ,λ)∫∫∫ dxdydz
  7. 7. 7Simplified ModelExact model can easily get complicated!Three simplifications help.1. We can consider four classes of light sources• ambient• point• spotlight• distant2. Human color perception allows us to consider illuminationfunction in terms of the three primary colors.3. We can neglect (OpenGL caveats):• multiple reflections• obstruction of light path by objects
  8. 8. 8Light SourcesAmbient light- no identifiable source or direction- hack for replacing true global illumination= (light bouncing off from other objects)
  9. 9. 9Ambient LightSimulates situations where light sources are designed to produceuniform lighting throughout a scene.Characterized by a scalar intensity, Ia , that is identical at every pointin the scene.Ia =IarIagIabAlthough every surface receives the same illumination, eachsurface can reflect the light differently.
  10. 10. 10Point SourcesAn ideal point source radiates equally in all directions. It canbe characterized by:I(p0) =Ir (p0 )Ig(p0)Ib (p0 )Intensity of illumination from a point source is proportionalto the inverse square of the distance between the point and theilluminated surface.I(p,p0 ) =1p−p02 I(p0 )
  11. 11. 11Light SourcesTypes of light sources- glLightfv(GL_LIGHT0,GL_POSITION,light[])- directional/parallel lights= real-life example: sun= infinitely far source: homogeneous co-ord. w=0- point lights= same intensity in all directions- spot lights= limited set of directions:point+direction+cutoff angle0zyx1zyx
  12. 12. 12SpotlightsSpotlights are point sources for which the angle through whichlight has been emitted has been limited.θlsI = k cose(θ) = k(l⋅s)e
  13. 13. 13Distant SourcesMost shading calculations require the direction from the point ona surface to the light source. As light sources are moved tolarger distances, this direction approaches a constant.Therefore the point source location will be replaced by a vectorindicating the direction of the source.p0=xyz1will be replaced by: p0=xyz0
  14. 14. 14ReflectionRough Surface:Light is reflected equally inall directions.DiffuseSmooth Surface:Light is reflected at an anglenear to the incident angle.Specular
  15. 15. 15Vectors Used byPhong Lighting Modelp is an arbitrary point on a surface.n is the unit normal to the surface at p.l is a unit vector in the direction of the light source.r is a unit vector in the direction of a perfectly (specular)reflectionv is a unit vector in the direction of the viewer.nlrvpViewer
  16. 16. 16Elements of the Phong Lighting ModelRi =Rira Riga RibaRird Rigd RibdRirsRigsRibsAt each point p thereis a reflection matrix forthe ith light source:I = Ia+ Id+ Is= LaRa+ LdRd+ LsRsAssuming the calculations will be done separately foreach primary, we can sum over light sources to get:Li=Lira Liga LibaLirdLigdLibdLirsLigsLibsAt each point p thereis an illumination matrixfrom the ith light source:red green blueambientdiffusespecular
  17. 17. 17Elements of the Phong Lighting ModelAmbient ReflectionIa= kaLa0 ≤ ka ≤1The intensity of ambient light is the same at every pointon the surface. The percentage of light reflected is givenby: Ra= kaNote that the ambient reflection terms can be differentfor red, green and blue.
  18. 18. 18Elements of the Phong Lighting ModelDiffuse ReflectionIntensity of illumination is dependent upon the incidence angleof light from the source:Adding a term for attenuationwith distance from source:Id =k da + bd + cd 2( l ⋅ n ) L dθlnRd∝ cosθ = l⋅nId= kd(l⋅n)Ld
  19. 19. 19Elements of the Phong Lighting ModelSpecular ReflectionFor a shiny surface, most light is reflected around vector r,corresponding to a reflected angle equal to the angle of incidence.If θ is the angle between v and r,Is= ksLscosαθAdding a distance term, and expressing the cosine in terms ofa dot product:Is =1a + bd + cd 2k s L s (r ⋅ v )αnlrvpViewer
  20. 20. 20The Complete Lighting ModelglobalambglobalambmaassddniLkELkLkLkcdbdaI+++⋅+⋅++= ∑−=)])()((1[ 210αvrnlDistance(Attenuation)AmbientDiffuse SpecularEmissionGlobalAmbientnlrvpViewer()()()glMaterialglLightelglLightModkLE
  21. 21. 21Calculation of NormalsNormal exists at every point for mathematically defined smoothsurfaces.Exists for each polygon in surface defined by flat polygons.What about the shared lines/points?Polygonal Case:p0p1p2nn = (p1− p0) × (p2− p0)
  22. 22. 22Calculation of NormalsMathematically Defined Surface: SphereSphere is defined implicitly by equation:f ( x, y, z) = x2+ y2+ z2− 1 = 0n =∂f∂x∂f∂y∂f∂z=2x2y2z= 2p
  23. 23. 23Specification of the Normal in OpenGLSpecification of the current normal is modal and associated withvertices.glNormal3f(nx,ny,nz);glNormal3fv(pointer_to_normal_vector);You have to calculate the normals yourself.
  24. 24. 24Shading in OpenGL:Flat ShadingOpenGL uses the normal of the first vertex of a singlepolygon to determine the color.Requested by: glShadeModel(GL_FLAT);Flat shading exaggerates the visual effect of theboundaries between polygons due to the Mach bandeffect.
  25. 25. 25Mach Band Effect(Mach, 1865)Color Science, Concepts and MethodsWyszecki, Stiles
  26. 26. 26Mach Band Effect
  27. 27. 27Mach Band Effect
  28. 28. 28Shading in OpenGL:Smooth ShadingRequested by: glShadeModel(GL_SMOOTH);Lighting calculations will be done at each vertex using thematerial properties, and the vectors v and l calculated for thatvertex.Bilinear interpolation is used to determine color values in theinterior of the polygon.Gouraud Shading:Normal at a vertex is the normalized average of the normals ofthe polygons that share that vertex.
  29. 29. 29Gouraud Shading
  30. 30. 30Lighting Implementation in OpenGL
  31. 31. 31Lighted Sphere Demo and Source Code
  32. 32. 32Enable Depth BufferFor Hidden Surface Removal//before enablingwhile (1) {get_viewing_point_from_mouse_position();glClear(GL_COLOR_BUFFER_BIT);draw_3d_object_A();draw_3d_object_B();}//after enablingglutInitDisplayMode (GLUT_DEPTH | .... );glEnable(GL_DEPTH_TEST); ...while (1) {glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);get_viewing_point_from_mouse_position();draw_3d_object_A();draw_3d_object_B();}
  33. 33. 33Specifying Light Sources in OpenGLGeneral form: glLightf(source, parameter, value);glLightfv(source, parameter, *array);source is one of at least eight lights: GL_LIGHTiParameters:GL_AMBIENT contains four values that specify the ambient RGBAintensity of the light. Default is (0.0, 0.0, 0.0, 1.0).GL_DIFFUSE contains four values that specify the diffuse RGBAintensity of the light. Default is (1.0, 1.0, 1.0, 1.0).GL_SPECULAR contains four values that specify the secular RGBAintensity of the light. Default is (1.0, 1.0, 1.0, 1.0).
  34. 34. 34Specifying Light Sources in OpenGLGeneral form: glLightf(source, parameter, value);glLightfv(source, parameter, *array);GL_POSITION specifies the position of the light in homogeneousobject coordinates. If the w component is zero, the lightis treated as a directional source.GL_SPOT_DIRECTION specifies the direction of the light inhomogeneous object coordinates. Default is (0.0, 0.0, -1.0)GL_SPOT_EXPONENT spotlight exponent, default 0.0GL_SPOT_CUTOFF spot cutoff angle in [0,90] or (default) 180.θlsI = kcose(θ) = k(l⋅s)e
  35. 35. 35Specifying Light Sources in OpenGLGeneral form: glLightf(source, parameter, value);glLightfv(source, parameter, *array);GL_CONSTANT_ATTENUATION constant atten. factor, default 1.0GL_LINEAR_ATTENUATION linear atten. factor, default 0.0GL_QUADRATIC_ATTENUATION quadratic atten. factor, default 0.0Id =k da + b d + c d 2( l ⋅ n ) L dnl rvpViewer
  36. 36. 36Enabling the Lights and LightingEnabling a specific light source: glEnable(GL_LIGHTi );Enabling the lighting model: glEnable (GL_LIGHTING);
  37. 37. 37Specifying Materials in OpenGLGeneral form: glMaterialf(face, parameter,value);glMaterialfv(face, parameter,*array);face is GL_FRONT, GL_BACK, GL_FRONT_AND_BACKparameter is:GL_AMBIENT four values that specify the ambient RGBAreflectance of the material. (0.2,0.2,0.2,1.0)GL_DIFFUSE four values that specify the diffuse RGBAreflectance of the material. (0.8,0.8,0.8,1.0)GL_SPECULAR four values that specify the ambient RGBAreflectance of the material. (0.0,0.0,0.0,1.0)GL_SHININESS specifies the specular reflectanceexponent of the material. 0.0
  38. 38. 381. Ambient light in ascene with 3 spheres.2. Diffuse lighthitting the surface of3 spheres. Notice,the spheres lookmatte and almostplastic like.3. The threespheres illuminatedby specular light.Imagine anextremely shinybilliard ball and thesheen it createsTypes Of Light And Its Effects
  39. 39. 39By S.Vanitha, Chennai

×