Skip to content

Commit

Permalink
fix: clickable area inverted on Metal
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Sep 28, 2020
1 parent 207ea9c commit 3c189ff
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Packages/SoftMaskForUGUI/Scripts/SoftMask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public enum DesamplingRate
};

private static bool s_UVStartsAtTop;
private static bool s_IsMetal;
private static Shader s_SoftMaskShader;
private static Texture2D s_ReadTexture;
private static readonly List<SoftMask> s_ActiveSoftMasks = new List<SoftMask>();
Expand Down Expand Up @@ -329,7 +330,7 @@ public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera, Graphic g, in
if (!isActiveAndEnabled || (g == graphic && !g.raycastTarget)) return true;

int x = (int) ((softMaskBuffer.width - 1) * Mathf.Clamp01(sp.x / Screen.width));
int y = s_UVStartsAtTop
int y = s_UVStartsAtTop && !s_IsMetal
? (int) ((softMaskBuffer.height - 1) * (1 - Mathf.Clamp01(sp.y / Screen.height)))
: (int) ((softMaskBuffer.height - 1) * Mathf.Clamp01(sp.y / Screen.height));
return 0.5f < GetPixelValue(x, y, interactions);
Expand All @@ -355,6 +356,7 @@ protected override void OnEnable()
if (s_StencilCompId == 0)
{
s_UVStartsAtTop = SystemInfo.graphicsUVStartsAtTop;
s_IsMetal = SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal;
s_StencilCompId = Shader.PropertyToID("_StencilComp");
s_ColorMaskId = Shader.PropertyToID("_ColorMask");
s_MainTexId = Shader.PropertyToID("_MainTex");
Expand Down

0 comments on commit 3c189ff

Please sign in to comment.