UNPKG

playcanvas

Version:

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

96 lines (94 loc) 2.46 kB
var gsplat_default = ` #include "gsplatCommonVS" varying mediump vec2 gaussianUV; varying mediump vec4 gaussianColor; #ifndef DITHER_NONE varying float id; #endif mediump vec4 discardVec = vec4(0.0, 0.0, 2.0, 1.0); #ifdef PREPASS_PASS varying float vLinearDepth; #endif #if defined(GSPLAT_UNIFIED_ID) && defined(PICK_PASS) flat varying uint vPickId; #endif #ifdef GSPLAT_OVERDRAW uniform sampler2D colorRamp; uniform float colorRampIntensity; #endif void main(void) { SplatSource source; if (!initSource(source)) { gl_Position = discardVec; return; } vec3 modelCenter = getCenter(); SplatCenter center; center.modelCenterOriginal = modelCenter; modifySplatCenter(modelCenter); center.modelCenterModified = modelCenter; if (!initCenter(modelCenter, center)) { gl_Position = discardVec; return; } SplatCorner corner; if (!initCorner(source, center, corner)) { gl_Position = discardVec; return; } #ifdef GSPLAT_SEPARATE_OPACITY float opacity = getOpacity(); vec4 clr = vec4(getColor(), opacity); #else vec4 clr = getColor(); #endif #if GSPLAT_AA clr.a *= corner.aaFactor; #endif #if SH_BANDS > 0 vec3 dir = normalize(center.view * mat3(center.modelView)); vec3 sh[SH_COEFFS]; float scale; readSHData(sh, scale); clr.xyz += evalSH(sh, dir) * scale; #endif modifySplatColor(modelCenter, clr); #if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS) float alphaClipValue = alphaClip; #else float alphaClipValue = alphaClipForward; #endif if (clr.w <= alphaClipValue) { gl_Position = discardVec; return; } clipCorner(corner, clr.w); #if GSPLAT_2DGS vec3 modelCorner = center.modelCenterModified + corner.offset; gl_Position = matrix_projection * center.modelView * vec4(modelCorner, 1.0); #else gl_Position = center.proj + vec4(corner.offset.xyz, 0); #endif gaussianUV = corner.uv; #ifdef GSPLAT_OVERDRAW float t = clamp(modelCenter.y / 20.0, 0.0, 1.0); vec3 rampColor = textureLod(colorRamp, vec2(t, 0.5), 0.0).rgb; clr.a *= (1.0 / 32.0) * colorRampIntensity; gaussianColor = vec4(rampColor, clr.a); #else gaussianColor = vec4(prepareOutputFromGamma(max(clr.xyz, 0.0), -center.view.z), clr.w); #endif #ifndef DITHER_NONE id = float(splat.index); #endif #ifdef PREPASS_PASS vLinearDepth = -center.view.z; #endif #if defined(GSPLAT_UNIFIED_ID) && defined(PICK_PASS) vPickId = loadPcId().r; #endif } `; export { gsplat_default as default };