Lighting & Material<br />CS3241 Lab<br />
Objectives<br />Render illuminated objects by defining the desired light sources and lighting model<br />Define the materi...
Resource<br />Lec7_code<br />ObjectMaterials.c<br />ObjectMaterials2.c<br />
Lighting<br />Enable lighting <br />glEnable(GL_LIGHTING);<br /> Turn on a light source (0-7)<br />glEnable(GL_LIGHT0…7);<...
Properties<br />Color<br />GL_AMBIENT<br />GL_DIFFUSE<br />GL_SPECULAR<br />Position<br />GL_POSITION<br />Attenuation <br...
Point Light<br />E.g. light bulb<br />Positional light<br />Creating Point light (setup a point light at [0,0,0])<br />Spe...
Directional Light<br />Directional Light<br />Light rays are shot in specified direction from infinite location<br />E.g. ...
Spot light<br />Positional light source<br />Creating a spot light<br />Glfloat position[] = { 0, 1.0, 0, 1.0 }; <br />GLf...
Moving a light<br />#1: Setting its position value<br />E.g. glLightfv(GL_LIGHT0, GL_POSITION, light_position); <br />#2: ...
Task 1<br />Starting Point: ObjectMaterials.c<br />Task 1.1<br />Turn off light0 by pressing spacebar<br />Hint: glDisable...
Task 1<br />Task 1.3<br />Make light1 hover overhead (in a circular motion)<br />Hint:<br />Glfloat position[4] = {0,0,0,0...
Material<br />
Material<br />Properties<br />GL_AMBIENT<br />ambient color of material<br />GL_DIFFUSE<br />diffuse color of material<br ...
Material<br />Using a material<br />Setup material<br />	e.g. glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); <br />Using mate...
Task 2<br />Set the teapot material to Ruby<br />Ruby<br />Ambient: (0.1745, 0.01175, 0.01175, 0.55)<br />Diffuse: (0.6142...
Reference<br />OpenGL Red book<br />http://www.glprogramming.com/red/chapter05.html<br />Material<br />http://www.cs.utk.e...
Upcoming SlideShare
Loading in …5
×

CS3241 Lab7

1,708 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,708
On SlideShare
0
From Embeds
0
Number of Embeds
295
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

CS3241 Lab7

  1. 1. Lighting & Material<br />CS3241 Lab<br />
  2. 2. Objectives<br />Render illuminated objects by defining the desired light sources and lighting model<br />Define the material properties of the objects being illuminated<br />Manipulate the matrix stack to control the position of light sources<br />
  3. 3. Resource<br />Lec7_code<br />ObjectMaterials.c<br />ObjectMaterials2.c<br />
  4. 4. Lighting<br />Enable lighting <br />glEnable(GL_LIGHTING);<br /> Turn on a light source (0-7)<br />glEnable(GL_LIGHT0…7);<br />Turn off a light source (0…7)<br />glDisable(GL_LIGHT0…7);<br />Setting up light properties<br /> e.g. glLightfv(GL_LIGHT0, GL_POSITION, pos);<br />
  5. 5. Properties<br />Color<br />GL_AMBIENT<br />GL_DIFFUSE<br />GL_SPECULAR<br />Position<br />GL_POSITION<br />Attenuation <br />(apply to positional light source only)<br />GL_CONSTANT_ATTENUTATION<br />GL_LINEAR_ATTENUATION<br />GL_QUADRATIC_ATTENUATION<br />
  6. 6. Point Light<br />E.g. light bulb<br />Positional light<br />Creating Point light (setup a point light at [0,0,0])<br />Specify by setting position.w = 1<br />GLfloat position[] = { 0.0, 0.0, 0.0, 1.0 }; <br />glLightfv(GL_LIGHT0, GL_POSITION, position); <br />x, y, z denote its position in 3D space<br />
  7. 7. Directional Light<br />Directional Light<br />Light rays are shot in specified direction from infinite location<br />E.g. Sun<br />Creating Directional light<br />Specify by setting position.w = 0<br />GLfloat position[] = { 1.0, 1.0, 1.0, 0.0 }; <br />glLightfv(GL_LIGHT0, GL_POSITION, position); <br />x, y, z denote its direction<br />
  8. 8. Spot light<br />Positional light source<br />Creating a spot light<br />Glfloat position[] = { 0, 1.0, 0, 1.0 }; <br />GLfloatspot_direction[] = { -1.0, -1.0, 0.0 }; <br />glLightfv(GL_LIGHT1, GL_POSITION, position); <br />glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0);<br />glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);<br />glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0); <br />Properties<br />GL_SPOT_DIRECTION<br />GL_SPOT_EXPONENT<br />GL_SPOT_CUTOFF<br />
  9. 9. Moving a light<br />#1: Setting its position value<br />E.g. glLightfv(GL_LIGHT0, GL_POSITION, light_position); <br />#2: Using Transformation Matrix<br />E.g. glTranslate(), glRotate()<br />Glfloat position[4] = {0,0,0,0};<br />glPushMatrix();<br />glRotatef(rotL, 0, 1, 0);<br />glTranslatef(1.5, 1.5, 0);<br />glLightfv(GL_LIGHT1, GL_POSITION, position); <br />glPopMatrix();<br />
  10. 10. Task 1<br />Starting Point: ObjectMaterials.c<br />Task 1.1<br />Turn off light0 by pressing spacebar<br />Hint: glDisable(GL_LIGHT0);<br />Task 1.2<br />Add a new point light source (light1) at [0,0,0]<br />Hint:<br />GLfloat position[] = { 0.0, 0.0, 0.0, 1.0 }; <br />glLightfv(GL_LIGHT1, GL_POSITION, position);<br />glEnable(GL_LIGHT1);<br />
  11. 11. Task 1<br />Task 1.3<br />Make light1 hover overhead (in a circular motion)<br />Hint:<br />Glfloat position[4] = {0,0,0,0};<br />glPushMatrix();<br />glRotatef(rotL, 0, 1, 0);<br />glTranslatef(1.5, 1.5, 0);<br />glLightfv(GL_LIGHT1, GL_POSITION, position); <br />glPopMatrix();<br />
  12. 12. Material<br />
  13. 13. Material<br />Properties<br />GL_AMBIENT<br />ambient color of material<br />GL_DIFFUSE<br />diffuse color of material<br />GL_AMBIENT_AND_DIFFUSE<br /> ambient and diffuse color of material<br />GL_SPECULAR<br />specular color of material<br />GL_SHININESS<br />specular exponent<br />GL_EMISSION<br />emissive color of material<br />
  14. 14. Material<br />Using a material<br />Setup material<br /> e.g. glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); <br />Using material<br />OpenGL is a state machine<br />Following draw call will use the material specified<br />Example<br />glPushMatrix(); <br /> // setup material<br />glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); <br /> // draw sphere<br />glutSolidSphere(1.0, 16, 16); <br />glPopMatrix();<br />
  15. 15. Task 2<br />Set the teapot material to Ruby<br />Ruby<br />Ambient: (0.1745, 0.01175, 0.01175, 0.55)<br />Diffuse: (0.61424, 0.04136, 0.04136, 0.55)<br />Specular: (0.727811, 0.626959, 0.626959, 0.55)<br />Shininess: 76.8<br />Solution in ObjectMaterials2.c<br />
  16. 16. Reference<br />OpenGL Red book<br />http://www.glprogramming.com/red/chapter05.html<br />Material<br />http://www.cs.utk.edu/~kuck/materials_ogl.htm<br />

×