Basic Shading

# Phong Illumination Model

The Phong reflection model (also called Phong illumination or Phong lighting) is an empirical model of the local illumination of points on a surface. In 3D computer graphics, it is sometimes ambiguously referred to as Phong shading, in particular if the model is used in combination with the interpolation method of the same name and in the context of pixel shaders or other places where a lighting calculation can be referred to as “shading”. In this project, I've created a program that takes in a series of command line options to draw 3D shapes with light sources, using this model.

# Program Specifications

- Opens a window that contains an OpenGL rendering area. Important: does not use OpenGL functions to shade! Each pixel is computed individually and rendered onto the 2D window.
- Displays a circular shape that will be shaded using the Phong Illumination Model for point and directional lights.
- The circular shape occupies most of the window. If the window is resized it updates the display so that the shape still occupies most of the window and is still round.
- When space bar is pressed the program exits.
- Finished executable can be found here.

# Command Line Arguments

-ka r g b
This is the ambient color coefficients of the sphere material. The parameters r g b are numbers between 0 and 1 inclusive.
-kd r g b
This is the diffuse color coefficients of the sphere material. The parameters r g b are numbers between 0 and 1 inclusive.
-ks r g b
This is the specular color coefficients of the sphere material. The parameters r g b are numbers between 0 and 1 inclusive.
-sp v
This is the power coefficient on the specular term. It is a number between 0 and max_float.
-pl x y z r g b
This adds a point light to the scene. The x y z values are the location of the light. The r g b values are it's color. Note that the x y z values are relative to the sphere. That is, the center of the sphere is at the origin and the radius of the sphere defines one unit of length. The Y direction is UP, the X direction is to the right on the screen, and the Z direction is "in your face." The r g b value are between 0 and max_float, NOT between 0 and 1 (that is, the r g b values encode the brightness of the light).
-dl x y z r g b
This adds a directional light to the scene. The x y z values are the direction that the light points in. The r g b values are it's color. See -pl for coordinate system notes.
There may be up to 5 point lights and 5 directional lights (10 total) in a scene. The r g b values of 1.0 should be mapped to a display values of 255.
All command line arguments are optional. The default values should be a black sphere with no lights.

Example command-line call (forms the image above with 5 different colored point lights and 5 different colored directional lights):

as1 -ka 0 0 0 -kd 0.55231 0.232 0.5612 -sp 30 -ks 0.262344 0.623421 0.1233 -dl -0.5 0.1234 -0.42 0.235 0.263 0.5 -pl 1.512 1.123 1.132 0.125 0.643 0.6423 -dl 0.125 0.125 0.125 0.125 0.125 0.125 -dl 0.6423 0.346 0.634 0.124 0.623 0.623 -dl 0.12312 0.512 0.1231 0.1231 0.123 0.5612 -dl 0.125 0.1245 0.321 1 1 1 -pl 1.512 1.3123 1.312 0.123 0.6236 0.623 -pl 1.1236 1.1236 1.6234 0.23460 0.3462 0.2346 -pl 1.2346 1.6342 1.423 0.123 0.632 0.6432 -pl 1.1236 1.6423 1.6423 0.123 0.632 0.6432

# Gallery

The following images are all produced from the program given certain command line arguments. Some images show diffuse only shading, specular only shading, combined shading, single/multiple point/direction light sources, and some other cool stuff implemented for fun: (i.e. toon shading, 3D shapes other than spheres).