From c7017067ea2cbf2f91a7dad0c235e0408638b9bd Mon Sep 17 00:00:00 2001 From: pharan Date: Sat, 30 Sep 2017 20:37:31 +0800 Subject: [PATCH 1/4] [unity] Fix Tint and TintBlack shaders ignoring alpha. --- .../spine-unity/Modules/Shaders/Spine-Skeleton-Tint.shader | 2 +- .../Shaders/Spine-SkeletonGraphic-TintBlack.shader | 2 +- .../Assets/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Modules/Shaders/Spine-Skeleton-Tint.shader b/spine-unity/Assets/spine-unity/Modules/Shaders/Spine-Skeleton-Tint.shader index 3ef83b319..117ae495e 100644 --- a/spine-unity/Assets/spine-unity/Modules/Shaders/Spine-Skeleton-Tint.shader +++ b/spine-unity/Assets/spine-unity/Modules/Shaders/Spine-Skeleton-Tint.shader @@ -52,7 +52,7 @@ Shader "Spine/Skeleton Tint" { float4 frag (VertexOutput i) : COLOR { float4 texColor = tex2D(_MainTex, i.uv); - return (texColor * i.vertexColor) + float4(((1-texColor.rgb) * texColor.a * _Black.rgb), 0); + return (texColor * i.vertexColor) + float4(((1-texColor.rgb) * _Black.rgb * texColor.a*_Color.a*i.vertexColor.a), 0); } ENDCG } diff --git a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic-TintBlack.shader b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic-TintBlack.shader index b45e14749..696d66006 100644 --- a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic-TintBlack.shader +++ b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/Shaders/Spine-SkeletonGraphic-TintBlack.shader @@ -110,7 +110,7 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)" clip (texColor.a - 0.001); #endif - return (texColor * IN.color) + float4(((1-texColor.rgb) * texColor.a * (_Black.rgb + float3(IN.uv1.r, IN.uv1.g, IN.uv2.r))), 0); + return (texColor * IN.color) + float4(((1-texColor.rgb) * (_Black.rgb + float3(IN.uv1.r, IN.uv1.g, IN.uv2.r)) * texColor.a*_Color.a*i.vertexColor.a), 0); } ENDCG } diff --git a/spine-unity/Assets/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader b/spine-unity/Assets/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader index 5e3420499..7eeca1e75 100644 --- a/spine-unity/Assets/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader +++ b/spine-unity/Assets/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader @@ -61,7 +61,7 @@ Shader "Spine/Skeleton Tint Black" { float4 frag (VertexOutput i) : COLOR { float4 texColor = tex2D(_MainTex, i.uv); - return (texColor * i.vertexColor) + float4(((1-texColor.rgb) * texColor.a * (_Black.rgb + float3(i.uv1.r, i.uv1.g, i.uv2.r))), 0); + return (texColor * i.vertexColor) + float4(((1-texColor.rgb) * (_Black.rgb + float3(i.uv1.r, i.uv1.g, i.uv2.r)) * texColor.a*_Color.a*i.vertexColor.a), 0); } ENDCG } From 145d1b6aef9edd83fe4325190a09bef8fd98b9f6 Mon Sep 17 00:00:00 2001 From: pharan Date: Sat, 30 Sep 2017 20:37:59 +0800 Subject: [PATCH 2/4] [unity] Minor doc. --- spine-unity/Assets/spine-unity/SkeletonRenderer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs index 1d2f004aa..e12b0b0d0 100644 --- a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs +++ b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs @@ -213,7 +213,7 @@ namespace Spine.Unity { for (int i = 0; i < separatorSlotNames.Length; i++) separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i])); - LateUpdate(); + LateUpdate(); // Generate mesh for the first frame it exists. if (OnRebuild != null) OnRebuild(this); From 4b3710abae3b38fad0d6e22b8a3a458610ba2b0a Mon Sep 17 00:00:00 2001 From: pharan Date: Sat, 30 Sep 2017 20:38:22 +0800 Subject: [PATCH 3/4] [unity] Update SkeletonExtensions. --- spine-unity/Assets/spine-unity/SkeletonExtensions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs index e178907a0..e81435733 100644 --- a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs +++ b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs @@ -144,6 +144,12 @@ namespace Spine.Unity { return new Quaternion(0, 0, Mathf.Sin(halfRotation), Mathf.Cos(halfRotation)); } + /// Gets a bone-local space UnityEngine.Quaternion representation of bone.rotation. + public static Quaternion GetLocalQuaternion (this Bone bone) { + var halfRotation = bone.rotation * Mathf.Deg2Rad * 0.5f; + return new Quaternion(0, 0, Mathf.Sin(halfRotation), Mathf.Cos(halfRotation)); + } + /// Gets the PointAttachment's Unity World position using its Spine GameObject Transform. public static Vector3 GetWorldPosition (this PointAttachment attachment, Slot slot, Transform spineGameObjectTransform) { Vector3 skeletonSpacePosition; @@ -288,6 +294,10 @@ namespace Spine { return va.bones != null && va.bones.Length > 0; } + public static bool IsRenderable (this Attachment a) { + return a is RegionAttachment || a is MeshAttachment; + } + #region Transform Modes public static bool InheritsRotation (this TransformMode mode) { const int RotationBit = 0; From be753eb672fee88c0d6dd033d1898f8c2f834060 Mon Sep 17 00:00:00 2001 From: pharan Date: Sat, 30 Sep 2017 20:39:24 +0800 Subject: [PATCH 4/4] [unity] Minor cleanup of SkeletonBaker code. --- .../spine-unity/Editor/SkeletonBaker.cs | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs index 699c7aef5..b9e04b5a0 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs @@ -457,7 +457,7 @@ namespace Spine.Unity.Editor { static Bone extractionBone; static Slot extractionSlot; - static Bone GetExtractionBone () { + internal static Bone GetExtractionBone () { if (extractionBone != null) return extractionBone; @@ -479,7 +479,7 @@ namespace Spine.Unity.Editor { return extractionBone; } - static Slot GetExtractionSlot () { + internal static Slot GetExtractionSlot () { if (extractionSlot != null) return extractionSlot; @@ -491,11 +491,14 @@ namespace Spine.Unity.Editor { return extractionSlot; } - static Mesh ExtractRegionAttachment (string name, RegionAttachment attachment, Mesh mesh = null) { + internal static Mesh ExtractRegionAttachment (string name, RegionAttachment attachment, Mesh mesh = null, bool centered = true) { var bone = GetExtractionBone(); - bone.X = -attachment.X; - bone.Y = -attachment.Y; + if (centered) { + bone.X = -attachment.X; + bone.Y = -attachment.Y; + } + bone.UpdateWorldTransform(); Vector2[] uvs = ExtractUV(attachment.UVs); @@ -504,12 +507,13 @@ namespace Spine.Unity.Editor { Vector3[] verts = ExtractVerts(floatVerts); //unrotate verts now that they're centered - for (int i = 0; i < verts.Length; i++) { - verts[i] = Quaternion.Euler(0, 0, -attachment.Rotation) * verts[i]; + if (centered) { + for (int i = 0; i < verts.Length; i++) + verts[i] = Quaternion.Euler(0, 0, -attachment.Rotation) * verts[i]; } - int[] triangles = new int[6] { 1, 3, 0, 2, 3, 1 }; - Color color = new Color(attachment.R, attachment.G, attachment.B, attachment.A); + int[] triangles = { 1, 3, 0, 2, 3, 1 }; + Color color = attachment.GetColor(); if (mesh == null) mesh = new Mesh(); @@ -519,7 +523,7 @@ namespace Spine.Unity.Editor { mesh.vertices = verts; mesh.uv = uvs; mesh.triangles = triangles; - mesh.colors = new Color[] { color, color, color, color }; + mesh.colors = new [] { color, color, color, color }; mesh.RecalculateBounds(); mesh.RecalculateNormals(); mesh.name = name; @@ -527,7 +531,7 @@ namespace Spine.Unity.Editor { return mesh; } - static Mesh ExtractMeshAttachment (string name, MeshAttachment attachment, Mesh mesh = null) { + internal static Mesh ExtractMeshAttachment (string name, MeshAttachment attachment, Mesh mesh = null) { var slot = GetExtractionSlot(); slot.Bone.X = 0; @@ -592,7 +596,7 @@ namespace Spine.Unity.Editor { } } - static Mesh ExtractWeightedMeshAttachment (string name, MeshAttachment attachment, int slotIndex, SkeletonData skeletonData, List boneList, Mesh mesh = null) { + internal static Mesh ExtractWeightedMeshAttachment (string name, MeshAttachment attachment, int slotIndex, SkeletonData skeletonData, List boneList, Mesh mesh = null) { if (attachment.Bones == null) throw new System.ArgumentException("Mesh is not weighted.", "attachment"); @@ -708,7 +712,7 @@ namespace Spine.Unity.Editor { return mesh; } - static Vector2[] ExtractUV (float[] floats) { + internal static Vector2[] ExtractUV (float[] floats) { Vector2[] arr = new Vector2[floats.Length / 2]; for (int i = 0; i < floats.Length; i += 2) { @@ -718,7 +722,7 @@ namespace Spine.Unity.Editor { return arr; } - static Vector3[] ExtractVerts (float[] floats) { + internal static Vector3[] ExtractVerts (float[] floats) { Vector3[] arr = new Vector3[floats.Length / 2]; for (int i = 0; i < floats.Length; i += 2) {