UNPKG

@itwin/core-frontend

Version:
36 lines 3.68 kB
/** @packageDocumentation * @module WebGL */ import { ShaderBuilder } from "../ShaderBuilder"; /** @internal */ export declare const decodeUint16 = "\nfloat decodeUInt16(vec2 v) {\n return dot(v, vec2(1.0, 256.0)); // v.x | (v.y << 8)\n}\n"; /** @internal */ export declare const decodeUint24 = "\nfloat decodeUInt24(vec3 v) {\n return dot(v, vec3(1.0, 256.0, 256.0*256.0)); // v.x | (v.y << 8) | (v.z << 16)\n}\n"; /** @internal */ export declare const unquantize3d = "\nvec3 unquantize3d(vec3 qpos, vec3 origin, vec3 scale) { return origin + scale * qpos; }\n"; /** @internal */ export declare const unquantize2d = "\n// params.xy = origin. params.zw = scale.\nvec2 unquantize2d(vec2 qpos, vec4 params) { return params.xy + params.zw * qpos; }\n"; /** @internal */ export declare const decodeDepthRgb = "\nfloat decodeDepthRgb(vec3 rgb) { return dot(rgb, vec3(1.0, 1.0 / 255.0, 1.0 / 65025.0)); }\n"; /** @internal */ export declare const encodeDepthRgb = "\nvec3 encodeDepthRgb(float depth) {\n // 1.0 must be reduced slightly; otherwise decoding will produce zero. It's the far plane, so we don't care (and decoding produces 1.0 anyway).\n depth = min(depth, 16777215.0/16777216.0);\n\n vec3 enc = vec3(1.0, 255.0, 65025.0) * depth;\n enc = fract(enc);\n enc.xy -= enc.yz / 255.0;\n return enc;\n}\n"; /** Pack 2 floats in the integer range [0..255] into a single float equal to v.x | (v.y << 8) * @internal */ export declare const pack2Bytes = "\nfloat pack2Bytes(vec2 v) {\n return v.x + (v.y * 256.0);\n}\n"; /** Unpack a float in the integer range [0..0xffff] into a vec2 containing 2 integers in the range [0..255] * @internal */ export declare const unpack2Bytes = "\nvec2 unpack2Bytes(float f) {\n f = floor(f + 0.5);\n vec2 v;\n v.y = floor(f / 256.0);\n v.x = floor(f - v.y * 256.0);\n return v;\n}\n"; /** @internal */ export declare const unpackAndNormalize2Bytes = "\nvec2 unpackAndNormalize2Bytes(float f) {\n return unpack2Bytes(f) / 255.0;\n}\n"; /** @internal */ export declare function addUnpackAndNormalize2Bytes(builder: ShaderBuilder): void; /** Given an IEEE 32-bit float stuffed into a RGBA unsigned byte texture, extract the float. * The input vec4 components are in the integer range [0..255]. * From https://github.com/CesiumGS/cesium/blob/main/Source/Shaders/Builtin/Functions/unpackFloat.glsl * @internal */ export declare const decodeFloat32 = "\nfloat decodeFloat32(vec4 packedFloat) {\n float sign = 1.0 - step(128.0, packedFloat[3]) * 2.0;\n float exponent = 2.0 * mod(packedFloat[3], 128.0) + step(128.0, packedFloat[2]) - 127.0;\n if (exponent == -127.0)\n return 0.0;\n\n float mantissa = mod(packedFloat[2], 128.0) * 65536.0 + packedFloat[1] * 256.0 + packedFloat[0] + float(0x800000);\n float result = sign * exp2(exponent - 23.0) * mantissa;\n return result;\n}\n"; export declare const decode3Float32 = "\n// This expects an array of 4 vec3s, where each vec4 contains a slice of all 3 of the packed floats in .xyz\n// pf0 is in [0].x, pf1 is in [0].y, and pf2 in [0].z\n// e.g.: packedFloat[0] = vec3(pf0.x, pf1.x, pf2.x)\n// likewise .y info is in [1], .z in [2], and .w in [3]\nvec3 decode3Float32(vec3 packedFloat[4]) {\n vec3 sign = 1.0 - step(128.0, packedFloat[3].xyz) * 2.0;\n vec3 exponent = 2.0 * mod(packedFloat[3].xyz, 128.0) + step(128.0, packedFloat[2].xyz) - 127.0;\n vec3 zeroFlag = vec3(notEqual(vec3(-127.0), exponent));\n vec3 mantissa = mod(packedFloat[2].xyz, 128.0) * 65536.0 + packedFloat[1].xyz * 256.0 + packedFloat[0].xyz + float(0x800000);\n vec3 result = sign * exp2(exponent - 23.0) * mantissa * zeroFlag;\n return result;\n}\n"; //# sourceMappingURL=Decode.d.ts.map