Unit vector
From Tech Artists Wiki
[edit] What is a Vector? What is a Unit Vector?
A unit vector is defined as:
A vector having a length of one unit.
For you non-3d math people, a vector is:
A quantity possessing both magnitude and direction, represented by an arrow the direction of which indicates the direction of the quantity and the length of which is proportional to the magnitude.
- For more info, see Data Types
Even if you've never written a shader, if you've used a 3D program, you are familiar with vectors- they can also be thought of as points in 3D space. The position [10, 4.2, 2.4] as XYZ is actually a vector. We think of positions as points in space, but they are (more appropriately) really numbers describing a vector from a common origin. The magnitude, or length, of the vector, is the distance of the point to the origin. A diagram should make things more clear:
Above is a vector, or position (at [3,2,0]), and its distance (3.60555). In green is a circle with a radius of 1.
So what happens when we normalize a vector? In simple terms, we find where this circle (sphere in 3d), with a radius of 1, intersects with the line from the origin to the position.
We get a position of [0.5547,0.83205,0]: that is our Normalized/Unit Vector. Its length, whether you use some trig or scripting to check, is 1.
[edit] Why are Unit Vectors Important?
Unit Vectors are important when we are comparing vectors, specifically in Dot Products and Cross Products- basically, when we only want to take direction, and not distance or magnitude, into account. This is especially important for surface and lighting information, such as when we want to calculate the angle between the light or view and surface normal, or when we want to calculate a binormal (since we want all our surface vectors to present just direction).
Categories: Shaders | Math | Rendering
