Gradients

Gradients



Definitions:


   Gradient:  The rate of change of one variable with respect to

another variable.  Note: This definition is actually the (i, j) components

of a real gradient, but we will call them gradients anyway.



   Vector:  A vector has magnitude and direction (just think of an

arrow) and is made up of (x, y) components (usually called i, j, where i

and j are vectors in the direction of x and y with length one).  So if



   P0 = (X0, Y0, Z0)

   P1 = (X1, Y1, Z1)



then we can make a vector out of P0 and P1.  If we want the vector to point

towards P1, then the vector = P1 - P0 = (X1 - X0)i + (Y1 - Y0)j + 

(Z1 - Z0)k.  If you don't understand vectors, go find a math or physics

book :)



   Cross Product:  The product of two vectors, the result being

another vector and is defined as:



   A = ai + bj + ck

   B = di + ej + fk



   A x B = | i  j  k | = (bf - ce)i - (af - cd)j + (ae - bd)k

           | a  b  c |

           | d  e  f |



So the resulting vector of A x B is (bf - ce)i - (af - cd)j + (ae - bd)k.

The resulting vector is also perpendicular to BOTH vectors and in the

direction of the right-hand rule.



   Equation of a plane:  a(x - x0) + b(y - y0) + c(z - z0) = 0 where

(x0, y0, z0) is any point in the plane and a, b, c are the slopes in each

direction.



   Normal vector:  A vector that is perpendicular to a plane.  The

coefficients of the normal are the same as the coefficients of the plane.

If a plane equals ax + by + cz = d, the normal equals ai + bj + ck.


Magical gradients:

	Gradients aren't really magical, but they seem like it because

they allow us to calculate the change of (su, sv, sz) across scanlines and

edges just ONCE per polygon because they are constant for a whole polygon.

Before, we were calculating the change of (su, sv, sz) for every scanline

with three divides.  Gradients are constant across polygon because our

polygons are flat (no curves) and therefore the slopes in the x and y

direction are constant (Gradients are the slopes in the x and y direction).

So we want to find the slopes of (su, sv, sz)with respect to x and y.  To do 

that, we need to calculate the equation of the plane that the triangle lies

in.  To calculate the equation of the plane, we need to calculate the cross

product of two vectors that make up the triangle (it doesn't matter which

two) and this will give us>

Transfer interrupted!