1 / 18

Computer Graphic And Vision

Computer Graphic And Vision. Computer Science Department 2014-2015. Lighting. Lighting in OpenGL. In the OpenGL lighting model, the light in a scene comes rom several light sources that can be individually turned on and off .

Télécharger la présentation

Computer Graphic And Vision

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. Computer Graphic And Vision Computer Science Department 2014-2015 Lighting

  2. Lighting in OpenGL • In the OpenGL lighting model, the light in a scene comes rom several light sources that can be individually turned on and off. • The light sources have an effect only when there are surfaces that absorb and reflect light • Each surface is assumed to be composed of a material with various properties

  3. Using Depth Buffer (z-buffer) • „A depth buffer works by associating a depth, or distance, from the view plane (usually the near clipping plane), with • To clear the depth buffer: • glClear(GL_DEPTH_BUFFER_BIT); • To enable the using of depth buffer: • glEnable(GL_DEPTH_TEST); • The depth buffer is needed when we use lighting to determine the distance from the light source.

  4. Enabling Lighting • To enable lighting we should use: • glEnable(GL_LIGHTING); • To disable lighting: • glDisable(GL_LIGHTING); • We need to enable each light source that we define: • glEnable(GL_LIGHT0); GL_LIGHT0 GL_LIGHT1 ... GL_LIGHT7

  5. Lighting in OpenGL

  6. Creating Light Sources • The command used to specify all properties of lights is glLight*(); • voidglLight{if}v(GLenum light, GLenumpname, TYPE[]param); GL_LIGHT0 GL_LIGHT1 ... GL_LIGHT7 GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_POSITION A pointer to a group of Values Float[] p = {1.0f ,.0f ,.0f 1.0f};

  7. Default Values for pname Parameter of glLight*()

  8. Creating Light Sources • The default values listed for GL_DIFFUSE and GL_SPECULAR in apply only to GL_LIGHT0. • For other lights, the default value is (0.0, 0.0, 0.0, 1.0) for bothGL_DIFFUSE and GL_SPECULAR. • If the fourth value is zero the light source position is far and can not be determined (first three values determine the direction of the light), if it is non-zero the first three values determine the position of the light.

  9. Example

  10. Example LitSpin.java

  11. Materials Color • Like lights, materials have different ambient, diffuse, and specular colors. • For a light, the numbers correspond to a percentage of full intensity for each color. • If R = G = B =1.0, the light is the brightest possible white • If the values are 0.5, the color is still white at half intensity (gray) • If R=G=1 and B=0, the light appears yellow • For materials, the numbers correspond to the reflected proportions of those colors • If R=1, G=0.5, and B=0 for a material, that material reflects all the incoming red light, half the incoming green, and none of the incoming blue light.

  12. Creating Light Sources • To change the material properties we can use glMaterial*(). • voidglMaterial{if}[v](GLenum face, GLenum pname, TYPE *param); GL_FRONT GL_BACK GL_FRONT_AND_BACK GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_EMISSION GL_SHININESS A pointer to a group of Values Float[] p = {1.0f ,.0f ,.0f 1.0f};

  13. Default Values for pname Parameter of glMaterial*()

  14. Control the size and brightness of the highlight [0.0 - 128] Example SphereWithLight.java

  15. Ambient ,Diffuse and Specular

  16. Emission • By specifying an RGBA color for GL_EMISSION, we can make an object appear to be giving off light of that color. Sphere_Light_Move_Emision.java Sphere_Light_Move.java

  17. Controlling a Light's Position and Direction • A light source is subject to the same matrix transformations as a primitive when glLight*() is called the position or direction is transformed by the current modelview matrix. • The following three different effects change the point in the program at which the light position is set, relative to modeling or viewing transformations: • A light position that remains fixed. • A light that moves around a stationary object. • A light that moves along with the viewpoint.

  18. More Info. • OpenGL programming Guide :The Official Guide to Learning OpenGL (red book) • Chapter 5: Lighting

More Related