Swizzling

Your Answer
Correct Answer
Waiting...

Swizzling — beyond being a great name — is a nice feature in GLSL for accessing the properties of a vector.

You can get a single float from a vector using .r, .g, .b or .a. For example:

But you can also create new vectors from combinations of their components like so:

In addition to .rgba, you can also use .xyzw. These are equivalent, but if you're using the vector for a position instead of a color it's easy to reason about when using the latter.

In this exercise, you can use the sw variable to create new colors:

P.S. don't forget to use semicolons at the end of each line: they're required in GLSL :')