UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

3 lines (2 loc) 3.45 kB
declare const _default: "\n#include \"gsplatCommonVS\"\n\nvarying mediump vec2 gaussianUV;\nvarying mediump vec4 gaussianColor;\n\n#ifndef DITHER_NONE\n varying float id;\n#endif\n\nmediump vec4 discardVec = vec4(0.0, 0.0, 2.0, 1.0);\n\n#ifdef PREPASS_PASS\n varying float vLinearDepth;\n#endif\n\n#if defined(GSPLAT_UNIFIED_ID) && defined(PICK_PASS)\n flat varying uint vPickId;\n#endif\n\n#ifdef GSPLAT_OVERDRAW\n uniform sampler2D colorRamp;\n uniform float colorRampIntensity;\n#endif\n\nvoid main(void) {\n // read gaussian details\n SplatSource source;\n if (!initSource(source)) {\n gl_Position = discardVec;\n return;\n }\n\n vec3 modelCenter = getCenter();\n\n SplatCenter center;\n center.modelCenterOriginal = modelCenter;\n \n modifySplatCenter(modelCenter);\n center.modelCenterModified = modelCenter;\n\n if (!initCenter(modelCenter, center)) {\n gl_Position = discardVec;\n return;\n }\n\n // project center to screen space\n SplatCorner corner;\n if (!initCorner(source, center, corner)) {\n gl_Position = discardVec;\n return;\n }\n\n // read color\n #ifdef GSPLAT_SEPARATE_OPACITY\n float opacity = getOpacity(); // must run before getColor() to cache color data\n vec4 clr = vec4(getColor(), opacity);\n #else\n vec4 clr = getColor();\n #endif\n\n #if GSPLAT_AA\n // apply AA compensation\n clr.a *= corner.aaFactor;\n #endif\n\n // evaluate spherical harmonics\n #if SH_BANDS > 0\n // calculate the model-space view direction\n vec3 dir = normalize(center.view * mat3(center.modelView));\n\n // read sh coefficients\n vec3 sh[SH_COEFFS];\n float scale;\n readSHData(sh, scale);\n\n // evaluate\n clr.xyz += evalSH(sh, dir) * scale;\n #endif\n\n modifySplatColor(modelCenter, clr);\n\n // discard splats with alpha too low to contribute any visible pixel (threshold matches frag pass)\n #if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)\n float alphaClipValue = alphaClip;\n #else\n float alphaClipValue = alphaClipForward;\n #endif\n if (clr.w <= alphaClipValue) {\n gl_Position = discardVec;\n return;\n }\n\n clipCorner(corner, clr.w);\n\n // write output\n #if GSPLAT_2DGS\n // 2DGS: Project world corner directly\n vec3 modelCorner = center.modelCenterModified + corner.offset;\n gl_Position = matrix_projection * center.modelView * vec4(modelCorner, 1.0);\n #else\n gl_Position = center.proj + vec4(corner.offset.xyz, 0);\n #endif\n gaussianUV = corner.uv;\n\n #ifdef GSPLAT_OVERDRAW\n // Overdraw visualization mode: color by elevation\n float t = clamp(modelCenter.y / 20.0, 0.0, 1.0);\n vec3 rampColor = textureLod(colorRamp, vec2(t, 0.5), 0.0).rgb;\n clr.a *= (1.0 / 32.0) * colorRampIntensity;\n gaussianColor = vec4(rampColor, clr.a);\n #else\n gaussianColor = vec4(prepareOutputFromGamma(max(clr.xyz, 0.0), -center.view.z), clr.w);\n #endif\n\n #ifndef DITHER_NONE\n id = float(splat.index);\n #endif\n\n #ifdef PREPASS_PASS\n vLinearDepth = -center.view.z;\n #endif\n\n #if defined(GSPLAT_UNIFIED_ID) && defined(PICK_PASS)\n vPickId = loadPcId().r;\n #endif\n}\n"; export default _default;