playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
135 lines (109 loc) • 3.35 kB
JavaScript
var gsplat_default = (
/* glsl */
`
varying mediump vec2 gaussianUV;
varying mediump vec4 gaussianColor;
varying float id;
mediump vec4 discardVec = vec4(0.0, 0.0, 2.0, 1.0);
varying float vLinearDepth;
flat varying uint vPickId;
uniform sampler2D colorRamp;
uniform float colorRampIntensity;
void main(void) {
// read gaussian details
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;
}
// project center to screen space
SplatCorner corner;
if (!initCorner(source, center, corner)) {
gl_Position = discardVec;
return;
}
// read color
float opacity = getOpacity(); // must run before getColor() to cache color data
vec4 clr = vec4(getColor(), opacity);
vec4 clr = getColor();
// apply AA compensation
clr.a *= corner.aaFactor;
// evaluate spherical harmonics
// calculate the model-space view direction
vec3 dir = normalize(center.view * mat3(center.modelView));
// read sh coefficients
vec3 sh[SH_COEFFS];
float scale;
readSHData(sh, scale);
// evaluate
clr.xyz += evalSH(sh, dir) * scale;
modifySplatColor(modelCenter, clr);
// discard splats with alpha too low to contribute any visible pixel (threshold matches frag pass)
float alphaClipValue = alphaClip;
float alphaClipValue = alphaClipForward;
if (clr.w <= alphaClipValue) {
gl_Position = discardVec;
return;
}
clipCorner(corner, clr.w);
// write output
// 2DGS: Project world corner directly
vec3 modelCorner = center.modelCenterModified + corner.offset;
gl_Position = matrix_projection * center.modelView * vec4(modelCorner, 1.0);
gl_Position = center.proj + vec4(corner.offset.xyz, 0);
gaussianUV = corner.uv;
// Overdraw visualization mode: color by elevation
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);
gaussianColor = vec4(prepareOutputFromGamma(max(clr.xyz, 0.0), -center.view.z), clr.w);
id = float(splat.index);
vLinearDepth = -center.view.z;
vPickId = loadPcId().r;
}
`
);
export {
gsplat_default as default
};