close #38; Improve for scene view
parent
8894eb3539
commit
c414a6271f
|
@ -175,9 +175,8 @@ namespace Coffee.UIExtensions
|
|||
static int s_SoftMaskTexId;
|
||||
static int s_StencilCompId;
|
||||
static int s_MaskInteractionId;
|
||||
static int s_SceneVId;
|
||||
static int s_ScenePId;
|
||||
static int s_GameVPId;
|
||||
static int s_GameTVPId;
|
||||
static List<SoftMaskable> s_ActiveSoftMaskables;
|
||||
static int[] s_Interactions = new int[4];
|
||||
static Material s_DefaultMaterial;
|
||||
|
@ -207,21 +206,20 @@ namespace Coffee.UIExtensions
|
|||
}
|
||||
|
||||
Material mat = sm._maskMaterial;
|
||||
mat.SetMatrix(s_SceneVId, w2c);
|
||||
mat.SetMatrix(s_ScenePId, prj);
|
||||
|
||||
var c = sm.graphic.canvas.rootCanvas;
|
||||
if (c.renderMode != RenderMode.ScreenSpaceOverlay && c.worldCamera)
|
||||
{
|
||||
var wcam = c.worldCamera;
|
||||
var pv = wcam.projectionMatrix * wcam.worldToCameraMatrix;
|
||||
var pv = GL.GetGPUProjectionMatrix (wcam.projectionMatrix, false) * wcam.worldToCameraMatrix;
|
||||
mat.SetMatrix(s_GameVPId, pv);
|
||||
mat.SetMatrix(s_GameTVPId, pv);
|
||||
}
|
||||
else
|
||||
{
|
||||
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 / 1000f)) * Matrix4x4.Translate(-pos);
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -250,9 +248,8 @@ namespace Coffee.UIExtensions
|
|||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.update += UpdateSceneViewMatrixForShader;
|
||||
s_SceneVId = Shader.PropertyToID("_SceneV");
|
||||
s_ScenePId = Shader.PropertyToID("_SceneP");
|
||||
s_GameVPId = Shader.PropertyToID("_GameVP");
|
||||
s_GameTVPId = Shader.PropertyToID("_GameTVP");
|
||||
#endif
|
||||
|
||||
s_SoftMaskTexId = Shader.PropertyToID("_SoftMaskTex");
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
|
||||
sampler2D _SoftMaskTex;
|
||||
float _Stencil;
|
||||
float4x4 _SceneV;
|
||||
float4x4 _SceneP;
|
||||
float4x4 _GameVP;
|
||||
float4x4 _GameTVP;
|
||||
half4 _MaskInteraction;
|
||||
|
||||
fixed Approximately(float4x4 a, float4x4 b)
|
||||
|
@ -16,7 +15,7 @@ fixed Approximately(float4x4 a, float4x4 b)
|
|||
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))))))))))))))),
|
||||
1);
|
||||
0.01);
|
||||
}
|
||||
|
||||
float GetMaskAlpha(float alpha, int stencilId, float interaction)
|
||||
|
@ -34,8 +33,8 @@ float SoftMaskInternal(float4 clipPos)
|
|||
{
|
||||
half2 view = clipPos.xy/_ScreenParams.xy;
|
||||
#if SOFTMASK_EDITOR
|
||||
fixed isSceneView = max(Approximately(UNITY_MATRIX_V, _SceneV), Approximately(UNITY_MATRIX_P, _SceneP));
|
||||
float4 cpos = mul(_GameVP, mul(UNITY_MATRIX_M, wpos));
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue