• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
CS3241 Lab7
 

CS3241 Lab7

on

  • 1,831 views

 

Statistics

Views

Total Views
1,831
Views on SlideShare
1,553
Embed Views
278

Actions

Likes
0
Downloads
10
Comments
0

16 Embeds 278

http://edisonkwtsui.blogspot.com 195
http://edisonkwtsui.blogspot.sg 51
http://edisonkwtsui.blogspot.com.es 15
http://edisonkwtsui.blogspot.co.at 3
http://edisonkwtsui.blogspot.com.br 2
http://edisonkwtsui.blogspot.de 2
http://edisonkwtsui.blogspot.hk 1
http://edisonkwtsui.blogspot.jp 1
http://edisonkwtsui.blogspot.kr 1
http://edisonkwtsui.blogspot.ru 1
http://www.blogger.com 1
http://edisonkwtsui.blogspot.hu 1
http://edisonkwtsui.blogspot.tw 1
http://www.slideshare.net 1
http://www.edisonkwtsui.blogspot.com 1
http://edisonkwtsui.blogspot.in 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    CS3241 Lab7 CS3241 Lab7 Presentation Transcript

    • Lighting & Material
      CS3241 Lab
    • 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
    • Resource
      Lec7_code
      ObjectMaterials.c
      ObjectMaterials2.c
    • 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);
    • 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
    • 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
    • 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
    • Spot light
      Positional light source
      Creating a spot light
      Glfloat position[] = { 0, 1.0, 0, 1.0 };
      GLfloatspot_direction[] = { -1.0, -1.0, 0.0 };
      glLightfv(GL_LIGHT1, GL_POSITION, position);
      glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0);
      glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);
      glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);
      Properties
      GL_SPOT_DIRECTION
      GL_SPOT_EXPONENT
      GL_SPOT_CUTOFF
    • Moving a light
      #1: Setting its position value
      E.g. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
      #2: Using Transformation Matrix
      E.g. glTranslate(), glRotate()
      Glfloat position[4] = {0,0,0,0};
      glPushMatrix();
      glRotatef(rotL, 0, 1, 0);
      glTranslatef(1.5, 1.5, 0);
      glLightfv(GL_LIGHT1, GL_POSITION, position);
      glPopMatrix();
    • Task 1
      Starting Point: ObjectMaterials.c
      Task 1.1
      Turn off light0 by pressing spacebar
      Hint: glDisable(GL_LIGHT0);
      Task 1.2
      Add a new point light source (light1) at [0,0,0]
      Hint:
      GLfloat position[] = { 0.0, 0.0, 0.0, 1.0 };
      glLightfv(GL_LIGHT1, GL_POSITION, position);
      glEnable(GL_LIGHT1);
    • Task 1
      Task 1.3
      Make light1 hover overhead (in a circular motion)
      Hint:
      Glfloat position[4] = {0,0,0,0};
      glPushMatrix();
      glRotatef(rotL, 0, 1, 0);
      glTranslatef(1.5, 1.5, 0);
      glLightfv(GL_LIGHT1, GL_POSITION, position);
      glPopMatrix();
    • Material
    • 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
    • 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();
    • 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
    • Reference
      OpenGL Red book
      http://www.glprogramming.com/red/chapter05.html
      Material
      http://www.cs.utk.edu/~kuck/materials_ogl.htm