GLSL built-in function

unpackSnorm2x16()

Unpacks one uint into two signed normalized components.

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

Syntax

vec2 unpackSnorm2x16(uint p)

Parameters

p
Packed unsigned integer

Return value

A vec2 in [-1, 1] decoded from the two signed 16-bit fields, with the low field mapped to x.

Live example

Edit the code and the preview updates as you type.

What unpackSnorm2x16 does

Unpacks one uint into two signed normalized components.

Read the preview

Unpacking the signed-normalized round trip recovers negative x on the left and positive x on the right. Choose .y instead of .x to rotate the background gradient into the vertical direction.

Core call

unpackSnorm2x16(packSnorm2x16(vec2(x,y))).x;

Unpacked values have finite precision; exact equality to the original is not expected.

Experiment

Change the pack input to vec2(x*3.0,y) before unpackSnorm2x16. The decoded ramp flattens at -1 and 1, showing that unpacking cannot recover values clipped during packing.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions