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 Playground

The 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

ParameterTypeDescription
valuefloat2Two 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