Skip to content

Commit

Permalink
fix: screen space overlay bug with game window resize
Browse files Browse the repository at this point in the history
close #93
  • Loading branch information
mob-sakai committed Jun 9, 2020
1 parent b0edc97 commit 91b7788
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Packages/SoftMaskForUGUI/Scripts/SoftMask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public enum DesamplingRate
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;
Expand Down Expand Up @@ -544,6 +546,16 @@ static void UpdateMaskTextures()
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>
Expand Down
13 changes: 12 additions & 1 deletion Packages/SoftMaskForUGUI/Shaders/SoftMask.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 91b7788

Please sign in to comment.