Swizzling (computer graphics)

Vector computation used in computer graphics

Not to be confused with Pointer swizzling.

In computer graphics, swizzles are a class of operations that transform vectors by rearranging components.[1] Swizzles can also project from a vector of one dimensionality to a vector of another dimensionality, such as taking a three-dimensional vector and creating a two-dimensional or five-dimensional vector using components from the original vector.[2] For example, if `A = {1,2,3,4}`, where the components are `x`, `y`, `z`, and `w` respectively, you could compute `B = A.wwxy`, whereupon `B` would equal `{4,4,1,2}`. Additionally, one could create a two-dimensional vector with A.wx or a five-dimensional vector with A.xyzwx. Combining vectors and swizzling can be employed in various ways. This is common in GPGPU applications. [3]

In terms of linear algebra, this is equivalent to multiplying by a matrix whose rows are standard basis vectors. If  A = ( 1 , 2 , 3 , 4 ) T {\displaystyle A=(1,2,3,4)^{T}} , then swizzling  A {\displaystyle A} as above looks like

A . w w x y = [ 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 ] [ 1 2 3 4 ] = [ 4 4 1 2 ] . {\displaystyle A.wwxy={\begin{bmatrix}0&0&0&1\\\0&0&0&1\\\1&0&0&0\\\0&1&0&0\end{bmatrix}}{\begin{bmatrix}1\\\2\\\3\\\4\end{bmatrix}}={\begin{bmatrix}4\\\4\\\1\\\2\end{bmatrix}}.}

## See also

[edit]

Z-order curve

## References

[edit]

1. ^ Lawlor, Orion. "OpenGL ARB_fragment_program Quick Reference ("Cheat Sheet")". University of Alaska Fairbanks. Retrieved 21 January 2014.
2. ^ "Vec3Swizzles". glam. Retrieved 29 March 2023.
3. ^ "Introduction to CUDA Programming and Performance Optimization". Retrieved 23 December 2024. (Relevant portion starts around 37min)

## External links

[edit]

* OpenGL Vertex Program documentation

This computer graphics–related article is a stub. You can help Wikipedia by expanding it.

|

* v
* t
* e

*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template