operator of the matrix (Operators on matrix)
Plus, minus operator (+,-) applies to matrix operations. However, the number of matrix rows and columns required to participate in the operation must be equal. The operation process is that the component of each same position of the matrix performs addition or subtraction, and the result is a matrix of the same size. The multiply operator (*) can be applied to:
- Scalar and matrix
- Matrices and scalars
- Vectors and matrices
- Matrices and vectors
- Matrices and matrices
The process of scalar multiplication matrix operations is that this scalar is multiplied by each member of the matrix, and the result is the same size as the matrix that participates in the Operation Matrix. Examples are as follows:
float3x3 M;float A = 3.0f;float3x3 m1 = m * a;// equivant to m1[0][0] = m[0][0] * A;m1[0][1] = m[0][1] * A;m1[0][2] = M[0][2] * a;m1[1][0] = m[1][0] * A;m1[1][1] = m[1][1] * a;m1[1][2] = m[1][2] * A;m1[2][0] = m[2][0] * A;m1[2][1] = m[2][1] * A;m1[2][2] = m[2][2] * A;
Vectors and matrices, or matrix and matrix multiplication to be more complex, the vector operand on the left, the compiler is treated as a line vector, in the right is the compiler as a column vector. The number of columns on the left side of the operand must be equal to the number of rows on the right side, so the multiplication is considered legal. Examples are as follows:
FLOAT3 v;float3x3 m;float3 u = m * v;//equivant to u = v.x * M[0];u + = V.y * M[1];u + = v.z * M[2];
Matrices are multiplied by matrices, for example:
float3x3 m, n, r;r = m * n;// equivant to r[0] = m[0] * N[0].x;r[0] + = m[1] * N[0].y;r[0] + = m[2] * N[0].z;r[1] = M[0] * N[1].x;r[1] + + m[1] * n[1].y;r[1] + + m[2] * n[1].z;r[2] = m[0] * n[2].x;r[2] + = m[1] * n[2].y;r[2] + = m[2] * n[2].z ;
The third chapter is the end of the operator. Translated from: https://developer.apple.com/library/ios/documentation/Metal/Reference/MetalShadingLanguageGuide/operators/ Operators.html#//apple_ref/doc/uid/tp40014364-ch3-sw1
Metal Coloring Language Programming Guide 18