OpenGL ES 2.0 / GLSL 1.0
Aggregate Operations and Constructors
最終更新:
opengles
-
view
Matrix Constructor Examples [5.4]
- mat2(float) // init diagonal
- mat2(vec2, vec2); // column-major order
- mat2(float, float, float, float); // column-major order
Structure Constructor Example [5.4.3]
- struct light {float intensity; vec3 pos; };
- light lightVar = light(3.0, vec3(1.0, 2.0, 3.0));
Matrix Components [5.6]
Access components of a matrix with array subscripting syntax.
For example:
For example:
- mat4 m; // m represents a matrix
- m[1] = vec4(2.0); // sets second column to all 2.0
- m[0][0] = 1.0; // sets upper left element to 1.0
- m[2][3] = 2.0; // sets 4th element of 3rd column to 2.0
Examples of operations on matrices and vectors:
- m = f * m; // scalar * matrix component-wise
- v = f * v; // scalar * vector component-wise
- v = v * v; // vector * vector component-wise
- m = m +/- m; // matrix component-wise addition/subtraction
- m = m * m; // linear algebraic multiply
- m = v * m; // row vector * matrix linear algebraic multiply
- m = m * v; // matrix * column vector linear algebraic multiply
- f = dot(v, v); // vector dot product
- v = cross(v, v); // vector cross product
- m = matrixCompMult(m, m); // component-wise multiply
Structure Operations [5.7]
Select structure fields using the period (.) operator. Other operators include:
. | field selector |
== != | equality |
= | assignment |
Array Operations [4.1.9]
Array elements are accessed using the array subscript
operator “[ ]”. For example:
operator “[ ]”. For example:
- diffuseColor += lightIntensity[3] * NdotL;