diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43294c9..76a46c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,10 @@
+# [0.10.0-preview.2](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.10.0-preview.1...v0.10.0-preview.2) (2020-05-03)
+
+
+### Bug Fixes
+
+* visual bug with ScreenSpaceCamera canvas on editor ([482b967](https://github.com/mob-sakai/SoftMaskForUGUI/commit/482b96709b9dce680e48214df26c81b7e963dc09)), closes [#78](https://github.com/mob-sakai/SoftMaskForUGUI/issues/78)
+
# [0.10.0-preview.1](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.9.1...v0.10.0-preview.1) (2020-05-01)
diff --git a/README.md b/README.md
index 7f528a3..1858a06 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,6 @@ SoftMaskForUGUI
UI Soft Mask is a smooth masking component for Unity UI (uGUI) elements.
-By using SoftMask instead of the default Mask component, you can beautifully represent the rounded edges of UI elements.
-
![](https://user-images.githubusercontent.com/12690315/50282438-18408d80-0496-11e9-8f86-81e804edadd4.png)
[![](https://img.shields.io/npm/v/com.coffee.softmask-for-ugui?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.coffee.softmask-for-ugui/)
@@ -23,8 +21,7 @@ By using SoftMask instead of the default Mask component, you can beautifully rep
## Description
-SoftMask is a smooth masking component for uGUI elements in Unity.
-By using SoftMask instead of default Mask, rounded edges of UI elements can be expressed beautifully.
+By using SoftMask instead of the default Mask component, you can beautifully represent the rounded edges of UI elements.
![](https://user-images.githubusercontent.com/12690315/50282806-4b375100-0497-11e9-891c-35309d332c7b.png)
@@ -77,7 +74,7 @@ By using SoftMask instead of default Mask, rounded edges of UI elements can be e
-## Install
+## Installation
#### Requirement
@@ -128,13 +125,15 @@ Or, use [UpmGitExtension](https://github.com/mob-sakai/UpmGitExtension) to insta
1. Open `Package Manager` window and select `UI Soft Mask` package in package list
2. Click `Import in project` button
![](https://user-images.githubusercontent.com/12690315/79000480-a8bd4880-7b87-11ea-89c7-a17033a486ba.png)
-3. The demo will be imported into `Assets/Samples/UI Soft Mask/{version}/Demo`; open `UISoftMask_Demo` scene and play it
+3. The demo will be imported into `Assets/Samples/UI Soft Mask/{version}/Demo`。
+Open `UISoftMask_Demo` scene and play it
#### For Unity 2018.4 or earlier
1. Select `Assets/Samples/UI Soft Mask Demo` from menu
![Assets_と_Menubar](https://user-images.githubusercontent.com/12690315/79001101-dd7dcf80-7b88-11ea-9cf2-b44c6c5c9b17.png)
-2. The demo will be imported into `Assets/Samples/UI Soft Mask/{version}/Demo`; open `UISoftMask_Demo` scene and play it
+2. The demo will be imported into `Assets/Samples/UI Soft Mask/{version}/Demo`.
+Open `UISoftMask_Demo` scene and play it
diff --git a/Samples~/Demo/SoftMask_Demo.unity b/Samples~/Demo/SoftMask_Demo.unity
index 5c53bc4..2ebfe05 100644
--- a/Samples~/Demo/SoftMask_Demo.unity
+++ b/Samples~/Demo/SoftMask_Demo.unity
@@ -8933,9 +8933,9 @@ RectTransform:
m_Father: {fileID: 1251643234}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
- m_AnchorMin: {x: 0, y: 0}
- m_AnchorMax: {x: 0, y: 0}
- m_AnchoredPosition: {x: 0, y: 0}
+ m_AnchorMin: {x: 0, y: 1}
+ m_AnchorMax: {x: 0, y: 1}
+ m_AnchoredPosition: {x: 260.00003, y: -36}
m_SizeDelta: {x: 233.9, y: 36}
m_Pivot: {x: 0, y: 0}
--- !u!114 &870704027
@@ -10509,7 +10509,7 @@ MonoBehaviour:
m_Inverse: 0
m_MaskInteraction: 85
m_UseStencil: 0
- m_RaycastFilter: 0
+ m_RaycastFilter: 1
--- !u!114 &1042560009
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -11068,9 +11068,9 @@ RectTransform:
m_Father: {fileID: 1251643234}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
- m_AnchorMin: {x: 0, y: 0}
- m_AnchorMax: {x: 0, y: 0}
- m_AnchoredPosition: {x: 0, y: 0}
+ m_AnchorMin: {x: 0, y: 1}
+ m_AnchorMax: {x: 0, y: 1}
+ m_AnchoredPosition: {x: 0, y: -36}
m_SizeDelta: {x: 233.9, y: 36}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1095566242
@@ -12528,7 +12528,7 @@ MonoBehaviour:
m_Inverse: 0
m_MaskInteraction: 85
m_UseStencil: 0
- m_RaycastFilter: 0
+ m_RaycastFilter: 1
--- !u!114 &1255989375
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -14906,7 +14906,7 @@ MonoBehaviour:
m_Inverse: 0
m_MaskInteraction: 85
m_UseStencil: 0
- m_RaycastFilter: 0
+ m_RaycastFilter: 1
--- !u!114 &1479323601
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -17374,9 +17374,9 @@ RectTransform:
m_Father: {fileID: 1251643234}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
- m_AnchorMin: {x: 0, y: 0}
- m_AnchorMax: {x: 0, y: 0}
- m_AnchoredPosition: {x: 0, y: 0}
+ m_AnchorMin: {x: 0, y: 1}
+ m_AnchorMax: {x: 0, y: 1}
+ m_AnchoredPosition: {x: 520.00006, y: -36}
m_SizeDelta: {x: 233.9, y: 36}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1731734725
@@ -21606,6 +21606,7 @@ GameObject:
- component: {fileID: 2105854283}
- component: {fileID: 2105854282}
- component: {fileID: 2105854281}
+ - component: {fileID: 2105854284}
m_Layer: 5
m_Name: SoftMask (0)
m_TagString: Untagged
@@ -21689,6 +21690,18 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2105854279}
m_CullTransparentMesh: 0
+--- !u!225 &2105854284
+CanvasGroup:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 2105854279}
+ m_Enabled: 1
+ m_Alpha: 1
+ m_Interactable: 1
+ m_BlocksRaycasts: 0
+ m_IgnoreParentGroups: 0
--- !u!1 &2113892777
GameObject:
m_ObjectHideFlags: 0
diff --git a/Scripts/SoftMask.cs b/Scripts/SoftMask.cs
old mode 100644
new mode 100755
index c106186..3a7e382
--- a/Scripts/SoftMask.cs
+++ b/Scripts/SoftMask.cs
@@ -98,7 +98,7 @@ public float softness
}
}
}
-
+
///
/// The transparency of the whole masked graphic.
///
@@ -296,6 +296,11 @@ protected override void OnEnable()
s_MainTexId = Shader.PropertyToID("_MainTex");
s_SoftnessId = Shader.PropertyToID("_Softness");
s_Alpha = Shader.PropertyToID("_Alpha");
+#if UNITY_EDITOR
+ UnityEditor.EditorApplication.update += UpdateGameViewMatrixForShader;
+ s_GameVPId = Shader.PropertyToID("_GameVP");
+ s_GameTVPId = Shader.PropertyToID("_GameTVP");
+#endif
}
}
s_ActiveSoftMasks.Add(this);
@@ -379,7 +384,33 @@ protected override void OnRectTransformDimensionsChange()
hasChanged = true;
}
- #if UNITY_EDITOR
+// #if UNITY_EDITOR
+ ///
+ /// Update the scene view matrix for shader.
+ ///
+ static void UpdateGameViewMatrixForShader()
+ {
+ foreach (var sm in s_ActiveSoftMasks)
+ {
+ var c = sm.graphic.canvas.rootCanvas;
+ var wcam = c.worldCamera ?? Camera.main;
+ if (c.renderMode != RenderMode.ScreenSpaceOverlay && wcam)
+ {
+ var pv = GL.GetGPUProjectionMatrix (wcam.projectionMatrix, false) * wcam.worldToCameraMatrix;
+ Shader.SetGlobalMatrix(s_GameVPId, pv);
+ Shader.SetGlobalMatrix(s_GameTVPId, pv);
+ }
+ else
+ {
+ var scale = c.transform.localScale.x;
+ var size = (c.transform as RectTransform).sizeDelta;
+ var pos = c.transform.position;
+ Shader.SetGlobalMatrix(s_GameVPId, Matrix4x4.TRS(new Vector3(0, 0, 0.5f), Quaternion.identity, new Vector3(2 / size.x, 2 / size.y, 0.0005f * scale)));
+ Shader.SetGlobalMatrix(s_GameTVPId, Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2/2000f)) * Matrix4x4.Translate(-pos));
+ }
+ }
+ }
+
///
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
///
@@ -390,7 +421,7 @@ protected override void OnValidate()
base.OnValidate();
_hasStencilStateChanged = false;
}
- #endif
+// #endif
//################################
// Private Members.
@@ -403,6 +434,8 @@ protected override void OnValidate()
static int s_ColorMaskId;
static int s_MainTexId;
static int s_SoftnessId;
+ static int s_GameVPId;
+ static int s_GameTVPId;
static int s_Alpha;
MaterialPropertyBlock _mpb;
CommandBuffer _cb;
@@ -491,6 +524,10 @@ static void UpdateMaskTextures()
s_previousViewProjectionMatrices [id] = s_nowViewProjectionMatrices [id];
}
s_nowViewProjectionMatrices.Clear ();
+
+#if UNITY_EDITOR
+ UpdateGameViewMatrixForShader();
+#endif
}
///
@@ -695,4 +732,4 @@ float GetPixelValue(int x, int y, int[] interactions)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Scripts/SoftMaskable.cs b/Scripts/SoftMaskable.cs
old mode 100644
new mode 100755
index 80c6c2b..b391c8c
--- a/Scripts/SoftMaskable.cs
+++ b/Scripts/SoftMaskable.cs
@@ -91,7 +91,6 @@ public Material GetModifiedMaterial(Material baseMaterial)
#if UNITY_EDITOR
result.EnableKeyword("SOFTMASK_EDITOR");
- UpdateSceneViewMatrixForShader();
#endif
}
else
@@ -112,7 +111,7 @@ public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
if (!isActiveAndEnabled || !_softMask)
return true;
-
+
if (!RectTransformUtility.RectangleContainsScreenPoint(transform as RectTransform, sp, eventCamera))
{
return false;
@@ -193,47 +192,11 @@ public void SetMaskInteraction(SpriteMaskInteraction layer0, SpriteMaskInteracti
static int s_SoftMaskTexId;
static int s_StencilCompId;
static int s_MaskInteractionId;
- static int s_GameVPId;
- static int s_GameTVPId;
static List s_ActiveSoftMaskables;
static int[] s_Interactions = new int[4];
static Material s_DefaultMaterial;
- #if UNITY_EDITOR
- ///
- /// Update the scene view matrix for shader.
- ///
- static void UpdateSceneViewMatrixForShader()
- {
-
- s_ActiveSoftMaskables.RemoveAll(x=>!x);
- foreach (var sm in s_ActiveSoftMaskables)
- {
- if (!sm || !sm._maskMaterial || !sm.graphic || !sm.graphic.canvas)
- {
- continue;
- }
-
- Material mat = sm._maskMaterial;
- var c = sm.graphic.canvas.rootCanvas;
- var wcam = c.worldCamera ?? Camera.main;
- if (c.renderMode != RenderMode.ScreenSpaceOverlay && wcam)
- {
- var pv = GL.GetGPUProjectionMatrix (wcam.projectionMatrix, false) * wcam.worldToCameraMatrix;
- mat.SetMatrix(s_GameVPId, pv);
- mat.SetMatrix(s_GameTVPId, pv);
- }
- else
- {
- var scale = c.transform.localScale.x;
- var size = (c.transform as RectTransform).sizeDelta;
- 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));
- }
- }
- }
-
+#if UNITY_EDITOR
///
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
///
@@ -244,7 +207,7 @@ void OnValidate()
graphic.SetMaterialDirty();
}
}
- #endif
+#endif
///
/// This function is called when the object becomes enabled and active.
@@ -256,12 +219,6 @@ void OnEnable()
{
s_ActiveSoftMaskables = new List();
- #if UNITY_EDITOR
- UnityEditor.EditorApplication.update += UpdateSceneViewMatrixForShader;
- s_GameVPId = Shader.PropertyToID("_GameVP");
- s_GameTVPId = Shader.PropertyToID("_GameTVP");
- #endif
-
s_SoftMaskTexId = Shader.PropertyToID("_SoftMaskTex");
s_StencilCompId = Shader.PropertyToID("_StencilComp");
s_MaskInteractionId = Shader.PropertyToID("_MaskInteraction");
@@ -341,4 +298,4 @@ void ISerializationCallbackReceiver.OnAfterDeserialize()
#pragma warning restore 0612
}
}
-}
\ No newline at end of file
+}
diff --git a/Shaders/SoftMask.cginc b/Shaders/SoftMask.cginc
index b8bb840..3f781f3 100644
--- a/Shaders/SoftMask.cginc
+++ b/Shaders/SoftMask.cginc
@@ -13,9 +13,9 @@ 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)))))))))))))),
- 0.01);
+ max(d._m20,max(d._m21,max(d._m22,max(d._m23,
+ max(d._m30,max(d._m31,max(d._m32,d._m33))))))))))))))),
+ 0.0000001);
}
float GetMaskAlpha(float alpha, int stencilId, float interaction)
@@ -60,8 +60,8 @@ float SoftMaskInternal(float4 clipPos)
#define SOFTMASK_EDITOR_ONLY(x) x
#define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos, worldPosition)
#else
- #define SOFTMASK_EDITOR_ONLY(x)
+ #define SOFTMASK_EDITOR_ONLY(x)
#define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos)
#endif
-#endif // UI_SOFTMASK_INCLUDED
\ No newline at end of file
+#endif // UI_SOFTMASK_INCLUDED
diff --git a/package.json b/package.json
index 035798d..7fa49d9 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "com.coffee.softmask-for-ugui",
"displayName": "UI Soft Mask",
"description": "UI Soft Mask is a smooth masking component for Unity UI (uGUI) elements.\nBy using SoftMask instead of the default Mask component, you can beautifully represent the rounded edges of UI elements.",
- "version": "0.10.0-preview.1",
+ "version": "0.10.0-preview.2",
"unity": "2017.1",
"license": "MIT",
"repository": {