From bd6f85965e8c4263fe4fa2a242737c49d73afe0a Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 15 Mar 2019 02:17:38 +0900 Subject: [PATCH] fix #41; Doesn't work with Screen-Space Overlay --- Scripts/SoftMask.cs | 2 +- Scripts/SoftMaskable.cs | 7 ++++--- SoftMask.cginc | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Scripts/SoftMask.cs b/Scripts/SoftMask.cs index f67c37c..4e79616 100644 --- a/Scripts/SoftMask.cs +++ b/Scripts/SoftMask.cs @@ -467,7 +467,7 @@ void UpdateMaskTexture() var cam = c.worldCamera ?? Camera.main; if (c && c.renderMode != RenderMode.ScreenSpaceOverlay && cam) { - _cb.SetViewProjectionMatrices(cam.worldToCameraMatrix, cam.projectionMatrix); + _cb.SetViewProjectionMatrices(cam.worldToCameraMatrix, GL.GetGPUProjectionMatrix(cam.projectionMatrix, true)); } else { diff --git a/Scripts/SoftMaskable.cs b/Scripts/SoftMaskable.cs index d709b1e..05bfc8a 100644 --- a/Scripts/SoftMaskable.cs +++ b/Scripts/SoftMaskable.cs @@ -215,10 +215,11 @@ static void UpdateSceneViewMatrixForShader() } else { + var scale = c.transform.localScale.x; + var size = (c.transform as RectTransform).sizeDelta; var pos = c.transform.localPosition; - var pv = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2 / 2000f)); - mat.SetMatrix(s_GameVPId, pv); - mat.SetMatrix(s_GameTVPId, pv * Matrix4x4.Translate(-pos)); + 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)); } } } diff --git a/SoftMask.cginc b/SoftMask.cginc index 5e98c61..0928e15 100644 --- a/SoftMask.cginc +++ b/SoftMask.cginc @@ -36,9 +36,10 @@ float SoftMaskInternal(float4 clipPos) 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); - #endif - - #if UNITY_UV_STARTS_AT_TOP && !defined(SHADER_API_D3D11) && !defined(SHADER_API_D3D11_9X) && !defined(SHADER_API_D3D9) + #if UNITY_UV_STARTS_AT_TOP + view.y = lerp(view.y, 1 - view.y, step(0, _ProjectionParams.x)); + #endif + #elif UNITY_UV_STARTS_AT_TOP view.y = 1.0 - view.y; #endif