playcanvas
Version:
PlayCanvas WebGL game engine
3 lines (2 loc) • 4.19 kB
TypeScript
declare const _default: "\n\n#define GSPLAT_CENTER_NOPROJ\n\n#include \"gsplatStructsVS\"\n#include \"gsplatCenterVS\"\n#include \"gsplatEvalSHVS\"\n#include \"gsplatQuatToMat3VS\"\n#include \"gsplatSourceFormatVS\"\n#include \"packHalfPS\"\n\nuniform uStartLine: i32; // Start row in destination texture\nuniform uViewportWidth: i32; // Width of the destination viewport in pixels\n\n#ifdef GSPLAT_LOD\n // LOD intervals texture\n var uIntervalsTexture: texture_2d<u32>;\n#endif\n\nuniform uColorMultiply: vec3f;\n\n// number of splats\nuniform uActiveSplats: i32;\n\n@fragment\nfn fragmentMain(input: FragmentInput) -> FragmentOutput {\n var output: FragmentOutput;\n \n // local fragment coordinates (within the viewport)\n let localFragCoords = vec2i(i32(input.position.x), i32(input.position.y) - uniform.uStartLine);\n\n // linear index of the splat\n let targetIndex = localFragCoords.y * uniform.uViewportWidth + localFragCoords.x;\n \n if (targetIndex >= uniform.uActiveSplats) {\n\n // Out of bounds: write zeros\n output.color = vec4f(0.0);\n #ifndef GSPLAT_COLOR_ONLY\n output.color1 = vec4u(0u);\n output.color2 = vec2u(0u);\n #endif\n\n } else {\n\n #ifdef GSPLAT_LOD\n // Use intervals texture to remap target index to source index\n let intervalsSize = i32(textureDimensions(uIntervalsTexture, 0).x);\n let intervalUV = vec2i(targetIndex % intervalsSize, targetIndex / intervalsSize);\n let originalIndex = textureLoad(uIntervalsTexture, intervalUV, 0).r;\n #else\n let originalIndex = targetIndex;\n #endif\n \n // source texture size\n var srcSize: u32;\n #if defined(GSPLAT_SOGS_DATA) || defined(GSPLAT_COMPRESSED_DATA)\n srcSize = u32(textureDimensions(packedTexture, 0).x);\n #else\n srcSize = u32(textureDimensions(splatColor, 0).x);\n #endif\n \n // Create SplatSource used to sample splat data textures\n var source: SplatSource;\n source.id = u32(originalIndex);\n source.uv = vec2i(i32(source.id % srcSize), i32(source.id / srcSize));\n\n // read center in local space\n var modelCenter = readCenter(&source);\n\n // compute world-space center for storage\n let worldCenter = (uniform.matrix_model * vec4f(modelCenter, 1.0)).xyz;\n var center: SplatCenter;\n initCenter(modelCenter, ¢er);\n\n // read and transform covariance\n var covA: vec3f;\n var covB: vec3f;\n readCovariance(&source, &covA, &covB);\n\n let C = mat3x3f(\n vec3f(covA.x, covA.y, covA.z),\n vec3f(covA.y, covB.x, covB.y),\n vec3f(covA.z, covB.y, covB.z)\n );\n let linear = mat3x3f(uniform.matrix_model[0].xyz, uniform.matrix_model[1].xyz, uniform.matrix_model[2].xyz);\n let Ct = linear * C * transpose(linear);\n covA = Ct[0];\n covB = vec3f(Ct[1][1], Ct[1][2], Ct[2][2]);\n\n // read color\n var color = readColor(&source);\n\n // evaluate spherical harmonics\n #if SH_BANDS > 0\n // calculate the model-space view direction\n let dir = normalize(center.view * mat3x3f(center.modelView[0].xyz, center.modelView[1].xyz, center.modelView[2].xyz));\n\n // read sh coefficients\n var sh: array<vec3f, SH_COEFFS>;\n var scale: f32;\n readSHData(&source, &sh, &scale);\n\n // evaluate\n color = vec4f(color.xyz + evalSH(&sh, dir) * scale, color.w);\n #endif\n\n color = vec4f(color.xyz * uniform.uColorMultiply, color.w);\n\n // write out results\n output.color = color;\n #ifndef GSPLAT_COLOR_ONLY\n output.color1 = vec4u(bitcast<u32>(worldCenter.x), bitcast<u32>(worldCenter.y), bitcast<u32>(worldCenter.z), pack2x16floatSafe(vec2f(covA.z, covB.z)));\n output.color2 = vec2u(pack2x16floatSafe(covA.xy), pack2x16floatSafe(covB.xy));\n #endif\n }\n \n return output;\n}\n";
export default _default;