From bba3a99329a080c0924c882b04e52c61b3e227fd Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Tue, 26 Mar 2019 20:38:28 +0900 Subject: [PATCH 1/4] fix #47; In overlay mode, mask will be incorrect if the root canvas's parent position are not zero --- Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs | 2 +- .../Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs mode change 100644 => 100755 Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs old mode 100644 new mode 100755 index 4ece7d1..1139db4 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs @@ -482,7 +482,7 @@ namespace Coffee.UIExtensions } else { - var pos = c.transform.localPosition; + var pos = c.transform.position; var vm = Matrix4x4.TRS(new Vector3(-pos.x, -pos.y, -1000), Quaternion.identity, new Vector3(1, 1, -1f)); var pm = Matrix4x4.TRS(new Vector3(0, 0, -1), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2 / 10000f)); _cb.SetViewProjectionMatrices(vm, pm); diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs old mode 100644 new mode 100755 index 7c5d1b7..2210763 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs @@ -208,7 +208,7 @@ namespace Coffee.UIExtensions { var scale = c.transform.localScale.x; var size = (c.transform as RectTransform).sizeDelta; - var pos = c.transform.localPosition; + var pos = c.transform.position; mat.SetMatrix(s_GameVPId, Matrix4x4.TRS(new Vector3(0, 0, 0.5f), Quaternion.identity, new Vector3(2 / size.x, 2 / size.y, 0.0005f * scale))); mat.SetMatrix(s_GameTVPId, Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2/2000f)) * Matrix4x4.Translate(-pos)); } From 6a15aaaeb2f5ef3722f62f44425f1fc520d678a2 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Wed, 1 May 2019 17:00:46 +0900 Subject: [PATCH 2/4] close #49; Camera movement affects the mask rendering when on a World Space Canvas --- .../SoftMaskForUGUI/Scripts/SoftMask.cs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs index 1139db4..7a817a8 100755 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs @@ -388,7 +388,10 @@ namespace Coffee.UIExtensions List _children = new List(); bool _hasChanged = false; bool _hasStencilStateChanged = false; - +#if !UNITY_2018_1_OR_NEWER + static readonly Dictionary s_previousViewProjectionMatrices = new Dictionary (); + static readonly Dictionary s_nowViewProjectionMatrices = new Dictionary (); +#endif Material material { get { return _material ? _material : _material = new Material(s_SoftMaskShader ? s_SoftMaskShader : s_SoftMaskShader = Resources.Load("SoftMask")){ hideFlags = HideFlags.HideAndDontSave }; } } @@ -404,6 +407,27 @@ namespace Coffee.UIExtensions if (!sm || sm._hasChanged) continue; + var canvas = sm.graphic.canvas; + if (canvas.renderMode == RenderMode.WorldSpace) + { + var cam = canvas.worldCamera; + Matrix4x4 nowsVP = cam.projectionMatrix * cam.worldToCameraMatrix; + +#if UNITY_2018_1_OR_NEWER + Matrix4x4 previousVP = cam.reviousViewProjectionMatrix; +#else + Matrix4x4 previousVP = default(Matrix4x4); + int id = cam.GetInstanceID (); + s_previousViewProjectionMatrices.TryGetValue (id, out previousVP); + s_nowViewProjectionMatrices[id] = nowsVP; +#endif + + if (previousVP != nowsVP) + { + sm.hasChanged = true; + } + } + var rt = sm.rectTransform; if (rt.hasChanged) { @@ -434,6 +458,16 @@ namespace Coffee.UIExtensions } } } + + +#if !UNITY_2018_1_OR_NEWER + s_previousViewProjectionMatrices.Clear (); + foreach (int id in s_previousViewProjectionMatrices.Keys) + { + s_previousViewProjectionMatrices [id] = s_nowViewProjectionMatrices [id]; + } + s_nowViewProjectionMatrices.Clear (); +#endif } /// From 8b0fad6a528e52cf3d443afc40f4eafa1b6f4664 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Wed, 1 May 2019 20:47:21 +0900 Subject: [PATCH 3/4] Update readme --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6e6aa81..fbbaf8b 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,10 @@ By using SoftMask instead of default Mask, rounded edges of UI elements can be e ![](https://user-images.githubusercontent.com/12690315/50284151-7459e080-049b-11e9-9cd3-24fb476766dc.png) * Support TextMeshPro. ![](https://user-images.githubusercontent.com/12690315/50284145-71f78680-049b-11e9-8be1-ac0ccbdf0144.png) -* Make multiple holes on one background by 'Parts of parent' option +* Make multiple holes on one background by 'Parts of parent' option. ![](https://user-images.githubusercontent.com/12690315/54102470-f5c26e80-440b-11e9-89d1-899aa4dca00d.png) +* Camera movement affects the mask rendering when on a World Space Canvas. +![](https://user-images.githubusercontent.com/12690315/57015752-68540b80-6c51-11e9-8511-2d4534dd9d58.gif) #### Components @@ -86,7 +88,7 @@ Find the manifest.json file in the Packages folder of your project and edit it t ```js { "dependencies": { - "com.coffee.softmask-for-ugui": "https://github.com/mob-sakai/SoftMaskForUGUI.git#0.7.0", + "com.coffee.softmask-for-ugui": "https://github.com/mob-sakai/SoftMaskForUGUI.git#0.8.0", ... }, } From 0b6557f0360bb4c33a505b1ea6036b1b4910d8ab Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Wed, 1 May 2019 21:39:04 +0900 Subject: [PATCH 4/4] update documents for v0.8.0 --- .../Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md | 11 +++++++++++ Assets/Coffee/UIExtensions/SoftMaskForUGUI/README.md | 6 ++++-- .../Coffee/UIExtensions/SoftMaskForUGUI/package.json | 2 +- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md index 8fff011..1003f91 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## [v0.8.0](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.8.0) (2019-05-01) + +[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.7.2...v0.8.0) + +Camera movement affects the mask rendering when on a World Space Canvas. +![](https://user-images.githubusercontent.com/12690315/57015752-68540b80-6c51-11e9-8511-2d4534dd9d58.gif) + +**Fixed bugs:** + +- In overlay mode, mask will be incorrect if the root canvas's parent position are not zero [\#47](https://github.com/mob-sakai/SoftMaskForUGUI/issues/47) + ## [v0.7.2](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.2) (2019-03-16) [Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.7.1...v0.7.2) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/README.md b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/README.md index 6e6aa81..fbbaf8b 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/README.md +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/README.md @@ -57,8 +57,10 @@ By using SoftMask instead of default Mask, rounded edges of UI elements can be e ![](https://user-images.githubusercontent.com/12690315/50284151-7459e080-049b-11e9-9cd3-24fb476766dc.png) * Support TextMeshPro. ![](https://user-images.githubusercontent.com/12690315/50284145-71f78680-049b-11e9-8be1-ac0ccbdf0144.png) -* Make multiple holes on one background by 'Parts of parent' option +* Make multiple holes on one background by 'Parts of parent' option. ![](https://user-images.githubusercontent.com/12690315/54102470-f5c26e80-440b-11e9-89d1-899aa4dca00d.png) +* Camera movement affects the mask rendering when on a World Space Canvas. +![](https://user-images.githubusercontent.com/12690315/57015752-68540b80-6c51-11e9-8511-2d4534dd9d58.gif) #### Components @@ -86,7 +88,7 @@ Find the manifest.json file in the Packages folder of your project and edit it t ```js { "dependencies": { - "com.coffee.softmask-for-ugui": "https://github.com/mob-sakai/SoftMaskForUGUI.git#0.7.0", + "com.coffee.softmask-for-ugui": "https://github.com/mob-sakai/SoftMaskForUGUI.git#0.8.0", ... }, } diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/package.json b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/package.json index bc2dbd4..451eaf9 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/package.json +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/package.json @@ -2,7 +2,7 @@ "name": "com.coffee.softmask-for-ugui", "displayName": "Soft Mask For uGUI", "description": "SoftMask is a smooth masking component for uGUI elements in Unity.\nBy using SoftMask instead of default Mask, rounded edges of UI elements can be expressed beautifully.", - "version": "0.7.2", + "version": "0.8.0", "unity": "2017.1", "license": "MIT", "repository": { diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fff011..1003f91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## [v0.8.0](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.8.0) (2019-05-01) + +[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.7.2...v0.8.0) + +Camera movement affects the mask rendering when on a World Space Canvas. +![](https://user-images.githubusercontent.com/12690315/57015752-68540b80-6c51-11e9-8511-2d4534dd9d58.gif) + +**Fixed bugs:** + +- In overlay mode, mask will be incorrect if the root canvas's parent position are not zero [\#47](https://github.com/mob-sakai/SoftMaskForUGUI/issues/47) + ## [v0.7.2](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.2) (2019-03-16) [Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.7.1...v0.7.2) diff --git a/package.json b/package.json index bc2dbd4..451eaf9 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.coffee.softmask-for-ugui", "displayName": "Soft Mask For uGUI", "description": "SoftMask is a smooth masking component for uGUI elements in Unity.\nBy using SoftMask instead of default Mask, rounded edges of UI elements can be expressed beautifully.", - "version": "0.7.2", + "version": "0.8.0", "unity": "2017.1", "license": "MIT", "repository": {