0.10.0-preview.2
# [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 ([pull/87/head482b967
](482b96709b
)), closes [#78](https://github.com/mob-sakai/SoftMaskForUGUI/issues/78)
parent
a9c6dadfa1
commit
f5f5b7e341
|
@ -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)
|
||||
|
||||
|
||||
|
|
13
README.md
13
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://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
|
|||
<br><br><br><br>
|
||||
## 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.
|
||||
|
||||

|
||||
|
||||
|
@ -77,7 +74,7 @@ By using SoftMask instead of default Mask, rounded edges of UI elements can be e
|
|||
|
||||
|
||||
<br><br><br><br>
|
||||
## 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
|
||||

|
||||
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
|
||||

|
||||
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
|
||||
|
||||
|
||||
<br><br><br><br>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -98,7 +98,7 @@ namespace Coffee.UIExtensions
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The transparency of the whole masked graphic.
|
||||
/// </summary>
|
||||
|
@ -296,6 +296,11 @@ namespace Coffee.UIExtensions
|
|||
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 @@ namespace Coffee.UIExtensions
|
|||
hasChanged = true;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// #if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Update the scene view matrix for shader.
|
||||
/// </summary>
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
|
||||
/// </summary>
|
||||
|
@ -390,7 +421,7 @@ namespace Coffee.UIExtensions
|
|||
base.OnValidate();
|
||||
_hasStencilStateChanged = false;
|
||||
}
|
||||
#endif
|
||||
// #endif
|
||||
|
||||
//################################
|
||||
// Private Members.
|
||||
|
@ -403,6 +434,8 @@ namespace Coffee.UIExtensions
|
|||
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 @@ namespace Coffee.UIExtensions
|
|||
s_previousViewProjectionMatrices [id] = s_nowViewProjectionMatrices [id];
|
||||
}
|
||||
s_nowViewProjectionMatrices.Clear ();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UpdateGameViewMatrixForShader();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -695,4 +732,4 @@ namespace Coffee.UIExtensions
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,6 @@ namespace Coffee.UIExtensions
|
|||
|
||||
#if UNITY_EDITOR
|
||||
result.EnableKeyword("SOFTMASK_EDITOR");
|
||||
UpdateSceneViewMatrixForShader();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
|
@ -112,7 +111,7 @@ namespace Coffee.UIExtensions
|
|||
{
|
||||
if (!isActiveAndEnabled || !_softMask)
|
||||
return true;
|
||||
|
||||
|
||||
if (!RectTransformUtility.RectangleContainsScreenPoint(transform as RectTransform, sp, eventCamera))
|
||||
{
|
||||
return false;
|
||||
|
@ -193,47 +192,11 @@ namespace Coffee.UIExtensions
|
|||
static int s_SoftMaskTexId;
|
||||
static int s_StencilCompId;
|
||||
static int s_MaskInteractionId;
|
||||
static int s_GameVPId;
|
||||
static int s_GameTVPId;
|
||||
static List<SoftMaskable> s_ActiveSoftMaskables;
|
||||
static int[] s_Interactions = new int[4];
|
||||
static Material s_DefaultMaterial;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Update the scene view matrix for shader.
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
|
||||
/// </summary>
|
||||
|
@ -244,7 +207,7 @@ namespace Coffee.UIExtensions
|
|||
graphic.SetMaterialDirty();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// This function is called when the object becomes enabled and active.
|
||||
|
@ -256,12 +219,6 @@ namespace Coffee.UIExtensions
|
|||
{
|
||||
s_ActiveSoftMaskables = new List<SoftMaskable>();
|
||||
|
||||
#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 @@ namespace Coffee.UIExtensions
|
|||
#pragma warning restore 0612
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
#endif // UI_SOFTMASK_INCLUDED
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue