Skip to content

Commit

Permalink
fix #41; Doesn't work with Screen-Space Overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Mar 14, 2019
1 parent c81114c commit 15c67ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 15c67ad

Please sign in to comment.