uvec4
Coerces various input data into a vector of four unsigned integers (uvec4). It is primarily used to pack multiple separate integer data points (like IDs, indices, or flags) into a single variable or to interact with integer textures.
Core Advantages
Efficient data packing. It allows compressing up to four independent pieces of information (like bone indices, material IDs, etc.) into a single vertex attribute to be passed to the GPU, saving valuable attribute slots and forming the core of complex vertex data management.
Common Uses
Skeletal animation vertex data
Packing and unpacking RGBA color data
GPU particle system state management
How to adjust
The output of uvec4 is determined by its input, with key behaviors being the truncation of decimals (not rounding) and unsigned conversion (negative inputs typically become 0). Its constructor is highly flexible and can be built by combining vectors and types of different dimensions, e.g., uvec4(myVec2, myFloat, myBool).
Code Examples
1// Scale a 0-1 range float color by 255
2const scaledColor = floatColor.mul( 255 );
3
4// Convert to a 0-255 range uvec4 integer color
5// e.g., vec4(0.5, 1.0, 0.75, 1.0) -> uvec4(127, 255, 191, 255)
6const integerColor = uvec4( scaledColor );