playcanvas
Version:
PlayCanvas WebGL game engine
55 lines (54 loc) • 2.45 kB
TypeScript
/**
* Utility static class providing functionality to pack float values to various storage
* representations.
*
* @category Math
*/
export class FloatPacking {
/**
* Packs a float to a 16-bit half-float representation used by the GPU.
*
* @param {number} value - The float value to pack.
* @returns {number} The packed value.
*/
static float2Half(value: number): number;
/**
* Packs a float value in [0..1) range to specified number of bytes and stores them in an array
* with start offset. Based on: https://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
* Note: calls to Math.round are only needed on iOS. Precision is somehow really bad without
* it. Looks like an issue with their implementation of Uint8ClampedArray.
*
* @param {number} value - The float value to pack.
* @param {Uint8ClampedArray} array - The array to store the packed value in.
* @param {number} offset - The start offset in the array to store the packed value at.
* @param {number} numBytes - The number of bytes to pack the value to.
*
* @ignore
*/
static float2Bytes(value: number, array: Uint8ClampedArray, offset: number, numBytes: number): void;
/**
* Packs a float into specified number of bytes. Min and max range for the float is specified,
* allowing the float to be normalized to 0..1 range.
*
* @param {number} value - The float value to pack.
* @param {Uint8ClampedArray} array - The array to store the packed value in.
* @param {number} offset - The start offset in the array to store the packed value at.
* @param {number} min - Range minimum.
* @param {number} max - Range maximum.
* @param {number} numBytes - The number of bytes to pack the value to.
*
* @ignore
*/
static float2BytesRange(value: number, array: Uint8ClampedArray, offset: number, min: number, max: number, numBytes: number): void;
/**
* Converts bits of a 32-bit float into RGBA8 format and stores the result in a provided color.
* The float can be reconstructed in shader using the uintBitsToFloat instruction.
*
* @param {number} value - The float value to convert.
* @param {Color} data - The color to store the RGBA8 packed value in.
*
* @ignore
*/
static float2RGBA8(value: number, data: Color): void;
}
import type { Color } from './color.js';