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 Playground

The 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

ParameterTypeDescription
valuefloat2Components 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