Parcourir la source

[unity] Optimization: Not rendering slot alpha 0 attachments by default.

Harald Csaszar il y a 1 an
Parent
commit
5fe6da05d6

+ 36 - 6
spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs

@@ -35,6 +35,12 @@
 #define SPINE_TRIANGLECHECK // Avoid calling SetTriangles at the cost of checking for mesh differences (vertex counts, memberwise attachment list compare) every frame.
 //#define SPINE_DEBUG
 
+// New optimization option to avoid rendering fully transparent attachments at slot alpha 0.
+// Comment out this line to revert to previous behaviour.
+// You may only need this option disabled when utilizing a custom shader which
+// uses vertex color alpha for purposes other than transparency.
+#define SLOT_ALPHA_DISABLES_ATTACHMENT
+
 using System;
 using System.Collections.Generic;
 using UnityEngine;
@@ -196,7 +202,11 @@ namespace Spine.Unity {
 			Slot[] drawOrderItems = drawOrder.Items;
 			for (int i = 0; i < drawOrderCount; i++) {
 				Slot slot = drawOrderItems[i];
-				if (!slot.Bone.Active) {
+				if (!slot.Bone.Active
+#if SLOT_ALPHA_DISABLES_ATTACHMENT
+					|| slot.A == 0f
+#endif
+					) {
 					workingAttachmentsItems[i] = null;
 					continue;
 				}
@@ -267,7 +277,11 @@ namespace Spine.Unity {
 			Material lastRendererMaterial = null;
 			for (int i = 0; i < drawOrderCount; i++) {
 				Slot slot = drawOrderItems[i];
-				if (!slot.Bone.Active) continue;
+				if (!slot.Bone.Active
+#if SLOT_ALPHA_DISABLES_ATTACHMENT
+					|| slot.A == 0f
+#endif
+					) continue;
 				Attachment attachment = slot.Attachment;
 				IHasTextureRegion rendererAttachment = attachment as IHasTextureRegion;
 				if (rendererAttachment != null) {
@@ -320,7 +334,11 @@ namespace Spine.Unity {
 			Slot[] drawOrderItems = drawOrder.Items;
 			for (int i = 0; i < drawOrderCount; i++) {
 				Slot slot = drawOrderItems[i];
-				if (!slot.Bone.Active) {
+				if (!slot.Bone.Active
+#if SLOT_ALPHA_DISABLES_ATTACHMENT
+					|| slot.A == 0f
+#endif
+					) {
 					workingAttachmentsItems[i] = null;
 					continue;
 				}
@@ -789,7 +807,11 @@ namespace Spine.Unity {
 
 					for (int slotIndex = startSlot; slotIndex < endSlot; slotIndex++) {
 						Slot slot = drawOrderItems[slotIndex];
-						if (!slot.Bone.Active) continue;
+						if (!slot.Bone.Active
+#if SLOT_ALPHA_DISABLES_ATTACHMENT
+							|| slot.A == 0f
+#endif
+							) continue;
 						Attachment attachment = slot.Attachment;
 
 						rg.x = slot.R2; //r
@@ -832,7 +854,11 @@ namespace Spine.Unity {
 
 				for (int slotIndex = startSlot; slotIndex < endSlot; slotIndex++) {
 					Slot slot = drawOrderItems[slotIndex];
-					if (!slot.Bone.Active) continue;
+					if (!slot.Bone.Active
+#if SLOT_ALPHA_DISABLES_ATTACHMENT
+						|| slot.A == 0f
+#endif
+						) continue;
 					Attachment attachment = slot.Attachment;
 					float z = slotIndex * settings.zSpacing;
 
@@ -988,7 +1014,11 @@ namespace Spine.Unity {
 					Slot[] drawOrderItems = skeleton.DrawOrder.Items;
 					for (int slotIndex = submeshInstruction.startSlot, endSlot = submeshInstruction.endSlot; slotIndex < endSlot; slotIndex++) {
 						Slot slot = drawOrderItems[slotIndex];
-						if (!slot.Bone.Active) continue;
+						if (!slot.Bone.Active
+#if SLOT_ALPHA_DISABLES_ATTACHMENT
+							|| slot.A == 0f
+#endif
+							) continue;
 
 						Attachment attachment = drawOrderItems[slotIndex].Attachment;
 						if (attachment is RegionAttachment) {

+ 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.34",
+	"version": "4.2.35",
 	"unity": "2018.3",
 	"author": {
 		"name": "Esoteric Software",

+ 1 - 1
spine-unity/Modules/com.esotericsoftware.spine.timeline/package-no-spine-unity-dependency.json

@@ -2,7 +2,7 @@
 	"name": "com.esotericsoftware.spine.timeline",
 	"displayName": "Spine Timeline Extensions",
 	"description": "This plugin provides integration of spine-unity for the Unity Timeline.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime (via the spine-unity unitypackage), version 4.2.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)",
-	"version": "4.2.14",
+	"version": "4.2.15",
 	"unity": "2018.3",
 	"author": {
 		"name": "Esoteric Software",