Skip to content

Commit

Permalink
fix: applied a workaround to fix a Microsoft HLSL compiler issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ManeFunction authored and mob-sakai committed May 15, 2022
1 parent f59d147 commit 50c41f2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Shaders/SoftMask.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ float4x4 _GameVP;
float4x4 _GameTVP;
half4 _MaskInteraction;

float CustomStep(float a, float x)
{
return x >= a;
}

fixed Approximately(float4x4 a, float4x4 b)
{
float4x4 d = abs(a - b);
Expand All @@ -30,16 +35,16 @@ float SoftMaskInternal(float4 clipPos)
float4 cpos = mul(_GameTVP, mul(UNITY_MATRIX_M, wpos));
view = lerp(view, cpos.xy / cpos.w * 0.5 + 0.5, isSceneView);
#if UNITY_UV_STARTS_AT_TOP
view.y = lerp(view.y, 1 - view.y, step(0, _ProjectionParams.x));
view.y = lerp(view.y, 1 - view.y, CustomStep(0, _ProjectionParams.x));
#endif
#elif UNITY_UV_STARTS_AT_TOP
view.y = lerp(view.y, 1 - view.y, step(0, _ProjectionParams.x));
view.y = lerp(view.y, 1 - view.y, CustomStep(0, _ProjectionParams.x));
#endif

fixed4 mask = tex2D(_SoftMaskTex, view);
half4 alpha = saturate(lerp(fixed4(1, 1, 1, 1), lerp(mask, 1 - mask, _MaskInteraction - 1), _MaskInteraction));
#if SOFTMASK_EDITOR
alpha *= step(0, view.x) * step(view.x, 1) * step(0, view.y) * step(view.y, 1);
alpha *= CustomStep(0, view.x) * CustomStep(view.x, 1) * CustomStep(0, view.y) * CustomStep(view.y, 1);
#endif

return alpha.x * alpha.y * alpha.z * alpha.w;
Expand All @@ -53,4 +58,4 @@ float SoftMaskInternal(float4 clipPos)
#define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos)
#endif

#endif // UI_SOFTMASK_INCLUDED
#endif // UI_SOFTMASK_INCLUDED

0 comments on commit 50c41f2

Please sign in to comment.