November 2019
Intermediate to advanced
404 pages
12h 9m
English
Swizzling is the shader programming technique of creating a new vector (an array of values) from an existing vector by listing the components in the order in which we wish to copy them into the new structure.
Here are some examples of swizzling:
float4 input = float4(1.0, 2.0, 3.0, 4.0); // initial test value (x, y, z, w)// swizzle two componentsfloat2 val1 = input.yz; // val1 = (2.0, 3.0)// swizzle three components in a different orderfloat3 val2 = input.zyx; // val2 = (3.0, 2.0, 1.0)// swizzle the same component multiple timesfloat4 val3 = input.yyy; // val3 = (2.0, 2.0, 2.0)// swizzle a scalar multiple timesfloat sclr = input.w; // sclr = (4.0)float3 val4 = sclr.xxx; // val4 = (4.0, 4.0, 4.0) ...
Read now
Unlock full access