GLSL swizzling reads or writes a vector's components in any order in one expression
Swizzling is GLSL’s ability to select, reorder, or duplicate a vector’s components by chaining component letters after a dot: v.x, v.xy, v.zyx, v.rgba. It produces a new vector from any combination of the source’s components, in any order, with repetition allowed, and without temporary variables. The xyzw and rgba letter sets are interchangeable aliases into the same storage (v.r is v.x) — the choice is convention (positional vs. color context). You can also write through a swizzle: v.rg = vec2(1.0) assigns two channels at once. A swizzle must respect the source vector’s length (you cannot read a component it lacks). GLSL is strictly typed, so a length or type mismatch is a compile error, not a silent coercion.
Examples
vec3 col = vec3(0.2, 0.8, 0.4);
vec2 gr = col.gr; // (0.8, 0.2) — reversed
vec3 rrb = col.rrb; // (0.2, 0.2, 0.4) — repeated
col.rg = vec2(1.0); // write through a swizzle
vec3 rev = col.zyx; // reversed order
iResolution.xy extracts width and height from a vec3.
Assessment
Given vec4 v = vec4(1.0, 2.0, 3.0, 4.0), write v.wzyx and v.xxy. Given a vec4 color, write the swizzle extracting RGB as a vec3 and the swizzle reversing the first three components. Explain why v.rr is a vec2.