playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
3 lines (2 loc) • 2.85 kB
TypeScript
export const computeGsplatProjectCommonSource: "\n\nstruct ProjectedSplatCommon {\n valid: bool,\n splatId: u32,\n center: vec3f,\n opacity: f32,\n proj: SplatCov2D\n}\n\nfn invalidProjectedSplatCommon() -> ProjectedSplatCommon {\n var cov: SplatCov2D;\n cov.screen = vec2f(0.0);\n cov.a = 0.0;\n cov.b = 0.0;\n cov.c = 0.0;\n cov.viewDepth = 0.0;\n cov.valid = false;\n\n return ProjectedSplatCommon(false, 0u, vec3f(0.0), 0.0, cov);\n}\n\nfn projectSplatCommon(\n threadIdx: u32,\n numVisible: u32,\n alphaClip: f32,\n minPixelSize: f32,\n minContribution: f32,\n foveationStrength: f32,\n foveationCenter: f32,\n viewMatrix: mat4x4f,\n viewProj: mat4x4f,\n focal: f32,\n viewportWidth: f32,\n viewportHeight: f32,\n nearClip: f32,\n farClip: f32,\n isOrtho: u32,\n #ifdef GSPLAT_FISHEYE\n fisheye_k: f32,\n fisheye_inv_k: f32,\n fisheye_projMat00: f32,\n fisheye_projMat11: f32,\n #endif\n #ifdef GSPLAT_XR\n viewProj1: mat4x4f,\n #endif\n) -> ProjectedSplatCommon {\n if (threadIdx >= numVisible) {\n return invalidProjectedSplatCommon();\n }\n\n let splatId = compactedSplatIds[threadIdx];\n setSplat(splatId);\n\n // read the world-space center and apply the render-stage center modifier before projection\n // (matches the quad renderer's gsplatVS, which calls modifySplatCenter on the model center)\n let originalCenter = getCenter();\n var center = originalCenter;\n modifySplatCenter(¢er);\n\n let opacity = getOpacity();\n if (opacity <= alphaClip) {\n return invalidProjectedSplatCommon();\n }\n\n // apply the render-stage rotation/scale modifier (e.g. scale-to-zero for reveal/hide effects).\n // getRotation() is (w,x,y,z); the modify hook contract is (x,y,z,w) and computeSplatCov expects\n // (w,x,y,z) - this mirrors gsplatCorner.js in the quad renderer.\n var rotation: vec4f = getRotation().yzwx;\n var scale: vec3f = getScale();\n modifySplatRotationScale(originalCenter, center, &rotation, &scale);\n\n let proj = computeSplatCov(\n center, half4(rotation.wxyz), half3(scale),\n viewMatrix, viewProj,\n focal, viewportWidth, viewportHeight,\n nearClip, farClip, opacity, minPixelSize,\n isOrtho, alphaClip, minContribution,\n foveationStrength, foveationCenter,\n #ifdef GSPLAT_FISHEYE\n fisheye_k, fisheye_inv_k,\n fisheye_projMat00, fisheye_projMat11,\n #endif\n #ifdef GSPLAT_XR\n viewProj1,\n #endif\n );\n\n if (!proj.valid) {\n return invalidProjectedSplatCommon();\n }\n\n return ProjectedSplatCommon(true, splatId, center, opacity, proj);\n}\n";
export default computeGsplatProjectCommonSource;