playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
3 lines (2 loc) • 3.81 kB
TypeScript
declare const _default: "\n#ifdef GSPLAT_WORKBUFFER_GEOMETRY\n\n // world-space transform data previously written to the work buffer (see gsplatWriteVS)\n uniform highp usampler2D uWorkBufferTransformA;\n uniform highp usampler2D uWorkBufferTransformB;\n\n // inverse of matrix_model, to convert stored world-space data back to local space\n uniform mat4 matrix_model_inverse;\n\n // world-space camera position\n uniform vec3 uCameraPosition;\n\n ivec2 wbCoord;\n uvec4 wbTransformA;\n\n // cache transformA at the destination pixel; must be called before any getters\n void initWorkBufferGeometry(ivec2 coord) {\n wbCoord = coord;\n wbTransformA = texelFetch(uWorkBufferTransformA, coord, 0);\n }\n\n vec3 workBufferWorldCenter() {\n return vec3(uintBitsToFloat(wbTransformA.x), uintBitsToFloat(wbTransformA.y), uintBitsToFloat(wbTransformA.z));\n }\n\n // world-space rotation (x,y,z,w), decoded to match the work buffer write encoding\n vec4 workBufferWorldRotation() {\n #ifdef GSPLAT_WORKBUFFER_COMPACT\n // half-angle projected quaternion, 11+11+10 bits (see containerCompactWrite)\n uint data = texelFetch(uWorkBufferTransformB, wbCoord, 0).x;\n vec3 p = vec3(\n float(data & 0x7FFu) / 2047.0 * 2.0 - 1.0,\n float((data >> 11u) & 0x7FFu) / 2047.0 * 2.0 - 1.0,\n float((data >> 22u) & 0x3FFu) / 1023.0 * 2.0 - 1.0\n );\n float d = dot(p, p);\n return vec4(sqrt(max(0.0, 2.0 - d)) * p, 1.0 - d);\n #else\n // rotation.xy in transformA.w, rotation.z in transformB.x (see containerPackedWrite)\n vec2 rotXY = unpackHalf2x16(wbTransformA.w);\n vec3 r = vec3(rotXY, unpackHalf2x16(texelFetch(uWorkBufferTransformB, wbCoord, 0).x).x);\n return vec4(r, sqrt(max(0.0, 1.0 - dot(r, r))));\n #endif\n }\n\n vec3 workBufferWorldScale() {\n #ifdef GSPLAT_WORKBUFFER_COMPACT\n // log-encoded scale, 3x8 bits: 0 = true zero, 1-255 maps to e^-12..e^9 (see containerCompactWrite)\n uint data = wbTransformA.w;\n float sx = float(data & 0xFFu);\n float sy = float((data >> 8u) & 0xFFu);\n float sz = float((data >> 16u) & 0xFFu);\n const float logRange = 21.0 / 255.0;\n const float logMin = -12.0;\n return vec3(\n sx == 0.0 ? 0.0 : exp(sx * logRange + logMin),\n sy == 0.0 ? 0.0 : exp(sy * logRange + logMin),\n sz == 0.0 ? 0.0 : exp(sz * logRange + logMin)\n );\n #else\n uvec2 b = texelFetch(uWorkBufferTransformB, wbCoord, 0).xy;\n return vec3(unpackHalf2x16(b.x).y, unpackHalf2x16(b.y));\n #endif\n }\n\n // rotate vector by the inverse of unit quaternion q (x,y,z,w)\n vec3 quatRotateInv(vec4 q, vec3 v) {\n vec3 t = -q.xyz;\n return v + 2.0 * cross(t, cross(t, v) + q.w * v);\n }\n\n // Source-format-compatible getters for user modifier code: local-space values reconstructed\n // from the stored world-space data (quantized by the work buffer format, so rotation and\n // scale are approximate).\n vec3 getCenter() {\n return (matrix_model_inverse * vec4(workBufferWorldCenter(), 1.0)).xyz;\n }\n\n // returns (w,x,y,z) to match the source format getRotation convention\n vec4 getRotation() {\n vec4 worldRotation = workBufferWorldRotation();\n vec4 localRotation = quatMul(vec4(-model_rotation.xyz, model_rotation.w), worldRotation);\n return localRotation.wxyz;\n }\n\n vec3 getScale() {\n return workBufferWorldScale() / model_scale;\n }\n\n#endif\n";
export default _default;