-
Notifications
You must be signed in to change notification settings - Fork 20
2. Swizzling
elect edited this page Aug 5, 2017
·
3 revisions
Shader languages like GLSL often feature so-called swizzle expressions, which
may be used to freely select and arrange a vector's components. For example,
variable.x
, variable.xzy
and variable.zxyy
respectively form a scalar,
a 3D vector and a 4D vector. The result of a swizzle expression in GLSL can be
either an R-value or an L-value. Swizzle expressions can be written with
characters from exactly one of xyzw
.
val A = Vec2()
var B = Vec2()
B.yx = A.wy
B = A.xx
Vec2 A = Vec2();
Vec2 B = Vec2();
B.yx(A.wy)
B = (Vec2) A.xx()
There are also alias available, such as rgba
and stpq
, but not swizzling
on them yet at the moment.