UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

33 lines (32 loc) 1.29 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{glsl as o}from"../../shaderModules/glsl.js";function t(t){t.code.add(o`const float MAX_RGBA_FLOAT = 255.0 / 256.0 + 255.0 / 256.0 / 256.0 + 255.0 / 256.0 / 256.0 / 256.0 + 255.0 / 256.0 / 256.0 / 256.0 / 256.0; const vec4 FIXED_POINT_FACTORS = vec4(1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0); vec4 float2rgba(const float value) { float valueInValidDomain = clamp(value, 0.0, MAX_RGBA_FLOAT); vec4 fixedPointU8 = floor(fract(valueInValidDomain * FIXED_POINT_FACTORS) * 256.0); const float toU8AsFloat = 1.0 / 255.0; return fixedPointU8 * toU8AsFloat; }`),t.code.add(o`const vec4 RGBA_TO_FLOAT_FACTORS = vec4( 255.0 / (256.0), 255.0 / (256.0 * 256.0), 255.0 / (256.0 * 256.0 * 256.0), 255.0 / (256.0 * 256.0 * 256.0 * 256.0) ); float rgbaTofloat(vec4 rgba) { return dot(rgba, RGBA_TO_FLOAT_FACTORS); }`),t.code.add(o`const vec4 uninterpolatedRGBAToFloatFactors = vec4( 1.0 / 256.0, 1.0 / 256.0 / 256.0, 1.0 / 256.0 / 256.0 / 256.0, 1.0 / 256.0 / 256.0 / 256.0 / 256.0 ); float uninterpolatedRGBAToFloat(vec4 rgba) { return (dot(round(rgba * 255.0), uninterpolatedRGBAToFloatFactors) - 0.5) * 2.0; }`)}export{t as RgbaFloatEncoding};