Swizzling is a new GL shading language feature that allows you to rearrange components of a vector. For example:
vec4 A (1.0, 2.0, 3.0 , 4.0);
Here, vec4
is represented by the x, y, z, and w component. The result is as follows:
vec4 B = A.xxzz;
Now, B is equivalent to {1.0, 1.0, 2.0, 2.0}
The component access of the vec2/3/4s data type in the shading language can be considered either as vector, color, or texture coordinates or an array:
Form type |
Components |
Example: vec4(1.1, 2.2, 3.3, 4.4 ); |
---|---|---|
Vector |
|
|
Color |
|
|
Texture coordinates |
|
|
Array |
|
|
Swizzling is a mechanism of accessing a component directly using component names. For example: