2018-11-20 07:49:14 +08:00
|
|
|
#ifndef UI_SOFTMASK_INCLUDED
|
|
|
|
#define UI_SOFTMASK_INCLUDED
|
|
|
|
|
|
|
|
sampler2D _SoftMaskTex;
|
|
|
|
float _Stencil;
|
2019-02-01 15:27:56 +08:00
|
|
|
float4x4 _GameVP;
|
2019-03-11 03:37:42 +08:00
|
|
|
float4x4 _GameTVP;
|
2019-01-26 20:30:41 +08:00
|
|
|
half4 _MaskInteraction;
|
2018-11-20 07:49:14 +08:00
|
|
|
|
2019-02-05 08:21:37 +08:00
|
|
|
#if SOFTMASK_EDITOR
|
|
|
|
float SoftMaskInternal(float4 clipPos, float4 wpos)
|
|
|
|
#else
|
|
|
|
float SoftMaskInternal(float4 clipPos)
|
|
|
|
#endif
|
2018-11-20 07:49:14 +08:00
|
|
|
{
|
|
|
|
half2 view = clipPos.xy/_ScreenParams.xy;
|
2019-02-01 15:27:56 +08:00
|
|
|
#if SOFTMASK_EDITOR
|
2020-06-07 12:19:49 +08:00
|
|
|
fixed isSceneView = any(UNITY_MATRIX_VP - _GameVP);
|
2019-03-11 03:37:42 +08:00
|
|
|
float4 cpos = mul(_GameTVP, mul(UNITY_MATRIX_M, wpos));
|
2019-02-01 15:27:56 +08:00
|
|
|
view = lerp(view, cpos.xy / cpos.w * 0.5 + 0.5, isSceneView);
|
2019-03-15 01:17:38 +08:00
|
|
|
#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
|
2019-03-15 22:40:05 +08:00
|
|
|
view.y = lerp(view.y, 1 - view.y, step(0, _ProjectionParams.x));
|
2019-01-11 20:36:28 +08:00
|
|
|
#endif
|
2018-11-20 07:49:14 +08:00
|
|
|
|
2019-01-26 20:30:41 +08:00
|
|
|
fixed4 mask = tex2D(_SoftMaskTex, view);
|
2020-06-07 12:19:49 +08:00
|
|
|
half4 alpha = saturate(lerp(fixed4(1, 1, 1, 1), lerp(mask, 1 - mask, _MaskInteraction - 1), _MaskInteraction))
|
2019-02-05 08:27:25 +08:00
|
|
|
#if SOFTMASK_EDITOR
|
|
|
|
* step(0, view.x) * step(view.x, 1) * step(0, view.y) * step(view.y, 1)
|
|
|
|
#endif
|
2019-02-05 08:21:37 +08:00
|
|
|
;
|
2018-11-20 07:49:14 +08:00
|
|
|
|
2020-06-07 12:19:49 +08:00
|
|
|
return alpha.x * alpha.y * alpha.z * alpha.w;
|
2018-11-20 07:49:14 +08:00
|
|
|
}
|
|
|
|
|
2019-02-05 08:21:37 +08:00
|
|
|
#if SOFTMASK_EDITOR
|
|
|
|
#define SOFTMASK_EDITOR_ONLY(x) x
|
|
|
|
#define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos, worldPosition)
|
|
|
|
#else
|
2020-05-03 19:38:06 +08:00
|
|
|
#define SOFTMASK_EDITOR_ONLY(x)
|
2019-02-05 08:21:37 +08:00
|
|
|
#define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos)
|
|
|
|
#endif
|
|
|
|
|
2020-05-03 19:38:06 +08:00
|
|
|
#endif // UI_SOFTMASK_INCLUDED
|