UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

77 lines (76 loc) 2.62 kB
/** * A utility class for computing camera-relative bin weights used in GSplat sorting. * Pre-allocates a single interleaved Float32Array that is reused across frames. * Used by both GPU (GSplatSortKeyCompute) and CPU worker sorting paths. * * This class is stringified and injected into the worker blob, so it must be * fully self-contained: no imports, and all constants as static properties. * * @ignore */ export class GSplatSortBinWeights { /** * Number of bins for camera-relative precision weighting. * * @type {number} */ static get NUM_BINS(): number; /** * Weight tiers for camera-relative precision (distance from camera bin -> weight multiplier). * Closer bins get more precision for better visual quality near the camera. * * @type {Array<{maxDistance: number, weight: number}>} */ static get WEIGHT_TIERS(): Array<{ maxDistance: number; weight: number; }>; /** * Computes the camera bin index based on sort mode and distance range. * * @param {boolean} radialSort - Whether using radial sort mode. * @param {number} minDist - Minimum distance. * @param {number} range - Distance range (maxDist - minDist). * @returns {number} The camera bin index (0 to NUM_BINS-1). */ static computeCameraBin(radialSort: boolean, minDist: number, range: number): number; /** * Pre-allocated interleaved array [base0, divider0, base1, divider1, ...]. * * @type {Float32Array} */ binWeights: Float32Array; /** * Pre-computed weight lookup table by distance from camera (constant). * * @type {Float32Array} */ weightByDistance: Float32Array; /** * Pre-allocated scratch array for bits per bin calculation. * * @type {Float32Array} */ bitsPerBin: Float32Array; /** * Cached cameraBin from last compute call. * * @type {number} */ lastCameraBin: number; /** * Cached bucketCount from last compute call. * * @type {number} */ lastBucketCount: number; /** * Computes bin weights for the given camera bin and bucket count. * Results are cached - returns immediately if inputs haven't changed. * * @param {number} cameraBin - The bin index where the camera is located (0 to NUM_BINS-1). * @param {number} bucketCount - Total number of sorting buckets (typically 2^numBits). * @returns {Float32Array} The same binWeights array with computed values. */ compute(cameraBin: number, bucketCount: number): Float32Array; }