Intrinsics1 min read

pack_unorm4x8

Packs four normalized floats into one 32-bit unsigned integer.

Reading Time
1 min
Word Count
95
Sections
7
Try It Live

Test pack_unorm4x8 in a live shader

Open the playground, start from a visual preset, and wire pack_unorm4x8 into the fragment stage to see how it behaves with real values.

Open Playground

The pack_unorm4x8 function clamps four float components to [0, 1], converts them to 8-bit unsigned normalized values, and packs them into a single uint.

Live Demo

Signature

bwsl
pack_unorm4x8 :: (float4 value) -> uint

Parameters

ParameterTypeDescription
valuefloat4Components to clamp, quantize, and pack

Return Value

Returns a uint containing four 8-bit UNorm channels.

Example

bwsl
float4 color = saturate(input.color);
uint packed = pack_unorm4x8(color);

Compiled Output

When compiled to GLSL:

glsl
packUnorm4x8(value)

When compiled to HLSL:

hlsl
// lowered to saturate, round, shifts, and bitwise OR

When compiled to Metal:

metal
pack_unorm4x8(value)

See Also