We went over several key details of the rendering pipeline, including clipping and transforming surface normals.
The assignment due Oct 31 will ask you to do a first version of implementing the rendering pipeline, building atop the MISApplet class. You'll need to use the notes from last week's class together with the extra details from this week's class. In the coming few weeks we will add more things to it like fancy shading.
As we discussed in class, clipping along an edge from vertex A to vertex B consists of several successive steps:
Any clipping plane can be characterized by a linear function that attains its zero values at that clipping plane. We want to keep geometry that falls on the half of space where this linear function is negative or zero, and we want to throw out geometry that falls on the half of space where this function in positive.
For example, if we want to keep only geometry that is beyond a near clipping plane, so that z ≤ -ε, then the coefficients [a b c d] of the linear function ax + by + cz + d associated with this clipping plane are:
[0 0 z ε]In other words, the points we want to keep are all (x,y,z) such that:
0x + 0y + z + ε ≤ 0
To clip a triangle, you will want to evaluate the linear equation that generates your clipping
As we discussed in class, a surface normal vector n is a gradient of a linear function, not a point in space. So you need to transform it the way you transform a linear equation, not the way you would transform a point in space.
For this reason, if the transformation matrix of an object is M, so you are transforming each surface point s of that object by the matrix vector product Ms, then you need to transform that surface point's associated normal vector by (M-1)Tn - ie: by the transpose of the inverse of M, where n is [nx,ny,nz,0]T
For the unit cube, vertices of the left and right faces should have normal vectors (-1,0,0) and (1,0,0), respectively. Similarly, vertices of the bottom and top faces should have normal vectors (0,-1,0) and (0,1,0), respectively, and vertices of the back and front faces should have normal vectors (0,0,-1) and (0,0,1), respectively,
For the unit sphere, the surface normal at any vertex is simply the same as the (x,y,z) coordinates that define the location of that vertex in space.
For the unit cylinder, the vertices of the front cap all have surface normal (0,0,1), the vertices of the rear cap all have surface normal (0,0,-1), and the central tube has surface normals(cos θ , sin θ , 0), where θ is the clockwise angle of this vertex around the unit circle in the x,y plane.
As I pointed out in class, in general the surface normal is the normalized (ie: set to unit length) vector in the direction of the gradient (vector valued derivative) of the characteristic function that defines the surface.
For example, the characteristic function of the unit sphere is x2 + y2 + z2 - 1. The sphere surface is just the set of points where this function has value zero. The gradient of this function is given by its partial derivatives in x, y and z, respectively. This produces the vector [2x,2y,2z]. When we normalize the length of this vector we get [x,y,z].