From 290538752acbabaa7025e632c4feb1d5b66b48e2 Mon Sep 17 00:00:00 2001 From: Denis Novozhilov Date: Fri, 24 Jun 2016 19:10:08 +0300 Subject: [PATCH 1/2] [Unity] Fix SpriteAttacher for pivots outside sprite. The case here is as follows: - create random unity sprite prefab - place sprite's pivot point outside of the sprite (say, pivot U is 2.53 and pivot V is -1.22) - try to attach this sprite via the SpriteAttacher script Expected result here would be seeing the sprite sticking with it's pivot point to the placeholder. Actual result here looks like the sprite's pivot point is somewhere in U: 1 and V: 0. The bug is caused by Mathf.InverseLerp - it just cannot return values outside of [0; 1] range. So the solution would be to make our own version of InverseLerp, which handles such situations correctly. --- spine-unity/Assets/spine-unity/Modules/SpriteAttacher.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Modules/SpriteAttacher.cs b/spine-unity/Assets/spine-unity/Modules/SpriteAttacher.cs index 5f44696ca..ceb4d2601 100644 --- a/spine-unity/Assets/spine-unity/Modules/SpriteAttacher.cs +++ b/spine-unity/Assets/spine-unity/Modules/SpriteAttacher.cs @@ -169,8 +169,8 @@ namespace Spine.Unity.Modules { attachment.SetColor(Color.white); attachment.ScaleX = 1; attachment.ScaleY = 1; - attachment.RegionOffsetX = sprite.rect.width * (0.5f - Mathf.InverseLerp(bounds.min.x, bounds.max.x, 0)) / sprite.pixelsPerUnit; - attachment.RegionOffsetY = sprite.rect.height * (0.5f - Mathf.InverseLerp(bounds.min.y, bounds.max.y, 0)) / sprite.pixelsPerUnit; + attachment.RegionOffsetX = sprite.rect.width * (0.5f - InverseLerp(bounds.min.x, bounds.max.x, 0)) / sprite.pixelsPerUnit; + attachment.RegionOffsetY = sprite.rect.height * (0.5f - InverseLerp(bounds.min.y, bounds.max.y, 0)) / sprite.pixelsPerUnit; attachment.Width = size.x; attachment.Height = size.y; attachment.RegionWidth = size.x; @@ -194,6 +194,11 @@ namespace Spine.Unity.Modules { public BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, string name) { throw new System.NotImplementedException(); } + + private float InverseLerp(float a, float b, float value) + { + return (value - a) / (b - a); + } } public static class SpriteAttachmentExtensions { From 64aa883486fef0619fcf32d396aca1432ddf9668 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 25 Jun 2016 02:05:27 +0800 Subject: [PATCH 2/2] [Unity] Remove buggy fog from default shader. --- spine-unity/Assets/spine-unity/Shaders/Skeleton.shader | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Shaders/Skeleton.shader b/spine-unity/Assets/spine-unity/Shaders/Skeleton.shader index 890aea1e3..cda7d3d76 100644 --- a/spine-unity/Assets/spine-unity/Shaders/Skeleton.shader +++ b/spine-unity/Assets/spine-unity/Shaders/Skeleton.shader @@ -8,6 +8,7 @@ Shader "Spine/Skeleton" { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } LOD 100 + Fog { Mode Off } Cull Off ZWrite Off Blend One OneMinusSrcAlpha @@ -24,8 +25,7 @@ Shader "Spine/Skeleton" { Name "Caster" Tags { "LightMode"="ShadowCaster" } Offset 1, 1 - - Fog { Mode Off } + ZWrite On ZTest LEqual Cull Off @@ -79,4 +79,4 @@ Shader "Spine/Skeleton" { } } } -} \ No newline at end of file +}