[]-operator is the array member selection operator and can also be used to access a vector.
The equivalent glsl code to
red = texture.Sample(sampler, uv)[x];
is
float red = texture(sampler, uv)[x];
texture
returns a value of type vec4
(e.g. for sampler2D
). The components of the vector can be accessed by the index operator. Since x
is the index, it has to be a variable or constant with an integral data type. The vector has 4 components (.x
, .y
, .z
, .w
respectively .r
, .g
, .b
, .a
), so the value of x
has to be 0, 1, 2 or 3.
texture(sampler, uv)[0]
is the same as texture(sampler, uv).r
. See also GLSL- Swizzling.