playcanvas
Version:
PlayCanvas WebGL game engine
4 lines (2 loc) • 3.57 kB
JavaScript
var gsplatCommonVS = '\n\n// stores the source UV and order of the splat\nstruct SplatSource {\n uint order; // render order\n uint id; // splat id\n ivec2 uv; // splat uv\n vec2 cornerUV; // corner coordinates for this vertex of the gaussian (-1, -1)..(1, 1)\n};\n\n// stores the camera and clip space position of the gaussian center\nstruct SplatCenter {\n vec3 view; // center in view space\n vec4 proj; // center in clip space\n mat4 modelView; // model-view matrix\n float projMat00; // elememt [0][0] of the projection matrix\n};\n\n// stores the offset from center for the current gaussian\nstruct SplatCorner {\n vec2 offset; // corner offset from center in clip space\n vec2 uv; // corner uv\n};\n\n#if SH_BANDS > 0\n #if SH_BANDS == 1\n #define SH_COEFFS 3\n #elif SH_BANDS == 2\n #define SH_COEFFS 8\n #elif SH_BANDS == 3\n #define SH_COEFFS 15\n #endif\n#endif\n\n#if GSPLAT_COMPRESSED_DATA == true\n #include "gsplatCompressedDataVS"\n #include "gsplatCompressedSHVS"\n#else\n #include "gsplatDataVS"\n #include "gsplatColorVS"\n #include "gsplatSHVS"\n#endif\n\n#include "gsplatSourceVS"\n#include "gsplatCenterVS"\n#include "gsplatCornerVS"\n#include "gsplatOutputVS"\n\n// modify the gaussian corner so it excludes gaussian regions with alpha\n// less than 1/255\nvoid clipCorner(inout SplatCorner corner, float alpha) {\n float clip = min(1.0, sqrt(-log(1.0 / 255.0 / alpha)) / 2.0);\n corner.offset *= clip;\n corner.uv *= clip;\n}\n\n// spherical Harmonics\n\n#if SH_BANDS > 0\n\n#define SH_C1 0.4886025119029199f\n\n#if SH_BANDS > 1\n #define SH_C2_0 1.0925484305920792f\n #define SH_C2_1 -1.0925484305920792f\n #define SH_C2_2 0.31539156525252005f\n #define SH_C2_3 -1.0925484305920792f\n #define SH_C2_4 0.5462742152960396f\n#endif\n\n#if SH_BANDS > 2\n #define SH_C3_0 -0.5900435899266435f\n #define SH_C3_1 2.890611442640554f\n #define SH_C3_2 -0.4570457994644658f\n #define SH_C3_3 0.3731763325901154f\n #define SH_C3_4 -0.4570457994644658f\n #define SH_C3_5 1.445305721320277f\n #define SH_C3_6 -0.5900435899266435f\n#endif\n\n// see https://github.com/graphdeco-inria/gaussian-splatting/blob/main/utils/sh_utils.py\nvec3 evalSH(in SplatSource source, in vec3 dir) {\n\n // read sh coefficients\n vec3 sh[SH_COEFFS];\n float scale;\n readSHData(source, sh, scale);\n\n float x = dir.x;\n float y = dir.y;\n float z = dir.z;\n\n // 1st degree\n vec3 result = SH_C1 * (-sh[0] * y + sh[1] * z - sh[2] * x);\n\n#if SH_BANDS > 1\n // 2nd degree\n float xx = x * x;\n float yy = y * y;\n float zz = z * z;\n float xy = x * y;\n float yz = y * z;\n float xz = x * z;\n\n result +=\n sh[3] * (SH_C2_0 * xy) * +\n sh[4] * (SH_C2_1 * yz) +\n sh[5] * (SH_C2_2 * (2.0 * zz - xx - yy)) +\n sh[6] * (SH_C2_3 * xz) +\n sh[7] * (SH_C2_4 * (xx - yy));\n#endif\n\n#if SH_BANDS > 2\n // 3rd degree\n result +=\n sh[8] * (SH_C3_0 * y * (3.0 * xx - yy)) +\n sh[9] * (SH_C3_1 * xy * z) +\n sh[10] * (SH_C3_2 * y * (4.0 * zz - xx - yy)) +\n sh[11] * (SH_C3_3 * z * (2.0 * zz - 3.0 * xx - 3.0 * yy)) +\n sh[12] * (SH_C3_4 * x * (4.0 * zz - xx - yy)) +\n sh[13] * (SH_C3_5 * z * (xx - yy)) +\n sh[14] * (SH_C3_6 * x * (xx - 3.0 * yy));\n#endif\n\n return result * scale;\n}\n#endif\n';
export { gsplatCommonVS as default };