Description
Accessing
a vector can be done using letters as well as standard C selectors.
vec4 a = vec4(1.0, 2.0, 3.0, 4.0);
float posX = a.x;
float posY = a[1];
vec2 posXY = a.xy;
float w = a.w;
Letters
(xyzw), (rgba), (stpq)
used to access vector elements, for position, colour, texture coord
respectively.
Swizzling is
an interesting syntax that allows multiple component access:
vec2 a = vec2(1.0, 2.0);
vec4 b = a.xyxx;
vec3 c = b.zyy;
What is c?
[1 2 2]T
Matrix
selectors
can take one or two arguments:
m[0] – the first column of the matrix
m[2][3]
-- a single element in the matrix