UNPKG

440 BPlain TextView Raw
1import {clamp} from '../util/util';
2
3/**
4 * Packs two numbers, interpreted as 8-bit unsigned integers, into a single
5 * float. Unpack them in the shader using the `unpack_float()` function,
6 * defined in _prelude.vertex.glsl
7 *
8 * @private
9 */
10export function packUint8ToFloat(a: number, b: number) {
11 // coerce a and b to 8-bit ints
12 a = clamp(Math.floor(a), 0, 255);
13 b = clamp(Math.floor(b), 0, 255);
14 return 256 * a + b;
15}