diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md index ced1495..8fff011 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## [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) [Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.7.0...v0.7.1) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs index f67c37c..4ece7d1 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; @@ -238,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); } @@ -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); + } } } } @@ -467,7 +478,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, false)); } else { @@ -542,6 +553,7 @@ namespace Coffee.UIExtensions { if (tmpRT) { + tmpRT.Release(); RenderTexture.ReleaseTemporary(tmpRT); tmpRT = null; } diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMaskable.cs index d709b1e..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) @@ -215,10 +206,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..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); } @@ -36,10 +36,11 @@ 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) - view.y = 1.0 - view.y; + #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 = lerp(view.y, 1 - view.y, step(0, _ProjectionParams.x)); #endif fixed4 mask = tex2D(_SoftMaskTex, view); 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..8fff011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## [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) [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": {