Эх сурвалжийг харах

[unity] Fixed SkeletonGraphic TintBlack shader with `PMA Vertex Color` and `CanvasGroup Compatible` looking incorrect. Closes #2483.

Harald Csaszar 1 жил өмнө
parent
commit
41ee663279

+ 10 - 8
spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs

@@ -619,13 +619,12 @@ namespace Spine.Unity {
 					color.r = (byte)(skeletonR * slot.R * c.r * color.a);
 					color.g = (byte)(skeletonG * slot.G * c.g * color.a);
 					color.b = (byte)(skeletonB * slot.B * c.b * color.a);
-					if (slot.Data.BlendMode == BlendMode.Additive) {
-						if (canvasGroupTintBlack)
-							tintBlackAlpha = 0;
-						else
+					if (canvasGroupTintBlack) {
+						tintBlackAlpha = (slot.Data.BlendMode == BlendMode.Additive) ? 0 : colorA;
+						color.a = 255;
+					} else {
+						if (slot.Data.BlendMode == BlendMode.Additive)
 							color.a = 0;
-					} else if (canvasGroupTintBlack) { // other blend modes
-						tintBlackAlpha = colorA;
 					}
 				} else {
 					color.a = (byte)(skeletonA * slot.A * c.a * 255);
@@ -882,7 +881,9 @@ namespace Spine.Unity {
 							color.r = (byte)(r * slot.R * regionAttachment.R * color.a);
 							color.g = (byte)(g * slot.G * regionAttachment.G * color.a);
 							color.b = (byte)(b * slot.B * regionAttachment.B * color.a);
-							if (slot.Data.BlendMode == BlendMode.Additive && !canvasGroupTintBlack) color.a = 0;
+							if (canvasGroupTintBlack) color.a = 255;
+							else if (slot.Data.BlendMode == BlendMode.Additive) color.a = 0;
+
 						} else {
 							color.a = (byte)(a * slot.A * regionAttachment.A * 255);
 							color.r = (byte)(r * slot.R * regionAttachment.R * 255);
@@ -929,7 +930,8 @@ namespace Spine.Unity {
 								color.r = (byte)(r * slot.R * meshAttachment.R * color.a);
 								color.g = (byte)(g * slot.G * meshAttachment.G * color.a);
 								color.b = (byte)(b * slot.B * meshAttachment.B * color.a);
-								if (slot.Data.BlendMode == BlendMode.Additive && !canvasGroupTintBlack) color.a = 0;
+								if (canvasGroupTintBlack) color.a = 255;
+								else if (slot.Data.BlendMode == BlendMode.Additive) color.a = 0;
 							} else {
 								color.a = (byte)(a * slot.A * meshAttachment.A * 255);
 								color.r = (byte)(r * slot.R * meshAttachment.R * 255);

+ 6 - 4
spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/SkeletonGraphic/CGIncludes/Spine-SkeletonGraphic-TintBlack-NormalPass.cginc

@@ -44,18 +44,20 @@ VertexOutput vert(VertexInput IN) {
 	OUT.texcoord = IN.texcoord;
 
 	OUT.darkColor = float4(IN.uv1.r, IN.uv1.g, IN.uv2.r, IN.uv2.g);
-	OUT.darkColor.rgb = GammaToTargetSpace(OUT.darkColor.rgb) + (_Black.rgb * IN.color.a);
 
 #ifdef _CANVAS_GROUP_COMPATIBLE
 	// CanvasGroup alpha multiplies existing vertex color alpha, but
 	// does not premultiply it to rgb components. This causes problems
 	// with additive blending (alpha = 0), which is why we store the
-	// alpha value in uv2.g (darkColor.a).
-	float originalAlpha = OUT.darkColor.a;
-	OUT.canvasAlpha = (originalAlpha == 0) ? IN.color.a : IN.color.a / originalAlpha;
+	// alpha value in uv2.g (darkColor.a) and store 1.0 in vertex color alpha.
+	float originalAlpha = IN.uv2.g;
+	OUT.canvasAlpha = IN.color.a;
 #else
 	float originalAlpha = IN.color.a;
 #endif
+
+	OUT.darkColor.rgb = GammaToTargetSpace(OUT.darkColor.rgb) + (_Black.rgb * originalAlpha);
+
 	// Note: CanvasRenderer performs a GammaToTargetSpace conversion on vertex color already,
 	// however incorrectly assuming straight alpha color.
 	float4 vertexColor = PMAGammaToTargetSpace(half4(TargetToGammaSpace(IN.color.rgb), originalAlpha));

+ 7 - 6
spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs

@@ -97,7 +97,7 @@ namespace Spine.Unity {
 			+ "a) enable 'CanvasGroup Compatible' at the Material or\n"
 			+ "b) disable 'Canvas Group Tint Black' at the SkeletonGraphic component under 'Advanced'.\n"
 			+ "You may want to duplicate the 'SkeletonGraphicTintBlack' material and change settings at the duplicate to not affect all instances.";
-		public static readonly string kCanvasGroupCompatibleDisabledMessage =
+		public static readonly string kCanvasGroupTintBlackDisabledMessage =
 			"\nWarning: 'CanvasGroup Compatible' is enabled at the Material but 'Canvas Group Tint Black' is disabled at SkeletonGraphic!\n\nPlease\n"
 			+ "a) disable 'CanvasGroup Compatible' at the Material or\n"
 			+ "b) enable 'Canvas Group Tint Black' at the SkeletonGraphic component under 'Advanced'.\n"
@@ -157,16 +157,17 @@ namespace Spine.Unity {
 					isProblematic = true;
 					errorMessage += kNoSkeletonGraphicTintBlackMaterialMessage;
 				}
-				if (settings.canvasGroupTintBlack == true && !IsCanvasGroupCompatible(material)) {
+				bool isCanvasGroupCompatible = IsCanvasGroupCompatible(material);
+				if (settings.canvasGroupTintBlack == true && !isCanvasGroupCompatible) {
 					isProblematic = true;
 					errorMessage += kCanvasGroupCompatibleMessage;
 				}
-				if (settings.tintBlack == true && settings.canvasGroupTintBlack == false
-					&& IsCanvasGroupCompatible(material)) {
+				if (settings.tintBlack == true && settings.canvasGroupTintBlack == false && isCanvasGroupCompatible) {
 					isProblematic = true;
-					errorMessage += kCanvasGroupCompatibleDisabledMessage;
+					errorMessage += kCanvasGroupTintBlackDisabledMessage;
 				}
-				if (settings.pmaVertexColors == true && IsCanvasGroupCompatible(material)) {
+				if (settings.pmaVertexColors == true && settings.canvasGroupTintBlack == false
+					&& isCanvasGroupCompatible) {
 					isProblematic = true;
 					errorMessage += kCanvasGroupCompatiblePMAVertexMessage;
 				}

+ 1 - 1
spine-unity/Assets/Spine/package.json

@@ -2,7 +2,7 @@
 	"name": "com.esotericsoftware.spine.spine-unity",
 	"displayName": "spine-unity Runtime",
 	"description": "This plugin provides the spine-unity runtime core.",
-	"version": "4.2.54",
+	"version": "4.2.55",
 	"unity": "2018.3",
 	"author": {
 		"name": "Esoteric Software",