1 / 28

Light Source

Lighting and Shading. Light Source. Incoming (Incident) light. Reflected light. Object Surface. Refracted light. Light Source. Point Light Source. Light emits from a single point in all directions. Parallel (Directional) Light Source.

jzimmerman
Download Presentation

Light Source

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. Lighting and Shading Light Source Incoming (Incident) light Reflected light Object Surface Refracted light

  2. Light Source Point Light Source Light emits from a single point in all directions Parallel (Directional) Light Source Light source is at infinity. Light rays are parallel lines. V V: Light direction vector

  3. Spotlight Light emits from a single point. Light rays are confined to a cone. V c c: Cut-off angle V: Light direction vector (Cone Axis) Extended Light Source Light source with a finite surface area. Can be approximated as multiple point light sources.

  4. Radial Intensity Attenuation Light intensity decreases as light travels away from the light source. Radial intensity attenuation factor d Distance from the light source a0 Constant attenuation coefficient a1 Linear attenuation coefficient a2 Quadratic attenuation coefficient Radial intensity attenuation only applies to point light and spotlight.

  5. Angular Intensity Attenuation R (light ray)  V (Cone axis) c For spotlight, light intensity decreases as the light ray deviates from the cone axis. Angular intensity attenuation factor  Light ray angle from cone axis m Angular intensity attenuation exponent

  6. Phong Reflection Model Ambient Diffuse Specular Emissive

  7. Ambient Light Ambient Light: Background light that comes from all directions and has constant intensity. Ia Intensity of incoming ambient light Oa Intensity of reflected ambient light ka Ambient reflectivity of object surface

  8. Diffuse Reflection • Incoming light comes from a certain direction. • Reflected light is scattered in all directions. Incident light N N Unit Surface Normal L Unit Direction Vector to Light  incident angle  L IdIntensity of incoming diffuse light Od Intensity of reflected diffuse light kd Diffuse reflectivity of object surface For most materials, kd = ka

  9. Specular Reflection • Incoming light comes from a certain direction. • Reflected light concentrates around a certain direction. Incident light N R L Viewer   V  R Unit Vector in Ideal Specular Reflection Direction V Unit Direction Vector to the Viewer

  10. Phong Model Is Intensity of incoming specular light Os Intensity of specular reflection light ks Specular reflectivity of object surface n Specular reflection exponent Simplified Phong Model Halfway vector N H R  L V 

  11. n controls the shininess of the surface N N R L L R Shiny surface (large n) Small specular highlight Dull surface (small n) Large specular highlight

  12. Surface Light Emission Light emitted by the object itself. Combine Everything Together nl: Number of light sources

  13. Colored Light and Material Light Intensity and Material Reflectivity are specified in RGB triples Lighting calculation is performed for each RGB component separately

  14. Polygon Shading Models • Flat shading • Smooth shading (Gouraud shading) • Phong shading Flat Shading Polygon surface is rendered using a single color. The color usually comes from a vertex or polygon centroid under certain illumination model.

  15. Smooth Shading (Gouraud shading) The color for each vertex of the polygon is calculated under certain illumination model. The surface color of the polygon is interpolated using the vertices’ colors. • Determine unit normal vector at each vertex. • Calculate the color of each vertex using an illumination model. • Linearly interpolate vertex colors across projected polygon.

  16. Phong Shading Interpolate vertex normal vectors instead of vertex colors • Determine unit normal vector at each vertex. • Linearly interpolate vertex normals across projected polygon. • Apply an illumination model and calculate the color of each projected pixel using the interpolated normal. • Advantage of Phong Shading over Smooth Shading: • No Mach bands effect (bright and dark intensity streaks) • Better specular highlight

  17. Vertex Normal Calculation Polygon Surface Normal and Plane Equation z N=(A, B, C) Three points on the polygon surface: Outside P1 P2 In right-handed coordinate system, P1, P2, P3 are specified in counter-clockwise direction when viewed from outside to inside P3 y Inside x Surface normal: Plane equation: or if Ax + By + Cz + D < 0, point (x, y, z) is inside. if Ax + By + Cz + D > 0, point (x, y, z) is outside.

  18. Averaged Vertex Normal of Polygon Surfaces N2 Average normal vectors of all polygons that share the vertex N N1 N3 N4 True Normal of a Curved Surface Non-parametric surface equation Parametric surface equation

  19. Lighting in OpenGL Create Light Source void glLightf(GLenum light, GLenum pname, GLfloat pvalue) void glLightfv(GLenum light, GLenum pname, GLfloat *pvalue) Create a light source light: Light source identifier. Values are GL_LIGHTi, (i = 0, 1, 2, … , 7) pname: Parameter name pvalue: Parameter value To enable a light source, use glEnable(GL_LIGHTi); To disable a light source, use glDisable(GL_LIGHTi); To enable lighting calculation, use glEnable(GL_LIGHTING); To disable lighting calculation, use glDisable(GL_LIGHTING);

  20. The light source position specified by GL_POSITION is transformed by current Modelview matrix and stored in eye coordinates. To make a light source relatively fixed to the viewer To make a light source relatively fixed to the scene Specify light source position Viewing Transformation Viewing Transformation Specify light source position Modeling Transformation Modeling Transformation

  21. Define Surface Material Properties void glMaterialf(GLenum face, GLenum pname, GLfloat pvalue) void glMaterialfv(GLenum face, GLenum pname, GLfloat *pvalue) face: Indicates which face the material properties are applied to. GL_FRONT, GL_BACK, GL_FRONT_AND_BACK

  22. Use Color Material Mode void glColorMaterial( GLenum face, GLenum mode) Cause material property specified by mode of polygon faces specified by face to track current color specified by glColor*() command. face: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK mode: GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_AMBIENT_AND_DIFFUSE, GL_EMISSION To enable color material mode, use glEnable(GL_COLOR_MATERIAL); To disable color material mode, use glDisable(GL_COLOR_MATERIAL);

  23. Select Lighting Model void glLightModel{if}(GLenum pname, TYPE pvalue) void glLightModel{if}v(GLenum pname, TYPE *pvalue) Global Ambient Light pname = GL_LIGHT_MODEL_AMBIENT pvalue = (R, G, B, A) Defines global ambient light intensity that is not from any particular light source. Default value is (0.2, 0.2, 0.2, 1.0) Two-Sided Lighting pname = GL_LIGHT_MODEL_TWO_SIDE pvalue = GL_FALSE One-sided lighting. Only perform lighting calculation on front faces. (default) pvalue= GL_TRUE Two-sided lighting. Perform lighting calculation on both front and back faces

  24. Local or Infinite Viewpoint pname = GL_LIGHT_MODEL_LOCAL_VIEWER pvalue = GL_FALSE Infinite viewpoint (default) pvalue = GL_TRUE Local viewpoint This parameter affects how direction to viewer vector V is calculated for specular reflection. For infinite viewpoint, V is a constant (0, 0, 1) in eye coordinates. For local viewpoint, the viewpoint is placed at the origin in eye coordinates and V is different for each vertex. Secondary Specular Color (Added in OpenGL 1.2. Need glext.h header) pname = GL_LIGHT_MODEL_COLOR_CONTROL pvalue = GL_SINGLE_COLOR Specular color is added to ambient, diffuse and emissive colors before texture mapping. (default) pvalue = GL_SEPARATE_SPECULAR_COLOR Specular color is calculated separately and added after texture mapping.

  25. Select shading model void glShadeModel(Glenum mode) mode: GL_FLAT Flat shading GL_SMOOTH Smooth shading (Gouraud shading)

  26. Specify Vertex Normal void glNormal3{bsifd}(TYPE x, TYPE y , TYPE z) void glNormal3{bsifd}v(TYPE * v) Specify current normal vector • Current normal vector is considered an OpenGL state variable. Therefore the normal vector of a vertex should be specified before its coordinates. • Normal vector should be unit vector. By default, OpenGL does not automatically normalize a normal vector. To enable automatically normalization, use glEnable(GL_NORMALIZE).

  27. Use glNormal*() in primitive rendering glBegin(mode); glNormal*(N0); glVertex*(V0); glNormal*(N1); glVertex*(V1); ... glNormal*(Nn1); glVertex*(Vn1); glEnd();

More Related