Intrinsics1 min read
pack_snorm2x16
Packs two signed normalized floats into one 32-bit unsigned integer.
Reading Time
1 min
Word Count
97
Sections
7
Try It Live
Test pack_snorm2x16 in a live shader
Open the playground, start from a visual preset, and wire pack_snorm2x16 into the fragment stage to see how it behaves with real values.
Open PlaygroundThe pack_snorm2x16 function clamps two float components to [-1, 1], converts them to 16-bit signed normalized values, and packs them into a single uint.
Live Demo
Signature
bwsl
pack_snorm2x16 :: (float2 value) -> uint
Parameters
| Parameter | Type | Description |
|---|---|---|
value | float2 | Components to clamp, quantize, and pack |
Return Value
Returns a uint containing two 16-bit SNorm channels.
Example
bwsl
float2 encodedNormal = normal.xy;
uint packedNormal = pack_snorm2x16(encodedNormal);Compiled Output
When compiled to GLSL:
glsl
packSnorm2x16(value)
When compiled to HLSL:
hlsl
// lowered to clamp, round, shifts, and bitwise OR
When compiled to Metal:
metal
pack_snorm2x16(value)
See Also
- unpack_snorm2x16 - Decode packed SNorm16 channels
- pack_unorm2x16 - Pack unsigned normalized channels
- pack_snorm4x8 - Pack four 8-bit SNorm channels