1.0.0-preview.5
# [1.0.0-preview.5](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.4...v1.0.0-preview.5) (2020-06-09) ### Bug Fixes * screen space overlay bug with game window resize ([pull/122/head91b7788
](91b77885bc
)), closes [#93](https://github.com/mob-sakai/SoftMaskForUGUI/issues/93)
parent
9aa9f568b8
commit
03a7b84fa2
|
@ -1,3 +1,10 @@
|
|||
# [1.0.0-preview.5](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.4...v1.0.0-preview.5) (2020-06-09)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* screen space overlay bug with game window resize ([91b7788](https://github.com/mob-sakai/SoftMaskForUGUI/commit/91b77885bc5f60cb59e8081009982a4635f9245c)), closes [#93](https://github.com/mob-sakai/SoftMaskForUGUI/issues/93)
|
||||
|
||||
# [1.0.0-preview.4](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.3...v1.0.0-preview.4) (2020-06-07)
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Coffee.UISoftMask
|
|||
[CanEditMultipleObjects]
|
||||
public class SoftMaskEditor : Editor
|
||||
{
|
||||
private const int k_PreviewSize = 128;
|
||||
private const string k_PrefsPreview = "SoftMaskEditor_Preview";
|
||||
private static readonly List<Graphic> s_Graphics = new List<Graphic>();
|
||||
private static bool s_Preview;
|
||||
|
@ -29,9 +30,10 @@ namespace Coffee.UISoftMask
|
|||
|
||||
var current = target as SoftMask;
|
||||
current.GetComponentsInChildren<Graphic>(true, s_Graphics);
|
||||
var fixTargets = s_Graphics.Where(x =>
|
||||
x.gameObject != current.gameObject && !x.GetComponent<SoftMaskable>() &&
|
||||
(!x.GetComponent<Mask>() || x.GetComponent<Mask>().showMaskGraphic)).ToList();
|
||||
var fixTargets = s_Graphics
|
||||
.Where(x => x.gameObject != current.gameObject)
|
||||
.Where(x => !x.GetComponent<SoftMaskable>() && (!x.GetComponent<Mask>() || x.GetComponent<Mask>().showMaskGraphic))
|
||||
.ToList();
|
||||
if (0 < fixTargets.Count)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
@ -58,7 +60,7 @@ namespace Coffee.UISoftMask
|
|||
|
||||
// Preview buffer.
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
if (s_Preview != (s_Preview = EditorGUILayout.ToggleLeft("Preview Buffer", s_Preview)))
|
||||
if (s_Preview != (s_Preview = EditorGUILayout.ToggleLeft("Preview Soft Mask Buffer", s_Preview)))
|
||||
{
|
||||
EditorPrefs.SetBool(k_PrefsPreview, s_Preview);
|
||||
}
|
||||
|
@ -66,10 +68,11 @@ namespace Coffee.UISoftMask
|
|||
if (s_Preview)
|
||||
{
|
||||
var tex = current.softMaskBuffer;
|
||||
var width = tex.width * 128 / tex.height;
|
||||
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(width, 128), tex, null, ScaleMode.ScaleToFit);
|
||||
var width = tex.width * k_PreviewSize / tex.height;
|
||||
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(width, k_PreviewSize), tex, null, ScaleMode.ScaleToFit);
|
||||
Repaint();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,8 @@ namespace Coffee.UISoftMask
|
|||
private static int s_GameVPId;
|
||||
private static int s_GameTVPId;
|
||||
private static int s_Alpha;
|
||||
private static int s_PreviousWidth;
|
||||
private static int s_PreviousHeight;
|
||||
private MaterialPropertyBlock _mpb;
|
||||
private CommandBuffer _cb;
|
||||
private Material _material;
|
||||
|
@ -76,7 +78,7 @@ namespace Coffee.UISoftMask
|
|||
[SerializeField, Range(0f, 1f), Tooltip("The transparency of the whole masked graphic.")]
|
||||
private float m_Alpha = 1;
|
||||
|
||||
[SerializeField, Tooltip("Should the soft mask ignore parent soft masks?")]
|
||||
[Header("Advanced Options")] [SerializeField, Tooltip("Should the soft mask ignore parent soft masks?")]
|
||||
private bool m_IgnoreParent = false;
|
||||
|
||||
[SerializeField, Tooltip("Is the soft mask a part of parent soft mask?")]
|
||||
|
@ -187,8 +189,7 @@ namespace Coffee.UISoftMask
|
|||
|
||||
if (!_softMaskBuffer)
|
||||
{
|
||||
_softMaskBuffer = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.ARGB32,
|
||||
RenderTextureReadWrite.Default);
|
||||
_softMaskBuffer = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
|
||||
hasChanged = true;
|
||||
_hasStencilStateChanged = true;
|
||||
}
|
||||
|
@ -242,7 +243,6 @@ namespace Coffee.UISoftMask
|
|||
}
|
||||
|
||||
|
||||
|
||||
Material material
|
||||
{
|
||||
get
|
||||
|
@ -251,9 +251,8 @@ namespace Coffee.UISoftMask
|
|||
? _material
|
||||
: _material =
|
||||
new Material(s_SoftMaskShader
|
||||
? s_SoftMaskShader
|
||||
: s_SoftMaskShader = Resources.Load<Shader>("SoftMask"))
|
||||
{hideFlags = HideFlags.HideAndDontSave};
|
||||
? s_SoftMaskShader
|
||||
: s_SoftMaskShader = Resources.Load<Shader>("SoftMask")) {hideFlags = HideFlags.HideAndDontSave};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -547,6 +546,16 @@ namespace Coffee.UISoftMask
|
|||
Profiler.EndSample();
|
||||
|
||||
Profiler.EndSample();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
var w = s_PreviousWidth;
|
||||
var h = s_PreviousHeight;
|
||||
GetDesamplingSize(DesamplingRate.None, out s_PreviousWidth, out s_PreviousHeight);
|
||||
if (w != s_PreviousWidth || h != s_PreviousHeight)
|
||||
{
|
||||
Canvas.ForceUpdateCanvases();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -558,8 +567,7 @@ namespace Coffee.UISoftMask
|
|||
Profiler.BeginSample("UpdateMaskTexture");
|
||||
|
||||
|
||||
_stencilDepth =
|
||||
MaskUtilities.GetStencilDepth(transform, MaskUtilities.FindRootSortOverrideCanvas(transform));
|
||||
_stencilDepth = MaskUtilities.GetStencilDepth(transform, MaskUtilities.FindRootSortOverrideCanvas(transform));
|
||||
|
||||
// Collect children soft masks.
|
||||
Profiler.BeginSample("Collect children soft masks");
|
||||
|
@ -570,7 +578,7 @@ namespace Coffee.UISoftMask
|
|||
var count = s_TmpSoftMasks[depth].Count;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
List<SoftMask> children = s_TmpSoftMasks[depth][i]._children;
|
||||
var children = s_TmpSoftMasks[depth][i]._children;
|
||||
var childCount = children.Count;
|
||||
for (var j = 0; j < childCount; j++)
|
||||
{
|
||||
|
@ -598,11 +606,11 @@ namespace Coffee.UISoftMask
|
|||
var cam = c.worldCamera ?? Camera.main;
|
||||
if (c && c.renderMode != RenderMode.ScreenSpaceOverlay && cam)
|
||||
{
|
||||
_cb.SetViewProjectionMatrices(cam.worldToCameraMatrix,
|
||||
GL.GetGPUProjectionMatrix(cam.projectionMatrix, false));
|
||||
var p = GL.GetGPUProjectionMatrix(cam.projectionMatrix, false);
|
||||
_cb.SetViewProjectionMatrices(cam.worldToCameraMatrix, p);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
var pv = GL.GetGPUProjectionMatrix(cam.projectionMatrix, false) * cam.worldToCameraMatrix;
|
||||
var pv = p * cam.worldToCameraMatrix;
|
||||
_cb.SetGlobalMatrix(s_GameVPId, pv);
|
||||
_cb.SetGlobalMatrix(s_GameTVPId, pv);
|
||||
#endif
|
||||
|
@ -611,19 +619,16 @@ namespace Coffee.UISoftMask
|
|||
{
|
||||
var pos = c.transform.position;
|
||||
var vm = Matrix4x4.TRS(new Vector3(-pos.x, -pos.y, -1000), Quaternion.identity, new Vector3(1, 1, -1f));
|
||||
var pm = Matrix4x4.TRS(new Vector3(0, 0, -1), Quaternion.identity,
|
||||
new Vector3(1 / pos.x, 1 / pos.y, -2 / 10000f));
|
||||
var pm = Matrix4x4.TRS(new Vector3(0, 0, -1), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2 / 10000f));
|
||||
_cb.SetViewProjectionMatrices(vm, pm);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
var scale = c.transform.localScale.x;
|
||||
var size = (c.transform as RectTransform).sizeDelta;
|
||||
_cb.SetGlobalMatrix(s_GameVPId,
|
||||
Matrix4x4.TRS(new Vector3(0, 0, 0.5f), Quaternion.identity,
|
||||
new Vector3(2 / size.x, 2 / size.y, 0.0005f * scale)));
|
||||
_cb.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));
|
||||
var gameVp = Matrix4x4.TRS(new Vector3(0, 0, 0.5f), Quaternion.identity, new Vector3(2 / size.x, 2 / size.y, 0.0005f * scale));
|
||||
var gameTvp = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2 / 2000f)) * Matrix4x4.Translate(-pos);
|
||||
_cb.SetGlobalMatrix(s_GameVPId, gameVp);
|
||||
_cb.SetGlobalMatrix(s_GameTVPId, gameTvp);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -640,8 +645,7 @@ namespace Coffee.UISoftMask
|
|||
|
||||
if (i != 0)
|
||||
{
|
||||
sm._stencilDepth = MaskUtilities.GetStencilDepth(sm.transform,
|
||||
MaskUtilities.FindRootSortOverrideCanvas(sm.transform));
|
||||
sm._stencilDepth = MaskUtilities.GetStencilDepth(sm.transform, MaskUtilities.FindRootSortOverrideCanvas(sm.transform));
|
||||
}
|
||||
|
||||
// Set material property.
|
||||
|
@ -700,6 +704,7 @@ namespace Coffee.UISoftMask
|
|||
private static void ReleaseRt(ref RenderTexture tmpRT)
|
||||
{
|
||||
if (!tmpRT) return;
|
||||
|
||||
tmpRT.Release();
|
||||
RenderTexture.ReleaseTemporary(tmpRT);
|
||||
tmpRT = null;
|
||||
|
@ -712,13 +717,13 @@ namespace Coffee.UISoftMask
|
|||
private static void ReleaseObject(Object obj)
|
||||
{
|
||||
if (!obj) return;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
DestroyImmediate(obj);
|
||||
else
|
||||
#endif
|
||||
Destroy(obj);
|
||||
obj = null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -133,8 +133,7 @@ namespace Coffee.UISoftMask
|
|||
mat.EnableKeyword("SOFTMASK_EDITOR");
|
||||
#endif
|
||||
mat.SetTexture(s_SoftMaskTexId, softMask.softMaskBuffer);
|
||||
mat.SetInt(s_StencilCompId,
|
||||
m_UseStencil ? (int) CompareFunction.Equal : (int) CompareFunction.Always);
|
||||
mat.SetInt(s_StencilCompId, m_UseStencil ? (int) CompareFunction.Equal : (int) CompareFunction.Always);
|
||||
|
||||
var root = MaskUtilities.FindRootSortOverrideCanvas(transform);
|
||||
var stencil = MaskUtilities.GetStencilDepth(transform, root);
|
||||
|
@ -179,15 +178,19 @@ namespace Coffee.UISoftMask
|
|||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
if (!sm) break;
|
||||
|
||||
s_Interactions[i] = sm ? ((m_MaskInteraction >> i * 2) & 0x3) : 0;
|
||||
var interaction = s_Interactions[i] == 1;
|
||||
var inRect = RectTransformUtility.RectangleContainsScreenPoint(sm.transform as RectTransform, sp, eventCamera);
|
||||
var rt = sm.transform as RectTransform;
|
||||
var inRect = RectTransformUtility.RectangleContainsScreenPoint(rt, sp, eventCamera);
|
||||
if (!sm.ignoreSelfGraphic && interaction != inRect) return false;
|
||||
|
||||
foreach (var child in sm._children)
|
||||
{
|
||||
if (!child) break;
|
||||
var inRectChild = RectTransformUtility.RectangleContainsScreenPoint(child.transform as RectTransform, sp, eventCamera);
|
||||
if (!child) continue;
|
||||
|
||||
var childRt = child.transform as RectTransform;
|
||||
var inRectChild = RectTransformUtility.RectangleContainsScreenPoint(childRt, sp, eventCamera);
|
||||
if (!child.ignoreSelfGraphic && interaction != inRectChild) return false;
|
||||
}
|
||||
|
||||
|
@ -201,7 +204,7 @@ namespace Coffee.UISoftMask
|
|||
/// <summary>
|
||||
/// Set the interaction for each mask.
|
||||
/// </summary>
|
||||
public void SetMaskInteraction(SpriteMaskInteraction intr)
|
||||
public void SetMaskInteraction(MaskIntr intr)
|
||||
{
|
||||
SetMaskInteraction(intr, intr, intr, intr);
|
||||
}
|
||||
|
@ -209,8 +212,7 @@ namespace Coffee.UISoftMask
|
|||
/// <summary>
|
||||
/// Set the interaction for each mask.
|
||||
/// </summary>
|
||||
public void SetMaskInteraction(SpriteMaskInteraction layer0, SpriteMaskInteraction layer1,
|
||||
SpriteMaskInteraction layer2, SpriteMaskInteraction layer3)
|
||||
public void SetMaskInteraction(MaskIntr layer0, MaskIntr layer1, MaskIntr layer2, MaskIntr layer3)
|
||||
{
|
||||
m_MaskInteraction = (int) layer0 + ((int) layer1 << 2) + ((int) layer2 << 4) + ((int) layer3 << 6);
|
||||
graphic.SetMaterialDirtyEx();
|
||||
|
@ -278,12 +280,14 @@ namespace Coffee.UISoftMask
|
|||
var current = this;
|
||||
UnityEditor.EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (current && graphic && graphic.material && graphic.material.shader &&
|
||||
graphic.material.shader.name == "Hidden/UI/Default (SoftMaskable)")
|
||||
{
|
||||
graphic.material = null;
|
||||
graphic.SetMaterialDirtyEx();
|
||||
}
|
||||
if (!current) return;
|
||||
if (!graphic) return;
|
||||
if (!graphic.material) return;
|
||||
if (!graphic.material.shader) return;
|
||||
if (graphic.material.shader.name != "Hidden/UI/Default (SoftMaskable)") return;
|
||||
|
||||
graphic.material = null;
|
||||
graphic.SetMaterialDirtyEx();
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -7,6 +7,17 @@ float4x4 _GameVP;
|
|||
float4x4 _GameTVP;
|
||||
half4 _MaskInteraction;
|
||||
|
||||
fixed Approximately(float4x4 a, float4x4 b)
|
||||
{
|
||||
float4x4 d = abs(a - 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.5);
|
||||
}
|
||||
|
||||
#if SOFTMASK_EDITOR
|
||||
float SoftMaskInternal(float4 clipPos, float4 wpos)
|
||||
#else
|
||||
|
@ -15,7 +26,7 @@ float SoftMaskInternal(float4 clipPos)
|
|||
{
|
||||
half2 view = clipPos.xy/_ScreenParams.xy;
|
||||
#if SOFTMASK_EDITOR
|
||||
fixed isSceneView = any(UNITY_MATRIX_VP - _GameVP);
|
||||
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);
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
|
|
|
@ -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": "1.0.0-preview.4",
|
||||
"version": "1.0.0-preview.5",
|
||||
"unity": "2017.1",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
|
Loading…
Reference in New Issue