From 15c67ad74036465a58e5ae17448a6e7aed0f7d99 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 15 Mar 2019 02:17:38 +0900 Subject: [PATCH 1/9] fix #41; Doesn't work with Screen-Space Overlay --- .../UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs | 2 +- .../UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs | 7 ++++--- Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs index f67c37c..4e79616 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs @@ -467,7 +467,7 @@ namespace Coffee.UIExtensions var cam = c.worldCamera ?? Camera.main; if (c && c.renderMode != RenderMode.ScreenSpaceOverlay && cam) { - _cb.SetViewProjectionMatrices(cam.worldToCameraMatrix, cam.projectionMatrix); + _cb.SetViewProjectionMatrices(cam.worldToCameraMatrix, GL.GetGPUProjectionMatrix(cam.projectionMatrix, true)); } else { diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs index d709b1e..05bfc8a 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs @@ -215,10 +215,11 @@ namespace Coffee.UIExtensions } else { + var scale = c.transform.localScale.x; + var size = (c.transform as RectTransform).sizeDelta; var pos = c.transform.localPosition; - var pv = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2 / 2000f)); - mat.SetMatrix(s_GameVPId, pv); - mat.SetMatrix(s_GameTVPId, pv * Matrix4x4.Translate(-pos)); + 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)); } } } diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc index 5e98c61..0928e15 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc @@ -36,9 +36,10 @@ float SoftMaskInternal(float4 clipPos) fixed isSceneView = 1 - Approximately(UNITY_MATRIX_VP, _GameVP); float4 cpos = mul(_GameTVP, mul(UNITY_MATRIX_M, wpos)); view = lerp(view, cpos.xy / cpos.w * 0.5 + 0.5, isSceneView); - #endif - - #if UNITY_UV_STARTS_AT_TOP && !defined(SHADER_API_D3D11) && !defined(SHADER_API_D3D11_9X) && !defined(SHADER_API_D3D9) + #if UNITY_UV_STARTS_AT_TOP + view.y = lerp(view.y, 1 - view.y, step(0, _ProjectionParams.x)); + #endif + #elif UNITY_UV_STARTS_AT_TOP view.y = 1.0 - view.y; #endif From 9ed8d73e226ebd585c8c0bd27b50d3f1187804fc Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 15 Mar 2019 23:14:15 +0900 Subject: [PATCH 2/9] fix #41; Doesn't work with Screen-Space Camera and World-Space --- Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs index 4e79616..908e9ce 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs @@ -467,7 +467,7 @@ namespace Coffee.UIExtensions var cam = c.worldCamera ?? Camera.main; if (c && c.renderMode != RenderMode.ScreenSpaceOverlay && cam) { - _cb.SetViewProjectionMatrices(cam.worldToCameraMatrix, GL.GetGPUProjectionMatrix(cam.projectionMatrix, true)); + _cb.SetViewProjectionMatrices(cam.worldToCameraMatrix, GL.GetGPUProjectionMatrix(cam.projectionMatrix, false)); } else { From ad87680c7f258e11c4edd1b0d82e886017087317 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 15 Mar 2019 03:02:05 +0900 Subject: [PATCH 3/9] update documents for v0.7.2 --- Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md | 8 ++++++++ Assets/Coffee/UIExtensions/SoftMaskForUGUI/package.json | 2 +- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md index ced1495..2cf2d7f 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [v0.7.2](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.2) (2019-03-15) + +[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.7.1...v0.7.2) + +**Fixed bugs:** + +- Doesn't work with Screen-Space Overlay [\#41](https://github.com/mob-sakai/SoftMaskForUGUI/issues/41) + ## [v0.7.1](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.1) (2019-03-11) [Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.7.0...v0.7.1) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/package.json b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/package.json index a20eb00..bc2dbd4 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.1", + "version": "0.7.2", "unity": "2017.1", "license": "MIT", "repository": { diff --git a/CHANGELOG.md b/CHANGELOG.md index ced1495..2cf2d7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [v0.7.2](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.2) (2019-03-15) + +[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.7.1...v0.7.2) + +**Fixed bugs:** + +- Doesn't work with Screen-Space Overlay [\#41](https://github.com/mob-sakai/SoftMaskForUGUI/issues/41) + ## [v0.7.1](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.1) (2019-03-11) [Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.7.0...v0.7.1) diff --git a/package.json b/package.json index a20eb00..bc2dbd4 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.1", + "version": "0.7.2", "unity": "2017.1", "license": "MIT", "repository": { From af0b76fb055a5a7dcffd57058c71c128f9c454a1 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 15 Mar 2019 23:40:05 +0900 Subject: [PATCH 4/9] fix #41; Doesn't work with Screen-Space Overlay on Mac editor --- Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc index 0928e15..b8bb840 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc @@ -13,8 +13,8 @@ fixed Approximately(float4x4 a, float4x4 b) return step( max(d._m00,max(d._m01,max(d._m02,max(d._m03, max(d._m10,max(d._m11,max(d._m12,max(d._m13, - max(d._m20,max(d._m21,max(d._m22,max(d._m23, - max(d._m30,max(d._m31,max(d._m32,d._m33))))))))))))))), + max(d._m20,max(d._m21,max(d._m22,//max(d._m23, + max(d._m30,max(d._m31,max(d._m32,d._m33)))))))))))))), 0.01); } @@ -40,7 +40,7 @@ float SoftMaskInternal(float4 clipPos) view.y = lerp(view.y, 1 - view.y, step(0, _ProjectionParams.x)); #endif #elif UNITY_UV_STARTS_AT_TOP - view.y = 1.0 - view.y; + view.y = lerp(view.y, 1 - view.y, step(0, _ProjectionParams.x)); #endif fixed4 mask = tex2D(_SoftMaskTex, view); From d0467e9cea2e86f6531608f1d87ce667fcfeb302 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Sat, 16 Mar 2019 16:49:47 +0900 Subject: [PATCH 5/9] fix #44; The masked images all disappear if game view is maximized --- .../UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs index 05bfc8a..7c5d1b7 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs @@ -186,15 +186,6 @@ namespace Coffee.UIExtensions /// static void UpdateSceneViewMatrixForShader() { - UnityEditor.SceneView sceneView = UnityEditor.SceneView.lastActiveSceneView; - if (!sceneView || !sceneView.camera) - { - return; - } - - Camera cam = sceneView.camera; - Matrix4x4 w2c = cam.worldToCameraMatrix; - Matrix4x4 prj = cam.projectionMatrix; s_ActiveSoftMaskables.RemoveAll(x=>!x); foreach (var sm in s_ActiveSoftMaskables) From 8d0dec19ad5b8904e2268964215ab2263e52fe3c Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Sat, 16 Mar 2019 16:51:21 +0900 Subject: [PATCH 6/9] fix #42; The masked images all disappear when game view is resized --- .../UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs index 908e9ce..644fec7 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs @@ -155,6 +155,7 @@ namespace Coffee.UIExtensions { _softMaskBuffer = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default); hasChanged = true; + _hasStencilStateChanged = true; } return _softMaskBuffer; @@ -289,6 +290,7 @@ namespace Coffee.UIExtensions graphic.SetVerticesDirty(); base.OnEnable(); + _hasStencilStateChanged = false; } /// @@ -324,6 +326,7 @@ namespace Coffee.UIExtensions ReleaseRT(ref _softMaskBuffer); base.OnDisable(); + _hasStencilStateChanged = false; } /// @@ -360,6 +363,7 @@ namespace Coffee.UIExtensions graphic.SetMaterialDirty(); OnTransformParentChanged(); base.OnValidate(); + _hasStencilStateChanged = false; } #endif @@ -383,6 +387,8 @@ namespace Coffee.UIExtensions SoftMask _parent; List _children = new List(); bool _hasChanged = false; + bool _hasStencilStateChanged = false; + Material material { get { return _material ? _material : _material = new Material(s_SoftMaskShader ? s_SoftMaskShader : s_SoftMaskShader = Resources.Load("SoftMask")){ hideFlags = HideFlags.HideAndDontSave }; } } @@ -421,6 +427,11 @@ namespace Coffee.UIExtensions if (!sm._parent) { sm.UpdateMaskTexture(); + if (sm._hasStencilStateChanged) + { + sm._hasStencilStateChanged = false; + MaskUtilities.NotifyStencilStateChanged (sm); + } } } } From cd7f395a077842eccb54c5f555373a3eb7cac6ef Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Sat, 16 Mar 2019 17:08:33 +0900 Subject: [PATCH 7/9] fix #43; Pixels out of range may be read by raycaster --- .../Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs index 644fec7..50e970f 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs @@ -239,8 +239,8 @@ namespace Coffee.UIExtensions return true; } - int x = (int)(softMaskBuffer.width * sp.x / Screen.width); - int y = (int)(softMaskBuffer.height * sp.y / Screen.height); + int x = (int)((softMaskBuffer.width - 1) * Mathf.Clamp01(sp.x / Screen.width)); + int y = (int)((softMaskBuffer.height - 1) * Mathf.Clamp01(sp.y / Screen.height)); return 0.5f < GetPixelValue(x, y, interactions); } From 78b9e501b51f24adef898ace4acaaeedab849bad Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Sat, 16 Mar 2019 17:09:27 +0900 Subject: [PATCH 8/9] Release temporary RT safety --- Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs index 50e970f..4ece7d1 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs @@ -553,6 +553,7 @@ namespace Coffee.UIExtensions { if (tmpRT) { + tmpRT.Release(); RenderTexture.ReleaseTemporary(tmpRT); tmpRT = null; } From 80dd12a2b39c248d48a2ebd8f2dc8bf947ebd308 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Sat, 16 Mar 2019 23:39:46 +0900 Subject: [PATCH 9/9] update documents for v0.7.2 --- Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md | 5 ++++- CHANGELOG.md | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md index 2cf2d7f..8fff011 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md @@ -1,11 +1,14 @@ # Changelog -## [v0.7.2](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.2) (2019-03-15) +## [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) **Fixed bugs:** +- The masked images all disappear if game view is maximized [\#44](https://github.com/mob-sakai/SoftMaskForUGUI/issues/44) +- Pixels out of range may be read by raycaster [\#43](https://github.com/mob-sakai/SoftMaskForUGUI/issues/43) +- The masked images all disappear when the game view is resized [\#42](https://github.com/mob-sakai/SoftMaskForUGUI/issues/42) - Doesn't work with Screen-Space Overlay [\#41](https://github.com/mob-sakai/SoftMaskForUGUI/issues/41) ## [v0.7.1](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.1) (2019-03-11) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cf2d7f..8fff011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ # Changelog -## [v0.7.2](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.2) (2019-03-15) +## [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) **Fixed bugs:** +- The masked images all disappear if game view is maximized [\#44](https://github.com/mob-sakai/SoftMaskForUGUI/issues/44) +- Pixels out of range may be read by raycaster [\#43](https://github.com/mob-sakai/SoftMaskForUGUI/issues/43) +- The masked images all disappear when the game view is resized [\#42](https://github.com/mob-sakai/SoftMaskForUGUI/issues/42) - Doesn't work with Screen-Space Overlay [\#41](https://github.com/mob-sakai/SoftMaskForUGUI/issues/41) ## [v0.7.1](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.7.1) (2019-03-11)