A direction is specified by three component values, x, y, z. The same (x,y,z) triple also defines a 3D space point, say P; the direction (x,y,z) is any direction paralled to OP, where O is the origin of the coordinate system.
Here are some examples,
// Positive x direction is specified by (1, 0, 0), or (1.1, 0, 0), or (0.1, 0, 0) // In our standard graphics coordinate system, a light source right behind us has a direction (0,0,1). // In our standard graphics coordinate system, a light source of direction (1,1,1) is behind us, above us, and to the right of us.
// Another way to specify a direction is by the 3 angles it makes with 3 axis direction. // Direction (1, 0, 0) makes 0 angle with positive x direction, and 90 deg with both y and z directions. // Direction (1, 1, 1) makes the same angles to all 3 positive axis directions, which is acos( 1/sqrt(3) ). // A general equation is, cos( agnle_to_x_axis ) = x / sqrt(x*x + y*y + z*z); cos( agnle_to_y_axis ) = y / sqrt(x*x + y*y + z*z); cos( agnle_to_z_axis ) = z / sqrt(x*x + y*y + z*z);
The perceived color of a vertex is related to the color of the object (material property, or material color), and the lighting condition.
In the simplest situation, we assume the light source is at infinite, and can be specified by its direction. And the lighting is of a diffuse type,
//In diffuse lighting, the perceived color is the material color, scaled by the cosine of the angle between the light //source direction and the normal direction at the surface point. if( angle_between_light_direction_and_normal > 180 ) perceived_color = background_color; else perceived_color = material_color * cos( angle_between_light_direction_and_normal );
Suppose the light source is at (0, 0, +infinite). Then the angle between a normal and the light is the angle the normal direction makes with the positive z-direction. The following computes the perceived the color of a vertex given the surface normal at that point.
RGB compute_lighting(Vector const& normal, RGB const& material_color) { if(normal.z < 0) return background_color; else { float scale = normal.z / sqrt(normal.x * normal.x + normal.y * normal.y + normal.z * normal.z); return material_color * scale; } }
1.3.6