Intrinsics1 min read
pack_half2x16
Packs two floats into one 32-bit unsigned integer as half-precision values.
Reading Time
1 min
Word Count
93
Sections
7
Try It Live
Test pack_half2x16 in a live shader
Open the playground, start from a visual preset, and wire pack_half2x16 into the fragment stage to see how it behaves with real values.
Open PlaygroundThe pack_half2x16 function converts two 32-bit floats to 16-bit floating-point values and packs them into one uint.
Live Demo
Signature
bwsl
pack_half2x16 :: (float2 value) -> uint
Parameters
| Parameter | Type | Description |
|---|---|---|
value | float2 | Two float values to encode as half precision |
Return Value
Returns a uint containing two 16-bit floating-point values.
Example
bwsl
float2 velocity = input.velocity.xy;
uint packedVelocity = pack_half2x16(velocity);Compiled Output
When compiled to GLSL:
glsl
packHalf2x16(value)
When compiled to HLSL:
hlsl
f32tof16(value.x) | (f32tof16(value.y) << 16)
When compiled to Metal:
metal
as_type<uint>(half2(value))
See Also
- unpack_half2x16 - Decode packed half floats
- pack_unorm4x8 - Pack normalized floats
- asuint - Reinterpret bits as unsigned integers