ScriptReference/Grid.Swizzle #116
Replies: 1 comment
-
|
Comment by RaspberrySpaceJam: For anyone else like me who was unsure about what the word swizzle means, it is a term that is most common in graphics programming and shaders. The term simply means to map the values of one vector onto a different vector with re-arrangement of the values. Below is an example of using the Swizzle method to swap the X and Y values of a vector. Vector3 preSwizzle = new Vector3(1.0f, 2.0f, 3.0f);
Vector3 postSwizzle = Grid.Swizzle(GridLayout.CellSwizzle.YXZ, preSwizzle);
//postSwizzle has the XYZ values: 2.0f, 1.0f, 3.0fIt is worth noting that this swizzle method is significantly less robust than swizzling typically is in shaders as it requires that each XYZ value be mapped to the new vector which is not typically a requirement when swizzling. Below is an example of what swizzling looks like in a shader to map the X value onto the XY value of a new vector (which is called a float3 in shader script) and keep the Z value the same. float3 preSwizzle = float3(1.0, 2.0, 3.0);
float3 postSwizzle = preSwizzle.xxz;
//postSwizzle has the XYZ values: 1.0, 1.0, 3.0 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
ScriptReference/Grid.Swizzle
https://docs.unity3d.com/ScriptReference/Grid.Swizzle.html
Beta Was this translation helpful? Give feedback.
All reactions