Computer Graphics 10 - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Computer Graphics 10

Description:

the amount of specular light is determined by the smoothness of an object ... The ambient, diffuse, and specular components of the material are multiplied by ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 35
Provided by: kowonDo
Category:

less

Transcript and Presenter's Notes

Title: Computer Graphics 10


1
Computer Graphics 10
  • Lee Byung-Gook

2
Lighting model
  • Definition a set of mathematical equations that
    calculate the color of each pixel that represents
    an object .
  • Tradeoffs must be made between the speed of the
    rendering and the quality of the rendering. In
    general, as the accurately of the model
    approaches real world lighting effects, the
    better the graphics but the slower the rendering

3
Light and object interaction
  • When light strikes an object it is
  • absorbed and converted to heat,
  • reflected off the surface, or
  • refracted (bent) and passed through (e.g., water,
    glass, cellophane)
  • For an accurate lighting model, all three
    interactions must be accounted for, but we will
    concentrate on reflected light.
  • Reflected light is the light that has bounced off
    of an object into our eye (or camera).
  • Reflected light is the light we actually see.

4
Types of reflected light
  • Ambient light
  • general light in a room background light
  • light that has been scattered in so many
    directions that it's source cannot be determined
  • ambient light determines the color of the portion
    of an object not in direct light. This is
    sometimes referred to as an object's "back side,"
    such as the "back side of the moon."
  • the relative position of the object, camera, and
    light sources has no effect on ambient light

5
Types of reflected light
  • Diffuse light
  • light that comes from one specific direction
    scatters in all directions
  • a surface is brighter (scatters more light) if it
    is perpendicular to the light direction
  • diffuse light is what gives an object its
    predominate color and what makes an object look
    "curved" or "rounded."
  • the relative position of the object to the light
    sources determines diffuse lighting.

6
Types of reflected light
  • Specular light
  • light that comes from one specific direction and
    bounces off in one specific direction
  • the amount of specular light is determined by the
    smoothness of an object
  • specular light causes a "hot spot" on shiny
    objects. The "hot spot" moves as the observer
    moves
  • the relative position of the object, camera, and
    light sources determine the amount of specular
    lighting.

7
Lighting Calculations
8
Notation
  • i the light number, as in LIGHT0, LIGHT1,
    LIGHT2, LIGHT7
  • d distance between the light's position and the
    vertex
  • kc GL_CONSTANT_ATTENUATION
  • kl GL_LINEAR_ATTENUATION
  • kq GL_QUADRATIC_ATTENUATION
  • Note if the light is a "spotlight", the
    attenuation factors are ignored
  • spotlight_effect
  • 1, if it is not a spotlight
  • 0, if it is a spotlight and the vertex is outside
    the cone of illumination
  • max v?d,0GL_SPOT_EXPONENT
  • where v is the unit vector that points from the
    spotlight position to the vertex and d is the
    spotlight direction
  • L unit vector from the vertex to the light
    position
  • n normalized normal vector at the vertex
  • s (unit vector between the vertex and the light
    position) (unit vector between the vertex and
    the camera position)

9
Lab 20
  • downloading

10
Shade Model
  • void glShadeModel( GLenum mode )
  • mode A symbolic value representing a shading
    technique. Accepted values are GL_FLAT and
    GL_SMOOTH. The default is GL_SMOOTH.
  • OpenGL only does lighting calculations at the
    vertices of a face (not every pixel of the face).
  • If the shade model is set to GL_FLAT, then the
    color calculated for the last vertex specified
    for the face will be use to color the entire face
  • If the shade model is set to GL_SMOOTH, then the
    color is calculated for every vertex of the face
    and the color of interior pixels of the face are
    interpolated from the colors at the vertices

11
glLightModelf,i
  • These functions set the lighting model
    parameters.
  • void glLightModelf(GLenum pname, GLfloat param)
  • void glLightModeli(GLenum pname, GLint param)
  • pname A lighting model parameter. The following
    values are accepted
  • GL_LIGHT_MODEL_LOCAL_VIEWER
  • GL_LIGHT_MODEL_TWO_SIDE

12
glLightModelf,iv
  • These functions set the lighting model
    parameters.
  • void glLightModelfv(GLenum pname, const
    GLfloatparams)
  • void glLightModeliv( GLenum pname, const GLint
    params)
  • pname A lighting model parameter.
  • The following values are accepted
  • GL_LIGHT_MODEL_AMBIENT
  • GL_LIGHT_MODEL_LOCAL_VIEWER
  • GL_LIGHT_MODEL_TWO_SIDE

13
Light model parameters
  • GL_LIGHT_MODEL_AMBIENT
  • The params parameter contains four integer or
    floating-point values that specify the ambient
    RGBA intensity of the entire scene. Integer
    values are mapped linearly such that the most
    positive representable value maps to 1.0, and the
    most negative representable value maps to 1.0.
    Floating-point values are mapped directly.
    Neither integer nor floating-point values are
    clamped. The default ambient scene intensity is
    (0.2, 0.2, 0.2, 1.0).
  • The ambient of the light model is multiplied by
    the ambient properties of the material. Think of
    it as the desired percentage of the material
    ambient properties
  • The ambient of the material is included for each
    light source along with the global light model
    ambient component. Think of the global ambient
    terms as being the one thing consistent for all
    objects, totally independent of any light source

14
Light model parameters
  • GL_LIGHT_MODEL_LOCAL_VIEWER
  • The params parameter is a single integer or
    floating-point value that specifies how specular
    reflection angles are computed. If params is 0
    (or 0.0), specular reflection angles take the
    view direction to be parallel to and in the
    direction of the z axis, regardless of the
    location of the vertex in eye coordinates.
    Otherwise specular reflections are computed from
    the origin of the eye coordinate system. The
    default is 0.

15
Light model parameters
  • if GL_FALSE, the light vector used in the
    calculations is always the same. This provides
    faster rendering but poorer quality rendering
  • if GL_TRUE, a new light vector is calculated for
    each color vertex calculation. This provides
    better quality rendering but at a slower speed

16
Light model parameters
  • GL_LIGHT_MODEL_TWO_SIDE
  • The params parameter is a single integer or
    floating-point value that specifies whether one-
    or two-sided lighting calculations are done for
    polygons. It has no effect on the lighting
    calculations for points, lines, or bitmaps. If
    params is 0 (or 0.0), one-sided lighting is
    specified, and only the front material parameters
    are used in the lighting equation. Otherwise,
    two-sided lighting is specified. In this case,
    vertices of back-facing polygons are lighted
    using the back material parameters, and have
    their normals reversed before the lighting
    equation is evaluated. Vertices of front-facing
    polygons are always lighted using the front
    material parameters, with no change to their
    normals. The default is 0.

17
Light model parameters
  • if GL_FALSE, the back side of faces will receive
    no diffuse or specular light. (only ambient
    light)
  • if GL_TRUE, the back side of faces is rendered
    just like the front side of faces. (When the back
    side is rendered, its normal vector is taken as
    the reverse of the normal vector for the front
    side.)

18
Lab 21
  • downloading

19
glMaterialf,i
  • These functions specify material parameters for
    the lighting model.
  • void glMaterialf( GLenum face, GLenum pname,
    GLfloat param ) void glMateriali( GLenum face,
    GLenum pname, GLint param )
  • face The face or faces that are being updated.
    Must be one of GL_FRONT, GL_BACK, or
    GL_FRONT_AND_BACK.
  • pname The single-valued material parameter of
    the face or faces being updated. Must be
    GL_SHININESS.
  • param The value that parameter GL_SHININESS
    will be set to.

20
glMaterialf,Iv
  • These functions specify material parameters for
    the lighting model.
  • void glMaterialfv(GLenum face,GLenum pname,const
    GLfloat params)
  • void glMaterialiv(GLenum face,GLenum pname,const
    GLint params )
  • face The face or faces that are being updated.
    Must be one of GL_FRONT, GL_BACK, or
    GL_FRONT_AND_BACK.
  • Pname The material parameter of the face or
    faces being updated. The parameters that can be
    specified using glMaterial, and their
    interpretations by the lighting equation, are as
    follows
  • GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION,
  • GL_SHININESS,GL_AMBIENT_AND_DIFFUSE,
  • GL_COLOR_INDEXES

21
Material properties
  • Percentages
  • Treat each value used to specify the material
    properties as a percentage
  • 0.0 means 0 color
  • 1.0 means 100 color

22
Material properties
  • Material / Light interaction
  • The ambient, diffuse, and specular components of
    the material are multiplied by the corresponding
    properties of light
  • The ambient color is typically a shade of gray,
    since the human eye cannot see colors in low
    light. (Shades of gray have equal values of red,
    green and blue.) e.g., (0.3, 0.3, 0.3)
  • The diffuse values determine the color (hue) of
    an object. For example, if you want a red ball,
    set the diffuse values to (1.0, 0.0, 0.0).

23
Material properties
  • The specular values determine the color (hue) of
    the hotspot (highlight). Typically the light
    sources are white, so these values would
    typically be a shade of white (i.e., all values
    equal), such as (0.8, 0.8, 0.8).
  • The emission values are added directly to the
    color calculations without any consideration of
    the light sources or the object's orientation. If
    the emission values are large (e.g., gt 0.5), the
    color of every pixel will typically become
    saturated (1.0) and the object will lose all
    shading.

24
glLightf,i
  • void glLightf( GLenum light, GLenum pname,
    GLfloat param ) void glLighti( GLenum light,
    GLenum pname, GLint param )
  • light A light. The number of lights depends on
    the implementation, but at least eight lights are
    supported. They are identified by symbolic names
    of the form GL_LIGHTi where 0 i lt
    GL_MAX_LIGHTS.
  • pname A single-valued light source parameter
    for light. The following values are accepted.
    GL_SPOT_EXPONENT,GL_SPOT_CUTOFF,
  • GL_CONSTANT_ATTENUATION,
  • GL_LINEAR_ATTENUATION,
  • GL_QUADRATIC_ATTENUATION
  • param The value to which parameter pname of
    light source light will be set.

25
glLightf,iv
  • void glLightfv( GLenum light, GLenum pname, const
    GLfloat params )
  • void glLightiv( GLenum light, GLenum pname, const
    GLint params )
  • pname A light source parameter for light. The
    following values are accepted
  • GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,
  • GL_POSITION ,GL_SPOT_DIRECTION,
  • GL_SPOT_EXPONENT,GL_SPOT_CUTOFF,
  • GL_CONSTANT_ATTENUATION
  • GL_LINEAR_ATTENUATION,
  • GL_QUADRATIC_ATTENUATION
  • params A pointer to the value or values to
    which parameter pname of light source light will
    be set.

26
Light types
  • Directional light
  • a light infinitely far away from the scene
  • all light rays are parallel
  • for example, the sun
  • has a homogeneous coordinate (w) of 0
  • for example (3.0, 4.0, 2.0, 0.0)

27
Light types
  • Positional light
  • a light inside the scene
  • the light rays go in different directions
  • for example, a table lamp
  • has a homogeneous coordinate (w) of 1
  • for example (3.0, 4.0, 2.0, 1.0)

28
Light types
  • Spot light
  • a positional light with a restricted cone of
    illumination
  • GL_SPOT_CUTOFF determines the size of the cone,
    as in the following diagram

29
Light types
  • The intensity of the beam varies, depending on
    the angle between the GL_SPOT_DIRECTION and the
    light ray. Light rays along the spot direction
    are calculated at 100 intensity, while the light
    rays at the periphery of the cone are at lower
    intensities.
  • A cos curve raised to the GL_SPOT_EXPONENT power
    is used to calculated the intensity of light at
    various positions within the cone of
    illumination. All positions outside of the cone
    get 0 light

30
Positioning lights
  • Directional lights have no position, only
    direction
  • The position and direction of a positional light
    source is multiplied by the current
    transformation matrix. It is very important that
    the camera of a scene be established before the
    position and direction of lights are specified
  • The correct ordering of statements to place
    positional lights within a scene is
  • Clear buffer (glClear())
  • Clear transformations (glLoadIdentity())
  • Set up camera transformations
  • Set the light position (and direction if it is a
    spotlight)
  • Draw the objects in the scene.

31
Dr. Nate Robins

32
Notes
  • OpenGL is a state machine. Therefore, if a
    parameter value never changes during the
    execution of a program, the value should only be
    set once. This increases the speed of rendering
  • For example, if the linear attenuation of a light
    source never changes, set the attenuation once in
    your "init" function
  • void init()
  • glLightf(GL_LIGHT0, GL_CONSTANT_ATTENTUATION,
    1.0)
  • glLightf(GL_LIGHT0, GL_LINEAR_ATTENTUATION,
    0.0)
  • glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENTUATION,
    0.0)

33
Notes
  • The exception to this "state machine" concept is
    lighting. The position and direction of light
    sources are multiplied by the current transform
    when they are specified. The position and
    direction of a light source needs to be specified
    only once if the camera never moves (and the
    camera was set up before they are specified).
  • OpenGL only applies the light model calculations
    to the vertices of a polygon. To increase the
    accuracy of the lighting effects, you must
    decrease the sizes of the polygons that define
    your objects. (Which makes rendering slower.)

34
Notes
  • The shading calculations are very depend on a
    correct normal vector defined for each face. The
    face normal vector is expected to be defined in
    normalized form (of unit length).
  • When an object is transformed by the current
    transformation matrix, both its vertices and
    normal vectors are transformed. If any scaling is
    part of the current transformation, the normal
    vectors will become un-normalized
  • You need to enable the feature that will
    re-normalize the normal vectors if
  • Your normal vectors were not initially specified
    in normal form
  • Your transformations include scaling
  • glEnable(GL_NORMALIZE)
Write a Comment
User Comments (0)
About PowerShow.com