Metal Coloring Language Programming Guide 18

Source: Internet
Author: User
Tags scalar

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:

    1. Scalar and matrix
    2. Matrices and scalars
    3. Vectors and matrices
    4. Matrices and vectors
    5. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.