GLSL built-in function

unpackHalf2x16()

Unpacks two half-precision components to floats.

Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment

Syntax

vec2 unpackHalf2x16(uint p)

Parameters

p
Packed unsigned integer

Return value

A vec2 decoded from two half-float fields: x from the low 16 bits, y from the high 16 bits.

Live example

Edit the code and the preview updates as you type.

What unpackHalf2x16 does

Unpacks two half-precision components to floats.

Read the preview

The preview selects .x after unpackHalf2x16(packHalf2x16(vec2(x,y))), plotting the recovered horizontal coordinate. Select .y to make the result follow the vertical coordinate instead.

Core call

unpackHalf2x16(packHalf2x16(vec2(x,y))).x;

Unpacking cannot recover precision already lost during packing.

Experiment

Pack vec2(0.25,0.75) before unpacking and retain .x. The decoded value becomes the exactly representable 0.25, so the curve turns into a fixed horizontal line.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions