9. Illuminated surfaces

Brock University
COSC 3P98 Computer Graphics
Instructor: Brian J. Ross



Illuminated surfaces


Important factors in illumination


Ambient light


Diffuse reflection


Diffuse reflection


Specular reflection


Specular reflection


Final lighting (almost)

I = Ia * Ra + Is * (Rd* cos A + Rs * (cos B)^f)


Improvements


Lighting & shading


Lighting & shading

  • When you do this interpolation for R, G, B, you end up with a "blend" of colours between start and end pixel colours
  • You can see this blend on an RGB colour cube: take two colours (points) on the cube, and the line between them is the blending you will get


    Flat shading


    Gouraud Shading


    Gouraud


    Phong Shading


    Examples of illumination/shading models

    Gouraud vs Phong:

    Youtube video


    OpenGL: shading

     glutInitDisplayMode(GLUT_RGB |...);  (must be in RGB mode!)
    ...
    glShadeModel(GL_SMOOTH); (default) OR glShadeModel(GL_FLAT); 
    glColour3f(1.0, 0.0, 0.0);
    glColor4ubv(bluevecf); /* unsigned byte bluevecf[4]; */


    OpenGL: Lighting


    Surface normals

    static float np[3] = {0, .7071, .7071};
    static float vp[3] = {0, 0, -1};
    
    glBegin(GL_POLYGON);
       glNormal3fv(np);
       glVertex3fv(vp);
        Add more normals, vertices below...
    glEnd();


    OpenGL: defining lights

    glLight{if}(GLenum light, GLenum pname, TYPE param);

     Parameter Default Meaning
    GL_AMBIENT (0.0, 0.0, 0.0, 1.0) ambient intensity
    GL_DIFFUSE (1.0, 1.0, 1.0, 1.0) diffuse intensity
    GL_SPECULAR (1.0, 1.0, 1.0, 1.0) specular intensity
    GL_POSITION (0.0, 0.0, 1.0, 0.0) (x, y, z, w) position of light
    GL_SPOT_DIRECTION (0.0, 0.0, -1.0) direction of spot light

    GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0};
    GLfloat light_diffuse[] = {0.9, 0.5, 0.3, 1.0};
    GLfloat light_specular[] = {0.9, 0.1, 0.1, 1.0};
    GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
    
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glEnable(GL_LIGHTING);   /* turns on lighting */
    glEnable(GL_LIGHT0);     /* turns on light 0  */

    OpenGL: Lighting model

    GLfloat lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0};
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
    glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); (default)


    OpenGL: materials

    glMaterial{if}[v](GLenum face, GLenum pname, TYPE param);

     Parameter Default Meaning
    GL_AMBIENT (0.2, 0.2, 0.2, 1.0) ambient colour of material
    GL_DIFFUSE (0.8, 0.8, 0.8, 1.0) diffuse colour
    GL_SPECULAR (0.0, 0.0, 0.0, 1.0) specular colour
    GL_SHININESS 0.0 specular exponent

    GLfloat mat_ambient = {0.7, 0.7, 0.7, 1.0};
    GLfloat mat_diffuse = {0.8, 0.2, 0.5, 1.0};
    GLfloat mat_specular = {0.0, 0.5, 0.0, 1.0};
    
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    
    draw_my_object();  /* will be drawn with above material */
    


    OpenGL: some example materials

    GLfloat mat_ambient = {0.1, 0.1, 0.1, 0.7};
    GLfloat mat_diffuse = {0.0, 0.37, 0.17, 0.7};/* note: G component (2nd) is strongest */
    GLfloat mat_specular = {0.5, 0.5, 0.5, 0.7};
    GLfloat mat_shininess = {0.30};
    
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    GLfloat mat_emission = {0.0, 0.4, 0.1, 0.0};
    glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
    


    OpenGL: lighting and performance


    OpenGL: display lists


    References



    Back to COSC 3P98 index

    COSC 3P98 Computer Graphics
    Brock University
    Dept of Computer Science
    Copyright © 2023 Brian J. Ross (Except noted figures).
    http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/illum/
    Last updated: November 14, 2023