How to reference to the components of vec in shader programming?

A vector in shading language can be seen as different types of data. When it is take as color, it has 4 components: r, g, b, a; If take it as position, it has 4 components: x, y, z, w; If take it as texture, it has 4 components: s, t, p, q;
vec4 color = vec4(0.5, 0.2, 0.3, 1.0); //declare a vector named color with 4 dimensional float array
vec3 temp = color.agb;                 //a is alpha value 1.0, g is green 0.2, b is blue 0.3, so temp is assigned to (1.0, 0.2, 0.3)
vec4 tempL = color.aabb;               //tempL is assigned to (1.0, 1.0, 0.3, 0.3)
vec3 tempLL;                           //declare a vector with 3 dimensional float array
tempLL.grb = color.aab;                //tempLL is assigned to (1.0, 1.0, 0.3)

Responses

0 Replies