JavaScript EditorFree JavaScript Editor     Ajax Editor 



Main Page
Previous Page
Next Page

5.5. Matrix Functions

Matrix functions can be used within either vertex shaders or fragment shaders (see Table 5.5).

Table 5.5. Matrix functions

Syntax

Description

mat2 matrixCompMult (mat2 x, mat2 y)
mat3 matrixCompMult (mat3 x, mat3 y)
mat4 matrixCompMult (mat4 x, mat4 y)

Multiply matrix x by matrix y component-wise, i.e., result[i][j] is the scalar product of x[i][j] and y[i][j].
Note: To get linear-algebraic matrix multiplication, use the multiply operator (*).


These functions produce the component-wise multiplication of two matrices. For instance, the result of calling matrixCompMult with two 3D matrices x and y looks like this:

mat3 x, y, newmat;
. . .
newmat = matrixCompMult(x, y);


This is not usually what you want if you are using matrices to represent transformation steps. In this case, you would use the multiply operator (*) to perform the linear-algebraic matrix multiplication

mat3 x, y, newmat;
. . .
newmat = x * y;

which performs the following operation:



Previous Page
Next Page




JavaScript EditorAjax Editor     JavaScript Editor