Intrinsics1 min read
unpack_half2x16
Unpacks two half-precision values from a 32-bit unsigned integer.
Reading Time
1 min
Word Count
84
Sections
7
Try It Live
Test unpack_half2x16 in a live shader
Open the playground, start from a visual preset, and wire unpack_half2x16 into the fragment stage to see how it behaves with real values.
Open PlaygroundThe unpack_half2x16 function decodes two 16-bit floating-point values from a uint and returns them as a float2.
Live Demo
Signature
bwsl
unpack_half2x16 :: (uint packed) -> float2
Parameters
| Parameter | Type | Description |
|---|---|---|
packed | uint | Packed 2x16-bit half-float value |
Return Value
Returns a float2 containing the decoded values.
Example
bwsl
uint packedVelocity = resources.velocityBuffer[index];
float2 velocity = unpack_half2x16(packedVelocity);Compiled Output
When compiled to GLSL:
glsl
unpackHalf2x16(packed)
When compiled to HLSL:
hlsl
float2(f16tof32(packed & 0xffffu), f16tof32(packed >> 16u))
When compiled to Metal:
metal
float2(as_type<half2>(packed))
See Also
- pack_half2x16 - Pack half floats
- unpack_unorm4x8 - Decode normalized channels
- asfloat - Reinterpret bits as floats