Bladeren bron

[ts][pixi] Fixed alpha issue for mesh not using dark tint (see #2561).

Davide Tantillo 1 jaar geleden
bovenliggende
commit
99affd27c7

+ 7 - 8
spine-ts/spine-pixi/src/Spine.ts

@@ -352,8 +352,6 @@ export class Spine extends Container {
 	* 
 	* We need to take this into consideration and calculates final colors for both light and dark color as if textures were always premultiplied.
 	* This implies for example that alpha for dark tint is always 1. This is way in DarkTintRenderer we have only the alpha of the light color.
-	* We implies alpha of dark color as 1 and just respective alpha byte to 1.
-	* (see DarkTintRenderer: const darkargb = (0xFF << 24) | darkTintRGB;)
 	* If we ever want to load texture as non premultiplied on GPU, we must add a new dark alpha parameter to the TintMaterial and set the alpha.
 	*/
 	private renderMeshes (): void {
@@ -420,17 +418,18 @@ export class Spine extends Container {
 				const skeletonColor = skeleton.color;
 				const slotColor = slot.color;
 				const alpha = skeletonColor.a * slotColor.a * attachmentColor.a;
+				// cannot premultiply the colors because the default mesh renderer already does that
 				this.lightColor.set(
-					skeletonColor.r * slotColor.r * attachmentColor.r * alpha,
-					skeletonColor.g * slotColor.g * attachmentColor.g * alpha,
-					skeletonColor.b * slotColor.b * attachmentColor.b * alpha,
+					skeletonColor.r * slotColor.r * attachmentColor.r,
+					skeletonColor.g * slotColor.g * attachmentColor.g,
+					skeletonColor.b * slotColor.b * attachmentColor.b,
 					alpha
 				);
 				if (slot.darkColor != null) {
 					this.darkColor.set(
-						slot.darkColor.r * alpha,
-						slot.darkColor.g * alpha,
-						slot.darkColor.b * alpha,
+						slot.darkColor.r,
+						slot.darkColor.g,
+						slot.darkColor.b,
 						1,
 					);
 				} else {

+ 2 - 3
spine-ts/spine-pixi/src/darkTintMesh/DarkTintMaterial.ts

@@ -191,9 +191,8 @@ export class DarkTintMaterial extends Shader {
 	public update(): void {
 		if (this._colorDirty) {
 			this._colorDirty = false;
-			const missingAlphaInPMAColor = this._alpha / this._tintColor.alpha;
-			Color.shared.setValue(this._tintColor).premultiply(missingAlphaInPMAColor, true).premultiply(this._alpha, false).toArray(this.uniforms.uColor);
-			Color.shared.setValue(this._darkTintColor).premultiply(missingAlphaInPMAColor, true).premultiply(1, false).toArray(this.uniforms.uDarkColor);
+			Color.shared.setValue(this._tintColor).premultiply(this._alpha, true).toArray(this.uniforms.uColor);
+			Color.shared.setValue(this._darkTintColor).premultiply(this._alpha, true).premultiply(1, false).toArray(this.uniforms.uDarkColor);
 		}
 		if (this.uvMatrix.update()) {
 			this.uniforms.uTextureMatrix = this.uvMatrix.mapCoord;

+ 2 - 3
spine-ts/spine-pixi/src/darkTintMesh/DarkTintRenderer.ts

@@ -99,9 +99,8 @@ export class DarkTintRenderer extends BatchRenderer {
 		const vertexData = element.vertexData;
 		const textureId = element._texture.baseTexture._batchLocation;
 		const worldAlpha = Math.min(element.worldAlpha, 1.0);
-		const missingAlphaInPMAColor = worldAlpha / element.alpha;
-		const argb = Color.shared.setValue(element._tintRGB).premultiply(missingAlphaInPMAColor, true).toPremultiplied(worldAlpha, false);
-		const darkargb = Color.shared.setValue(element._darkTintRGB).premultiply(missingAlphaInPMAColor, true).toPremultiplied(1, false);
+		const argb = Color.shared.setValue(element._tintRGB).toPremultiplied(worldAlpha, true);
+		const darkargb = Color.shared.setValue(element._darkTintRGB).premultiply(worldAlpha, true).toPremultiplied(1, false);
 
 		// lets not worry about tint! for now..
 		for (let i = 0; i < vertexData.length; i += 2) {