Events << [Table of Contents] >> Composite
uni.render.Vector
A vector is a multi-dimensional number. Vectors can greatly simplify things when working with 2 and 3 dimensional graphics. They are available in short, int, long, float, double, and real in 2, 3, and 4 dimensional varieties.
Vectors
Operations work just like scalars (single value variables).
auto a = float4(1.0, 0.5, 0.0, 1.0); auto b = float4(0.0, 0.5, 1.0, 1.0); auto avg = (a + b) / 2; // avg is now float4(0.5, 0.5, 0.5, 1.0)
Swizzling lets you to access the components of a vector in any order.
auto a = int4(1, 2, 3, 4); auto b = a.wzyx; // b is now int4(4, 3, 2, 1)
Smearing is like Swizzling, however it also allows repeating of components.
auto a = int4(1, 2, 3, 4); auto c = a.xxy; // c is now int3(1, 1, 2)
Write Masking gives you control of which components are going to be written to.
auto a = int4(1, 2, 3, 4); a.yw = int2(5, 6); // a is now int3(1, 5, 3, 6)
Functions
s norm(v), s norm2(v) and v normalize(v)
Calculates the normal, the squared normal or a normalized version of a vector. A vector is considdered normal when it's largest value is 1.0 or less.
v dot(v1, v2)
Calculates the dot product of 2 vectors.
