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 PlaygroundThe 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
| Parameter | Type | Description |
|---|---|---|
value | float4 | Components 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
- unpack_snorm4x8 - Decode packed SNorm channels
- pack_unorm4x8 - Pack unsigned normalized channels
- pack_half2x16 - Pack half-precision floats