Skip to content

Commit

Permalink
0.10.0-preview.2
Browse files Browse the repository at this point in the history
# [0.10.0-preview.2](v0.10.0-preview.1...v0.10.0-preview.2) (2020-05-03)

### Bug Fixes

* visual bug with ScreenSpaceCamera canvas on editor ([482b967](482b967)), closes [#78](#78)
  • Loading branch information
semantic-release-bot committed May 3, 2020
1 parent a9c6dad commit f5f5b7e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 76 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.coffee.softmask-for-ugui/)
Expand All @@ -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.

![](https://user-images.githubusercontent.com/12690315/50282806-4b375100-0497-11e9-891c-35309d332c7b.png)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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


<br><br><br><br>
Expand Down
37 changes: 25 additions & 12 deletions Samples~/Demo/SoftMask_Demo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
45 changes: 41 additions & 4 deletions Scripts/SoftMask.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public float softness
}
}
}

/// <summary>
/// The transparency of the whole masked graphic.
/// </summary>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -379,7 +384,33 @@ protected override void OnRectTransformDimensionsChange()
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>
Expand All @@ -390,7 +421,7 @@ protected override void OnValidate()
base.OnValidate();
_hasStencilStateChanged = false;
}
#endif
// #endif

//################################
// Private Members.
Expand All @@ -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;
Expand Down Expand Up @@ -491,6 +524,10 @@ static void UpdateMaskTextures()
s_previousViewProjectionMatrices [id] = s_nowViewProjectionMatrices [id];
}
s_nowViewProjectionMatrices.Clear ();

#if UNITY_EDITOR
UpdateGameViewMatrixForShader();
#endif
}

/// <summary>
Expand Down Expand Up @@ -695,4 +732,4 @@ float GetPixelValue(int x, int y, int[] interactions)
}
}
}
}
}
51 changes: 4 additions & 47 deletions Scripts/SoftMaskable.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public Material GetModifiedMaterial(Material baseMaterial)

#if UNITY_EDITOR
result.EnableKeyword("SOFTMASK_EDITOR");
UpdateSceneViewMatrixForShader();
#endif
}
else
Expand All @@ -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;
Expand Down Expand Up @@ -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<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>
Expand All @@ -244,7 +207,7 @@ void OnValidate()
graphic.SetMaterialDirty();
}
}
#endif
#endif

/// <summary>
/// This function is called when the object becomes enabled and active.
Expand All @@ -256,12 +219,6 @@ void OnEnable()
{
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");
Expand Down Expand Up @@ -341,4 +298,4 @@ void ISerializationCallbackReceiver.OnAfterDeserialize()
#pragma warning restore 0612
}
}
}
}
10 changes: 5 additions & 5 deletions Shaders/SoftMask.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit f5f5b7e

Please sign in to comment.