Intrinsics1 min read
pack_unorm2x16
Packs two unsigned normalized floats into one 32-bit unsigned integer.
Reading Time
1 min
Word Count
97
Sections
7
Try It Live
Test pack_unorm2x16 in a live shader
Open the playground, start from a visual preset, and wire pack_unorm2x16 into the fragment stage to see how it behaves with real values.
Open PlaygroundThe pack_unorm2x16 function clamps two float components to [0, 1], converts them to 16-bit unsigned normalized values, and packs them into a single uint.
Live Demo
Signature
bwsl
pack_unorm2x16 :: (float2 value) -> uint
Parameters
| Parameter | Type | Description |
|---|---|---|
value | float2 | Components to clamp, quantize, and pack |
Return Value
Returns a uint containing two 16-bit UNorm channels.
Example
bwsl
float2 velocity = saturate(encodedVelocity);
uint packedVelocity = pack_unorm2x16(velocity);Compiled Output
When compiled to GLSL:
glsl
packUnorm2x16(value)
When compiled to HLSL:
hlsl
// lowered to saturate, round, shifts, and bitwise OR
When compiled to Metal:
metal
pack_unorm2x16(value)
See Also
- unpack_unorm2x16 - Decode packed UNorm16 channels
- pack_snorm2x16 - Pack signed normalized channels
- pack_unorm4x8 - Pack four 8-bit UNorm channels