From 928f4b8e146b10def2a99666138615aa2d66ac03 Mon Sep 17 00:00:00 2001 From: badlogic Date: Mon, 29 May 2017 11:45:19 +0200 Subject: [PATCH 1/8] [c] Incorrect deallocation order, closes #913 --- spine-c/spine-c/src/spine/AnimationState.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-c/spine-c/src/spine/AnimationState.c b/spine-c/spine-c/src/spine/AnimationState.c index 6c4733eec..503337637 100644 --- a/spine-c/spine-c/src/spine/AnimationState.c +++ b/spine-c/spine-c/src/spine/AnimationState.c @@ -236,8 +236,8 @@ void spAnimationState_dispose (spAnimationState* self) { _spEventQueue_free(internal->queue); FREE(internal->events); FREE(internal->propertyIDs); - FREE(internal); spTrackEntryArray_dispose(self->mixingTo); + FREE(internal); } void spAnimationState_update (spAnimationState* self, float delta) { From d288fab6648fb2dd3dee3a2e58e75b6bfeeacdb6 Mon Sep 17 00:00:00 2001 From: pharan Date: Tue, 30 May 2017 19:20:06 +0800 Subject: [PATCH 2/8] [unity] Handle TextAssets not found. --- .../Assets/spine-unity/Editor/SpineEditorUtilities.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs index 302f94067..f7edf6e55 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs @@ -589,7 +589,8 @@ namespace Spine.Unity.Editor { imagePaths.Add(str); break; case ".json": - if (IsSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)))) + var jsonAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)); + if (jsonAsset != null && IsSpineData(jsonAsset)) skeletonPaths.Add(str); break; case ".bytes": @@ -1215,6 +1216,8 @@ namespace Spine.Unity.Editor { } public static bool IsSpineData (TextAsset asset) { + if (asset == null) return false; + bool isSpineData = false; string rawVersion = null; From 5fcb77eb1a6c3c8ddbb1180e3619a568d0705722 Mon Sep 17 00:00:00 2001 From: pharan Date: Tue, 30 May 2017 19:20:39 +0800 Subject: [PATCH 3/8] [unity] Match pre-initialized buffer size of submesh indices. --- spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs b/spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs index 162427990..978b9b9ee 100644 --- a/spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs +++ b/spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs @@ -110,9 +110,9 @@ namespace Spine.Unity { const float BoundsMinDefault = float.MaxValue; const float BoundsMaxDefault = float.MinValue; - [NonSerialized] readonly ExposedList vertexBuffer = new ExposedList(); - [NonSerialized] readonly ExposedList uvBuffer = new ExposedList(); - [NonSerialized] readonly ExposedList colorBuffer = new ExposedList(); + [NonSerialized] readonly ExposedList vertexBuffer = new ExposedList(4); + [NonSerialized] readonly ExposedList uvBuffer = new ExposedList(4); + [NonSerialized] readonly ExposedList colorBuffer = new ExposedList(4); [NonSerialized] readonly ExposedList> submeshes = new ExposedList> { new ExposedList(6) }; // start with 1 submesh. [NonSerialized] Vector2 meshBoundsMin, meshBoundsMax; From dfddf15d0af80008d4d95965957cec1bb2a3388f Mon Sep 17 00:00:00 2001 From: pharan Date: Tue, 30 May 2017 19:21:24 +0800 Subject: [PATCH 4/8] [unity] SkeletonLit shader no longer requires mesh normals. --- .../Shaders/Spine-SkeletonLit.shader | 158 +++++++++++++++--- 1 file changed, 131 insertions(+), 27 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Shaders/Spine-SkeletonLit.shader b/spine-unity/Assets/spine-unity/Shaders/Spine-SkeletonLit.shader index 4c2279974..1917340ee 100644 --- a/spine-unity/Assets/spine-unity/Shaders/Spine-SkeletonLit.shader +++ b/spine-unity/Assets/spine-unity/Shaders/Spine-SkeletonLit.shader @@ -1,9 +1,13 @@ -Shader "Spine/Skeleton Lit" { +// - Vertex Lit + ShadowCaster +// - Premultiplied Alpha Blending (One OneMinusSrcAlpha) +// - Double-sided, no depth + +Shader "Spine/Skeleton Lit" { Properties { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 - [NoScaleOffset] _MainTex ("Texture to blend", 2D) = "black" {} + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} } - // 2 texture stage GPUs + SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } LOD 100 @@ -12,14 +16,132 @@ ZWrite Off Blend One OneMinusSrcAlpha +// Pass { +// Tags { "LightMode"="Vertex" } +// ColorMaterial AmbientAndDiffuse +// Lighting On +// SetTexture [_MainTex] { +// Combine texture * primary DOUBLE, texture * primary +// } +// } + Pass { - Tags { "LightMode"="Vertex" } - ColorMaterial AmbientAndDiffuse - Lighting On - SetTexture [_MainTex] { - Combine texture * primary DOUBLE, texture * primary + Tags { + "LIGHTMODE"="Vertex" + "QUEUE"="Transparent" + "IGNOREPROJECTOR"="true" + "RenderType"="Transparent" } - } + + ZWrite Off + Cull Off + Blend One OneMinusSrcAlpha + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 2.0 + #include "UnityCG.cginc" + + // ES2.0/WebGL/3DS can not do loops with non-constant-expression iteration counts :( + #if defined(SHADER_API_GLES) + #define LIGHT_LOOP_LIMIT 8 + #elif defined(SHADER_API_N3DS) + #define LIGHT_LOOP_LIMIT 4 + #else + #define LIGHT_LOOP_LIMIT unity_VertexLightParams.x + #endif + + #pragma multi_compile __ POINT SPOT + + half3 computeLighting (int idx, half3 dirToLight, half3 eyeNormal, half3 viewDir, half4 diffuseColor, half atten) { + half NdotL = max(dot(eyeNormal, dirToLight), 0.0); + // diffuse + half3 color = NdotL * diffuseColor.rgb * unity_LightColor[idx].rgb; + return color * atten; + } + + half3 computeOneLight (int idx, float3 eyePosition, half3 eyeNormal, half3 viewDir, half4 diffuseColor) { + float3 dirToLight = unity_LightPosition[idx].xyz; + half att = 1.0; + + #if defined(POINT) || defined(SPOT) + dirToLight -= eyePosition * unity_LightPosition[idx].w; + + // distance attenuation + float distSqr = dot(dirToLight, dirToLight); + att /= (1.0 + unity_LightAtten[idx].z * distSqr); + if (unity_LightPosition[idx].w != 0 && distSqr > unity_LightAtten[idx].w) att = 0.0; // set to 0 if outside of range + distSqr = max(distSqr, 0.000001); // don't produce NaNs if some vertex position overlaps with the light + dirToLight *= rsqrt(distSqr); + #if defined(SPOT) + + // spot angle attenuation + half rho = max(dot(dirToLight, unity_SpotDirection[idx].xyz), 0.0); + half spotAtt = (rho - unity_LightAtten[idx].x) * unity_LightAtten[idx].y; + att *= saturate(spotAtt); + #endif + #endif + + att *= 0.5; // passed in light colors are 2x brighter than what used to be in FFP + return min (computeLighting (idx, dirToLight, eyeNormal, viewDir, diffuseColor, att), 1.0); + } + + int4 unity_VertexLightParams; // x: light count, y: zero, z: one (y/z needed by d3d9 vs loop instruction) + + struct appdata { + float3 pos : POSITION; + float3 normal : NORMAL; + half4 color : COLOR; + float3 uv0 : TEXCOORD0; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct VertexOutput { + fixed4 color : COLOR0; + float2 uv0 : TEXCOORD0; + float4 pos : SV_POSITION; + UNITY_VERTEX_OUTPUT_STEREO + }; + + VertexOutput vert (appdata v) { + VertexOutput o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + half4 color = v.color; + float3 eyePos = UnityObjectToViewPos(float4(v.pos, 1)).xyz; //mul(UNITY_MATRIX_MV, float4(v.pos,1)).xyz; + half3 fixedNormal = half3(0,0,-1); + half3 eyeNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, fixedNormal)); + half3 viewDir = 0.0; + + // Lights + half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb; + for (int il = 0; il < LIGHT_LOOP_LIMIT; ++il) { + lcolor += computeOneLight(il, eyePos, eyeNormal, viewDir, color); + } + + color.rgb = lcolor.rgb; + o.color = saturate(color); + o.uv0 = v.uv0; + o.pos = UnityObjectToClipPos(v.pos); + return o; + } + + sampler2D _MainTex; + + fixed4 frag (VertexOutput i) : SV_Target { + fixed4 tex = tex2D(_MainTex, i.uv0); + + fixed4 col; + col.rgb = tex * i.color; + col *= 2; + col.a = tex.a * i.color.a; + return col; + } + ENDCG + + } Pass { Name "Caster" @@ -63,22 +185,4 @@ ENDCG } } - // 1 texture stage GPUs - SubShader { - Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } - LOD 100 - - Cull Off - ZWrite Off - Blend One OneMinusSrcAlpha - - Pass { - Tags { "LightMode"="Vertex" } - ColorMaterial AmbientAndDiffuse - Lighting On - SetTexture [_MainTex] { - Combine texture * primary DOUBLE, texture * primary - } - } - } } \ No newline at end of file From a7f03b15879732d41275778d5d8537ad9cff8ad1 Mon Sep 17 00:00:00 2001 From: pharan Date: Tue, 30 May 2017 19:22:12 +0800 Subject: [PATCH 5/8] [unity] Skeleton shader property inspector now says "Main Texture" --- spine-unity/Assets/spine-unity/Shaders/Spine-Skeleton.shader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-unity/Assets/spine-unity/Shaders/Spine-Skeleton.shader b/spine-unity/Assets/spine-unity/Shaders/Spine-Skeleton.shader index 2f8091b57..2741ba504 100644 --- a/spine-unity/Assets/spine-unity/Shaders/Spine-Skeleton.shader +++ b/spine-unity/Assets/spine-unity/Shaders/Spine-Skeleton.shader @@ -1,7 +1,7 @@ Shader "Spine/Skeleton" { Properties { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 - [NoScaleOffset] _MainTex ("Texture to blend", 2D) = "black" {} + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} } SubShader { From da0132b3331f41733aca7671faf25e7a3c7d0176 Mon Sep 17 00:00:00 2001 From: pharan Date: Tue, 30 May 2017 19:25:13 +0800 Subject: [PATCH 6/8] [unity] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8dcb3e08..37b4d729d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -97,6 +97,7 @@ * **Spine folder**. In the unitypackage, the "spine-csharp" and "spine-unity" folders are now inside a "Spine" folder. This change will only affect fresh imports. Importing the unitypackage to update Spine-Unity in your existing project will update the appropriate files however you chose to arrange them, as long as the meta files are intact. * **Breaking changes** * The Sprite shaders module was updated to the latest version from the [source](https://github.com/traggett/UnitySpriteShaders/commits/master). Some changes were made to the underlying keyword structure. You may need to review the settings of your lit materials. Particularly, your Fixed Normals settings. + * The `Spine/Skeleton Lit` shader was switched over to non-fixed-function code. It now no longer requires mesh normals and has fixed normals at the shader level. * The old MeshGenerator classes, interfaces and code in `Spine.Unity.MeshGeneration` are now deprecated. All mesh-generating components now share the class `Spine.Unity.MeshGenerator` defined in `SpineMesh.cs`. MeshGenerator is a serializable class. * The `SkeletonRenderer.renderMeshes` optimization is currently non-functional. * Old triangle-winding code has been removed from `SkeletonRenderer`. Please use shaders that have backface culling off. From e781ad9ccd8aad6ae6bf017d8fbc5e5584b1c175 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 30 May 2017 21:52:45 +0800 Subject: [PATCH 7/8] [unity] Fix default mesh bounds check. --- spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs b/spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs index 978b9b9ee..14efdeecf 100644 --- a/spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs +++ b/spine-unity/Assets/spine-unity/Mesh Generation/SpineMesh.cs @@ -107,8 +107,8 @@ namespace Spine.Unity { } } - const float BoundsMinDefault = float.MaxValue; - const float BoundsMaxDefault = float.MinValue; + const float BoundsMinDefault = float.PositiveInfinity; + const float BoundsMaxDefault = float.NegativeInfinity; [NonSerialized] readonly ExposedList vertexBuffer = new ExposedList(4); [NonSerialized] readonly ExposedList uvBuffer = new ExposedList(4); @@ -940,7 +940,7 @@ namespace Spine.Unity { mesh.uv = ubi; mesh.colors32 = cbi; - if (meshBoundsMin.x == BoundsMinDefault) { + if (float.IsInfinity(meshBoundsMin.x)) { // meshBoundsMin.x == BoundsMinDefault // == doesn't work on float Infinity constants. mesh.bounds = new Bounds(); } else { //mesh.bounds = ArraysMeshGenerator.ToBounds(meshBoundsMin, meshBoundsMax); From 6e234f79352d8c2eca798b6e483d864f4139398d Mon Sep 17 00:00:00 2001 From: John Date: Thu, 1 Jun 2017 19:25:48 +0800 Subject: [PATCH 8/8] [unity] Fix Tint Black shader alpha. --- .../Assets/spine-unity/Shaders/Spine-Skeleton-TintBlack.shader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 729921692..5e3420499 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))), 1); + return (texColor * i.vertexColor) + float4(((1-texColor.rgb) * texColor.a * (_Black.rgb + float3(i.uv1.r, i.uv1.g, i.uv2.r))), 0); } ENDCG }