2. Objectives Render illuminated objects by defining the desired light sources and lighting model Define the material properties of the objects being illuminated Manipulate the matrix stack to control the position of light sources
4. Lighting Enable lighting glEnable(GL_LIGHTING); Turn on a light source (0-7) glEnable(GL_LIGHT0…7); Turn off a light source (0…7) glDisable(GL_LIGHT0…7); Setting up light properties e.g. glLightfv(GL_LIGHT0, GL_POSITION, pos);
5. Properties Color GL_AMBIENT GL_DIFFUSE GL_SPECULAR Position GL_POSITION Attenuation (apply to positional light source only) GL_CONSTANT_ATTENUTATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION
6. Point Light E.g. light bulb Positional light Creating Point light (setup a point light at [0,0,0]) Specify by setting position.w = 1 GLfloat position[] = { 0.0, 0.0, 0.0, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, position); x, y, z denote its position in 3D space
7. Directional Light Directional Light Light rays are shot in specified direction from infinite location E.g. Sun Creating Directional light Specify by setting position.w = 0 GLfloat position[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, position); x, y, z denote its direction
13. Material Properties GL_AMBIENT ambient color of material GL_DIFFUSE diffuse color of material GL_AMBIENT_AND_DIFFUSE ambient and diffuse color of material GL_SPECULAR specular color of material GL_SHININESS specular exponent GL_EMISSION emissive color of material
14. Material Using a material Setup material e.g. glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); Using material OpenGL is a state machine Following draw call will use the material specified Example glPushMatrix(); // setup material glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); // draw sphere glutSolidSphere(1.0, 16, 16); glPopMatrix();
15. Task 2 Set the teapot material to Ruby Ruby Ambient: (0.1745, 0.01175, 0.01175, 0.55) Diffuse: (0.61424, 0.04136, 0.04136, 0.55) Specular: (0.727811, 0.626959, 0.626959, 0.55) Shininess: 76.8 Solution in ObjectMaterials2.c
16. Reference OpenGL Red book http://www.glprogramming.com/red/chapter05.html Material http://www.cs.utk.edu/~kuck/materials_ogl.htm