Skip to content

Commit

Permalink
fix #33; Shaders for TMPro have compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Feb 5, 2019
1 parent 1d03cab commit 599f59b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ SubShader {
fixed4 underlayColor : COLOR1;
#endif
float4 textures : TEXCOORD5;
SOFTMASK_EDITOR_ONLY(float4 worldPosition : TEXCOORD6;)
};

// Used by Unity internally to handle Texture Tiling and Offset.
Expand Down Expand Up @@ -220,6 +221,7 @@ SubShader {
underlayColor,
#endif
float4(faceUV, outlineUV),
SOFTMASK_EDITOR_ONLY(input.position)
};

return output;
Expand Down Expand Up @@ -292,7 +294,7 @@ SubShader {
faceColor *= m.x * m.y;
#endif

faceColor *= SoftMask(input.position);
faceColor *= SoftMask(input.position, input.worldPosition);

#if UNITY_UI_ALPHACLIP
clip(faceColor.a - 0.001);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ SubShader {
float4 texcoord1 : TEXCOORD3; // Texture UV, alpha, reserved
half2 underlayParam : TEXCOORD4; // Scale(x), Bias(y)
#endif
SOFTMASK_EDITOR_ONLY(float4 worldPosition : TEXCOORD5;)
};


Expand Down Expand Up @@ -180,6 +181,7 @@ SubShader {
float4(input.texcoord0 + layerOffset, input.color.a, 0),
half2(layerScale, layerBias),
#endif
SOFTMASK_EDITOR_ONLY(input.vertex)
};

return output;
Expand Down Expand Up @@ -218,7 +220,7 @@ SubShader {
c *= input.texcoord1.z;
#endif

c *= SoftMask(input.vertex);
c *= SoftMask(input.vertex, input.worldPosition);

#if UNITY_UI_ALPHACLIP
clip(c.a - 0.001);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Shader "TextMeshPro/Sprite (SoftMaskable)"
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#endif

color.a *= SoftMask(IN.vertex);
color.a *= SoftMask(IN.vertex, IN.worldPosition);

#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
Expand Down
19 changes: 16 additions & 3 deletions Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ fixed Approximately(float4x4 a, float4x4 b)
1);
}

fixed GetMaskAlpha(fixed alpha, fixed stencilId, fixed interaction)
float GetMaskAlpha(float alpha, int stencilId, float interaction)
{
fixed onStencil = step(stencilId, _Stencil);
alpha = lerp(1, alpha, onStencil * step(1, interaction));
return lerp(alpha, 1 - alpha, onStencil * step(2, interaction));
}

half SoftMask(float4 clipPos, float4 wpos)
#if SOFTMASK_EDITOR
float SoftMaskInternal(float4 clipPos, float4 wpos)
#else
float SoftMaskInternal(float4 clipPos)
#endif
{
half2 view = clipPos.xy/_ScreenParams.xy;
#if SOFTMASK_EDITOR
Expand All @@ -43,9 +47,18 @@ half SoftMask(float4 clipPos, float4 wpos)
half alpha = GetMaskAlpha(mask.x, 1, _MaskInteraction.x)
* GetMaskAlpha(mask.y, 3, _MaskInteraction.y)
* GetMaskAlpha(mask.z, 7, _MaskInteraction.z)
* GetMaskAlpha(mask.w, 15, _MaskInteraction.w);
* GetMaskAlpha(mask.w, 15, _MaskInteraction.w)
;

return alpha;
}

#if SOFTMASK_EDITOR
#define SOFTMASK_EDITOR_ONLY(x) x
#define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos, worldPosition)
#else
#define SOFTMASK_EDITOR_ONLY(x)
#define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos)
#endif

#endif // UI_SOFTMASK_INCLUDED

0 comments on commit 599f59b

Please sign in to comment.