mirror of
https://github.com/storytold/spark.git
synced 2026-10-19 07:54:46 +00:00
Use material.premultipliedAlpha to adjust blending function (#136)
This commit is contained in:
+3
-21
@@ -294,14 +294,8 @@ export class SparkRenderer extends THREE.Mesh {
|
|||||||
vertexShader: shaders.splatVertex,
|
vertexShader: shaders.splatVertex,
|
||||||
fragmentShader: shaders.splatFragment,
|
fragmentShader: shaders.splatFragment,
|
||||||
uniforms,
|
uniforms,
|
||||||
|
premultipliedAlpha,
|
||||||
transparent: true,
|
transparent: true,
|
||||||
blending: premultipliedAlpha
|
|
||||||
? THREE.CustomBlending
|
|
||||||
: THREE.NormalBlending,
|
|
||||||
blendSrc: premultipliedAlpha ? THREE.OneFactor : THREE.SrcAlphaFactor,
|
|
||||||
blendDst: premultipliedAlpha
|
|
||||||
? THREE.OneMinusSrcAlphaFactor
|
|
||||||
: THREE.OneFactor,
|
|
||||||
depthTest: true,
|
depthTest: true,
|
||||||
depthWrite: false,
|
depthWrite: false,
|
||||||
side: THREE.DoubleSide,
|
side: THREE.DoubleSide,
|
||||||
@@ -435,8 +429,6 @@ export class SparkRenderer extends THREE.Mesh {
|
|||||||
time: { value: 0 },
|
time: { value: 0 },
|
||||||
// Delta time in seconds since last frame
|
// Delta time in seconds since last frame
|
||||||
deltaTime: { value: 0 },
|
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)
|
// Whether to encode Gsplat with linear RGB (for environment mapping)
|
||||||
encodeLinear: { value: false },
|
encodeLinear: { value: false },
|
||||||
// Debug flag that alternates each frame
|
// Debug flag that alternates each frame
|
||||||
@@ -531,20 +523,10 @@ export class SparkRenderer extends THREE.Mesh {
|
|||||||
|
|
||||||
if (isNewFrame) {
|
if (isNewFrame) {
|
||||||
// Keep these uniforms the same for both eyes if in WebXR
|
// Keep these uniforms the same for both eyes if in WebXR
|
||||||
const blending = this.premultipliedAlpha
|
if (this.material.premultipliedAlpha !== this.premultipliedAlpha) {
|
||||||
? THREE.CustomBlending
|
this.material.premultipliedAlpha = this.premultipliedAlpha;
|
||||||
: 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;
|
|
||||||
this.material.needsUpdate = true;
|
this.material.needsUpdate = true;
|
||||||
}
|
}
|
||||||
this.uniforms.premultipliedAlpha.value = this.premultipliedAlpha;
|
|
||||||
this.uniforms.time.value = time;
|
this.uniforms.time.value = time;
|
||||||
this.uniforms.deltaTime.value = deltaTime;
|
this.uniforms.deltaTime.value = deltaTime;
|
||||||
// Alternating debug flag that can aid in visual debugging
|
// Alternating debug flag that can aid in visual debugging
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ precision highp int;
|
|||||||
|
|
||||||
uniform float near;
|
uniform float near;
|
||||||
uniform float far;
|
uniform float far;
|
||||||
uniform bool premultipliedAlpha;
|
|
||||||
uniform bool encodeLinear;
|
uniform bool encodeLinear;
|
||||||
uniform float maxStdDev;
|
uniform float maxStdDev;
|
||||||
uniform float minAlpha;
|
uniform float minAlpha;
|
||||||
@@ -69,9 +68,9 @@ void main() {
|
|||||||
rgba.rgb = srgbToLinear(rgba.rgb);
|
rgba.rgb = srgbToLinear(rgba.rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (premultipliedAlpha) {
|
#ifdef PREMULTIPLIED_ALPHA
|
||||||
fragColor = vec4(rgba.rgb * rgba.a, rgba.a);
|
fragColor = vec4(rgba.rgb * rgba.a, rgba.a);
|
||||||
} else {
|
#else
|
||||||
fragColor = rgba;
|
fragColor = rgba;
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user