playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
3 lines (2 loc) • 2.48 kB
TypeScript
declare const _default: "\n// means dequantization (both V1 and V2)\nuniform vec3 means_mins;\nuniform vec3 means_maxs;\n\n#ifndef SOG_V2\n // V1: linear min/max dequantization (no codebooks)\n uniform vec3 scales_mins;\n uniform vec3 scales_maxs;\n uniform vec4 sh0_mins;\n uniform vec4 sh0_maxs;\n#endif\n\n// SH_C0 coefficient for 0th degree spherical harmonic\nconst float SH_C0 = 0.28209479177387814;\nconst float norm = sqrt(2.0);\n\n#ifdef SOG_V2\n // 256x1 RGBA32F LUT:\n // .r = scales codebook, .g = sh0 codebook, .b = shN codebook, .a unused\n float lutScales(int b) { return texelFetch(sogCodebook, ivec2(b, 0), 0).r; }\n float lutSh0(int b) { return texelFetch(sogCodebook, ivec2(b, 0), 0).g; }\n float lutShN(int b) { return texelFetch(sogCodebook, ivec2(b, 0), 0).b; }\n#endif\n\n// read the model-space center of the gaussian (16-bit per-axis, low + high byte)\nvec3 getCenter() {\n vec3 l = texelFetch(means_l, splat.uv, 0).xyz;\n vec3 u = texelFetch(means_u, splat.uv, 0).xyz;\n vec3 n = (l + u * 256.0) / 257.0;\n vec3 v = mix(means_mins, means_maxs, n);\n return sign(v) * (exp(abs(v)) - 1.0);\n}\n\n// decode rotation quaternion (3 components + 2-bit mode selecting the omitted axis)\nvec4 getRotation() {\n vec4 q = texelFetch(quats, splat.uv, 0);\n uint qmode = uint(q.w * 255.0 + 0.5) - 252u;\n vec3 abc = (q.xyz - 0.5) * norm;\n float d = sqrt(max(0.0, 1.0 - dot(abc, abc)));\n return (qmode == 0u) ? vec4(d, abc) :\n ((qmode == 1u) ? vec4(abc.x, d, abc.yz) :\n ((qmode == 2u) ? vec4(abc.xy, d, abc.z) : vec4(abc, d)));\n}\n\nvec3 getScale() {\n vec3 s = texelFetch(scales, splat.uv, 0).xyz;\n #ifdef SOG_V2\n ivec3 i = ivec3(s * 255.0 + 0.5);\n vec3 logS = vec3(lutScales(i.x), lutScales(i.y), lutScales(i.z));\n #else\n vec3 logS = mix(scales_mins, scales_maxs, s);\n #endif\n return exp(logS);\n}\n\nvec4 getColor() {\n vec4 c = texelFetch(sh0, splat.uv, 0);\n #ifdef SOG_V2\n ivec3 i = ivec3(c.xyz * 255.0 + 0.5);\n vec3 rgb = vec3(lutSh0(i.x), lutSh0(i.y), lutSh0(i.z));\n float alpha = c.w;\n #else\n vec3 rgb = mix(sh0_mins.xyz, sh0_maxs.xyz, c.xyz);\n float logitAlpha = mix(sh0_mins.w, sh0_maxs.w, c.w);\n float alpha = 1.0 / (1.0 + exp(-logitAlpha));\n #endif\n return vec4(vec3(0.5) + rgb * SH_C0, alpha);\n}\n\n#include \"gsplatSogSHVS\"\n";
export default _default;