Use material.premultipliedAlpha to adjust blending function (#136)

This commit is contained in:
Noeri Huisman
2025-07-25 03:26:29 +02:00
committed by GitHub
parent 3445167e7a
commit 30f50aa9ee
2 changed files with 6 additions and 25 deletions
+3 -21
View File
@@ -294,14 +294,8 @@ export class SparkRenderer extends THREE.Mesh {
vertexShader: shaders.splatVertex,
fragmentShader: shaders.splatFragment,
uniforms,
premultipliedAlpha,
transparent: true,
blending: premultipliedAlpha
? THREE.CustomBlending
: THREE.NormalBlending,
blendSrc: premultipliedAlpha ? THREE.OneFactor : THREE.SrcAlphaFactor,
blendDst: premultipliedAlpha
? THREE.OneMinusSrcAlphaFactor
: THREE.OneFactor,
depthTest: true,
depthWrite: false,
side: THREE.DoubleSide,
@@ -435,8 +429,6 @@ export class SparkRenderer extends THREE.Mesh {
time: { value: 0 },
// Delta time in seconds since last frame
deltaTime: { value: 0 },
// Whether to use premultiplied alpha when accumulating splat RGB
premultipliedAlpha: { value: true },
// Whether to encode Gsplat with linear RGB (for environment mapping)
encodeLinear: { value: false },
// Debug flag that alternates each frame
@@ -531,20 +523,10 @@ export class SparkRenderer extends THREE.Mesh {
if (isNewFrame) {
// Keep these uniforms the same for both eyes if in WebXR
const blending = this.premultipliedAlpha
? THREE.CustomBlending
: THREE.NormalBlending;
if (blending !== this.material.blending) {
this.material.blending = blending;
this.material.blendSrc = this.premultipliedAlpha
? THREE.OneFactor
: THREE.SrcAlphaFactor;
this.material.blendDst = this.premultipliedAlpha
? THREE.OneMinusSrcAlphaFactor
: THREE.OneFactor;
if (this.material.premultipliedAlpha !== this.premultipliedAlpha) {
this.material.premultipliedAlpha = this.premultipliedAlpha;
this.material.needsUpdate = true;
}
this.uniforms.premultipliedAlpha.value = this.premultipliedAlpha;
this.uniforms.time.value = time;
this.uniforms.deltaTime.value = deltaTime;
// Alternating debug flag that can aid in visual debugging
+3 -4
View File
@@ -6,7 +6,6 @@ precision highp int;
uniform float near;
uniform float far;
uniform bool premultipliedAlpha;
uniform bool encodeLinear;
uniform float maxStdDev;
uniform float minAlpha;
@@ -69,9 +68,9 @@ void main() {
rgba.rgb = srgbToLinear(rgba.rgb);
}
if (premultipliedAlpha) {
#ifdef PREMULTIPLIED_ALPHA
fragColor = vec4(rgba.rgb * rgba.a, rgba.a);
} else {
#else
fragColor = rgba;
}
#endif
}