In HLSL scalar types such as float
and half
are one-dimensional vectors which have the only .x
(or the .r
) component. This subscription is usually used for the type-casting:
float s = .5;
float3 v1 = s.xxx; // v is (0.5, 0.5, 0.5), or even
float3 v2 = 0.5.xxx; // :)
There's also an implicit conversions from vectors to scalars that takes the first component. Remember that components are stored like RGBA (or XYZW):
float3 v = {0.5, 0.6, 0.7}
float s1 = v; // s1 is 0.5 (implicit conversion)
float s2 = v.x // s2 is 0.5 (explicit conversion)
float s3 = v.xxx /* s3 is 0.5 because we've just created float3(v.x, v.x, v.x)
and then implicitly taken it's X component, which is v.x */
This is how it works. Try to modify your code:
half3 color = condition ? a_previously_defined_half3 : half3(mask, mask, mask)
Nothing should change.