GLSL built-in function

packUnorm2x16()

Packs two unsigned normalized components into one uint.

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

Syntax

uint packUnorm2x16(vec2 v)

Parameters

v
Components to pack

Return value

One uint containing two unsigned 16-bit normalized encodings of v clamped to [0, 1], x in the low bits.

Live example

Edit the code and the preview updates as you type.

What packUnorm2x16 does

Packs two unsigned normalized components into one uint.

Read the preview

packUnorm2x16(uv) encodes coordinates from 0 to 1, and the preview displays the decoded x channel. Try uv*2.0 to make the right half clamp to 1.

Core call

unpackUnorm2x16(packUnorm2x16(uv)).x;

Inputs are clamped to [0,1]; this is not an HDR color encoding.

Experiment

Replace uv with vec2(0.25,uv.y) in packUnorm2x16. The diagonal becomes a horizontal result near 0.25 because the low 16 bits now hold one fixed value.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions