CS 4621: Lecture 6

Vertex Attributes, Revisited

glMatrix

OperationGLSLglMatrix
Declarationvec3 a;var a = vec3.create();
Creating From Valuesvec3 a = vec3(1.0, 2.0, 3.0);var a = vec3.fromValues(1.0, 2.0, 3.0);
Cloningvec3 a = b;var a = vec3.clone(b);
Copyinga = b;vec3.copy(a, b);
Additiona = b + c;vec3.add(a, b, c);
Scaled Additiona = b + s * c;vec3.scaleAndAdd(a, b, c, s);
Scalinga = s * b;vec3.scale(a, b, s);
Component-wise Multiplicationa = b * c;vec3.multiply(a, b, c); // or vec3.mul()
Dot Productfloat s = dot(a, b);var s = vec3.dot(a, b);
Cross Producta = cross(b, c);vec3.cross(a, b, c);
Normalizationa = normalize(b);vec3.normalize(a, b);
Euclidean Lengthfloat s = length(a);vec3.length(a) // or vec3.len()
Matrix-Vector Multiplicationa = m * b;vec3.transformMat3(a, b, m);
Homogeneous Matrix-Vector Multiplicationvec4 c = m * vec4(b, 1.0); a = c.xyz / c.w;vec3.transformMat4(a, b, m);
Matrix-Matrix Multiplicationa = b * c;mat4.multiply(a, b, c); // or mat4.mul()
Matrix InversionNot available in WebGL 1mat4.invert(a, b);

Matrix Uniforms

The Depth Test

Exhibits