Intrinsics1 min read

unpack_unorm4x8

Unpacks four unsigned normalized channels from a 32-bit integer.

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

Test unpack_unorm4x8 in a live shader

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

Open Playground

The unpack_unorm4x8 function decodes a uint containing four 8-bit unsigned normalized channels into a float4 in [0, 1].

Live Demo

Signature

bwsl
unpack_unorm4x8 :: (uint packed) -> float4

Parameters

ParameterTypeDescription
packeduintPacked 4x8-bit UNorm value

Return Value

Returns a float4 with components in [0, 1].

Example

bwsl
uint packed = resources.colorBuffer[index];
float4 color = unpack_unorm4x8(packed);

Compiled Output

When compiled to GLSL:

glsl
unpackUnorm4x8(packed)

When compiled to HLSL:

hlsl
// lowered to shifts, masks, and division by 255

When compiled to Metal:

metal
unpack_unorm4x8(packed)

See Also