RGBA HSB OpenGL Illumination Model

Source: Internet
Author: User
Tags emit

RGBA HSB The HSV color model corresponds to the painter's method of color matching. The painter uses a method of changing the color and color depth to obtain different shades of color from a solid color. This is done by adding white to a solid color to change the color consistency, adding black to change the color depth, adding different proportions of white, and black to get different shades of color.

1. Several concepts

      ambient light-the light that has been reflected many times is called ambient light and cannot determine its initial orientation, but when a particular light source is closed, they disappear.
    • scattered light-from the same direction, after the surface of the object, will be reflected evenly in all directions, so that the brightness of the surface is the same regardless of the direction in which it is viewed.
    • specular light-from a particular direction, is also reflected in a specific direction. Specular reflectance is associated with it.

  • OpenGL, when simulating a light source, assumes that the emitted light is decomposed into r,g,b three components, so that for each light source, the amount of red, green, and blue light emitted can be used to describe it, whereas for a surface material, it can be described using the ratio of red light reflected in each direction, green and blue.
  • The light source affects only the surfaces that absorb or reflect light, each of which is made up of materials with various properties, the material itself may emit light (such as car headlights), scatter incident light in all directions (normal), or reflect incident light in a particular direction (such as mirrors and other smooth surfaces).
  • The material's ambient, scattering, and specular colors determine the reflectivity of the material to ambient light, scattered light, and specular light. Multiplies the ambient light reflectance of the material by the ambient light component of each light source, and multiplies the scattered light reflectance from the scattered light components. ; The specular reflectance is multiplied by the specular reflection light. The reflectivity of the material to ambient light and scattered light determines its color, and the reflectivity is often equal, and the specular color of the material is usually white or gray (ie (1.0,1.0,1.0)). Therefore, the color of the specular reflection point is generally the color of the specular light in the light source.
  • The OpenGL illumination model divides the light into four separate parts: ambient light, scattered light, specular light, and emitted light, which are calculated separately and superimposed on the four kinds of light.
  • The r,g,b value of the light represents the strength of each component, and the r,g,b value of the material represents the reflection scale of the material to the corresponding component.
  • There is no attenuation of three rays in the directional light source, but there is attenuation in the locating light source.
  • The irradiated object does not emit light to other objects.

    • Defines the normal vector for each vertex of an object, which determines the orientation of the object relative to the light source.
    • Create and select one or more lights, and set the location of the light.
    • Create and select a lighting model that defines the level of global ambient light and the actual location of the observer point (for lighting calculations).
    • Enable lighting.
    • Sets the material properties of the object in the scene.

  • Specify normal vectors for vertices: GLNORMAL3FV (n0); GLVERTEX3FV (V0);
  • To create a light source, specify the location:
    GLLIGHTFV (gl_light0,gl_position,light_position);
    GLLIGHTFV (gl_light0,gl_ambient,light_ambient); Note that the default value for Gl_position is (0,0,1,0), which defines a directional light source that points to a negative z-axis.
  • Select the lighting model: it includes four items, that is, the global ambient light intensity, whether the observation point is near the scene or infinity, if the same illumination is computed on the front and back of the object, and whether the specular color is separated from the ambient color and the scattering color, and applied after the texture operation. function has
    GLLIGHTMODELFV (gl_light_model_ambient,lmodel_ambient); GLLIGHTMODELFV (gl_light_model_local_viewer,lmodel_viewer) ..., where near or farsighted points only affect the calculation of the specular area.
  • Enable illumination: Glenable (gl_lighting); glenable (GL_LIGHT0);
  • To set material properties:
    With GLMATERIALFV (Glenum face, glenum pname, type* param) function set gl_ambient, Gl_diffuse, Gl_ambient_and_diffuse, Gl_specular, Gl_shinness, gl_emission equivalent.

  • The ambient light of the light source defaults to (0.0,0.0,0.0,1.0), i.e. no ambient light.
  • The scattered light of the light source defaults to (1.0,1.0,1.0,1.0), which is the presence of white scattered light.
  • The ambient reflection light of the light source has two cases, one corresponds to the light source gl_lignt0, its gl_specular is (1.0,1.0,1.0,1.0), which is the white light, and the other corresponds to the other light source, whose default value is (0.0,0.0,0.0,0.0). In general, The gl_specular of the light source should be the same as the Gl_diffuse value.
  • By default, the position light emits light in all directions, but it can be set as a spotlight so that it glows within the cone.
  • In the light model, the global ambient light defaults to (0.2,0.2,0.2,1.0), that is, there is a faint white light; the viewpoint position defaults to 0.0 or gl_false, i.e. infinity; By default, single-sided illumination, or gl_light_model_two_side to 0.0 or gl_ FALSE (to enable double-sided illumination when there is a cut on an object); By default, specular color is done before the texture map, that is, the value of Gl_light_model_color_control is Gl_single_color.
  • Default value for material properties: gl_ambient (0.2,0.2,0.2,1.0); Gl_diffuse (0.8,0.8,0.8,1.0); Gl_specular (0.0,0.0,0.0,1.0); Gl_shinness 0.0; Gl_emission (0.0,0.0,0.0,1.0).

  • Color when vertex is illuminated: vertex color = emitted light color of vertex +
    Ambient light properties for global ambient light and materials +
    Ambient light, scattered light and specular reflection light in each light source
    When the light calculation is performed, the color value (RGBA mode) is truncated to [0.0,1.0].
  • The emitted light color of the vertex is the gl_emission value in GLMATERIALFV ().
  • The reflected global ambient light = GLLIGHTMODELFV () specifies the gl_ambient value specified by the gl_ambient * GLMATERIALFV ().
  • Contribution of the light Source = attenuation factor * Spotlight effect * (ambient light + scatter light + specular light); where ambient light = GLLIGHTFV () specifies the gl_ambient of gl_ambient * GLMATERIALFV ();
    The scattering light calculation needs to consider the illumination angle of the light, the scattering component of the light source and the scattering property of the material:
    Scattered light =
    (Max{l dotproduct n,0} * light_diffuse * material_diffuse), L is the vertex-to-light unit vector, and n is the unit normal vector of the vertex.
    Specular light terms also depend on the light's angle of illumination. if (L dotproduct N) <=0; vertices will not have specular light, otherwise specular light depends on the following factors:
    1) the unit normal vector N of the vertex.
    2) The sum of the unit vectors that point to the light source from the vertex and the units that point to the viewpoint from the vertex, where the light model is assumed to be short-sighted, otherwise the second unit vector is (0,0,1), and then the added vector is normalized and recorded as S.
    3) Specular reflectance index (GLLIGHTFV () specified gl_shinness).
    4) The specular light component of the light source (GLLIGHTFV () specifies the gl_specular, generally the same as its gl_diffuse).
    5) Specular properties of the material (GLMATERIALFV () specified gl_specular).
    Calculation formula: (Max{s dotproduct n,0}) ^shinness * light_specular * material_specular.
Top
0
Step
0

RGBA HSB OpenGL Illumination Model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.