Intrinsics1 min read

pack_snorm4x8

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

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

Test pack_snorm4x8 in a live shader

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

Open Playground

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

Live Demo

Signature

bwsl
pack_snorm4x8 :: (float4 value) -> uint

Parameters

ParameterTypeDescription
valuefloat4Components to clamp, quantize, and pack

Return Value

Returns a uint containing four 8-bit SNorm channels.

Example

bwsl
float4 normalAndRoughness = float4(normal.xyz, roughness);
uint packed = pack_snorm4x8(normalAndRoughness);

Compiled Output

When compiled to GLSL:

glsl
packSnorm4x8(value)

When compiled to HLSL:

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

When compiled to Metal:

metal
pack_snorm4x8(value)

See Also