GLSL built-in function
packHalf2x16()
Converts two floats to half precision and packs them.
Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment
Syntax
uint packHalf2x16(vec2 v)Parameters
- v
- Components to pack
Return value
One uint holding two 16-bit floating-point encodings; v.x occupies the low 16 bits and v.y the high 16 bits.
Live example
Edit the code and the preview updates as you type.
What packHalf2x16 does
Converts two floats to half precision and packs them.
Read the preview
The round trip through packHalf2x16(vec2(x,y)) preserves a nearly straight x ramp at this scale. Replace x with x*0.5 to halve the decoded line's slope.
Core call
unpackHalf2x16(packHalf2x16(vec2(x,y))).x;
Half precision loses mantissa bits and very large values can overflow.
Experiment
Pack vec2(0.1,y) instead of vec2(x,y). The decoded x component becomes a constant close to 0.1, with the small half-precision rounding hidden at normal preview scale.