TMP_SDF-Surface-Mobile.shader 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Simplified version of the SDF Surface shader :
  2. // - No support for Bevel, Bump or envmap
  3. // - Diffuse only lighting
  4. // - Fully supports only 1 directional light. Other lights can affect it, but it will be per-vertex/SH.
  5. Shader "TextMeshPro/Mobile/Distance Field (Surface)" {
  6. Properties {
  7. _FaceTex ("Fill Texture", 2D) = "white" {}
  8. _FaceColor ("Fill Color", Color) = (1,1,1,1)
  9. _FaceDilate ("Face Dilate", Range(-1,1)) = 0
  10. _OutlineColor ("Outline Color", Color) = (0,0,0,1)
  11. _OutlineTex ("Outline Texture", 2D) = "white" {}
  12. _OutlineWidth ("Outline Thickness", Range(0, 1)) = 0
  13. _OutlineSoftness ("Outline Softness", Range(0,1)) = 0
  14. _GlowColor ("Color", Color) = (0, 1, 0, 0.5)
  15. _GlowOffset ("Offset", Range(-1,1)) = 0
  16. _GlowInner ("Inner", Range(0,1)) = 0.05
  17. _GlowOuter ("Outer", Range(0,1)) = 0.05
  18. _GlowPower ("Falloff", Range(1, 0)) = 0.75
  19. _WeightNormal ("Weight Normal", float) = 0
  20. _WeightBold ("Weight Bold", float) = 0.5
  21. // Should not be directly exposed to the user
  22. _ShaderFlags ("Flags", float) = 0
  23. _ScaleRatioA ("Scale RatioA", float) = 1
  24. _ScaleRatioB ("Scale RatioB", float) = 1
  25. _ScaleRatioC ("Scale RatioC", float) = 1
  26. _MainTex ("Font Atlas", 2D) = "white" {}
  27. _TextureWidth ("Texture Width", float) = 512
  28. _TextureHeight ("Texture Height", float) = 512
  29. _GradientScale ("Gradient Scale", float) = 5.0
  30. _ScaleX ("Scale X", float) = 1.0
  31. _ScaleY ("Scale Y", float) = 1.0
  32. _PerspectiveFilter ("Perspective Correction", Range(0, 1)) = 0.875
  33. _Sharpness ("Sharpness", Range(-1,1)) = 0
  34. _VertexOffsetX ("Vertex OffsetX", float) = 0
  35. _VertexOffsetY ("Vertex OffsetY", float) = 0
  36. //_MaskCoord ("Mask Coords", vector) = (0,0,0,0)
  37. //_MaskSoftness ("Mask Softness", float) = 0
  38. }
  39. SubShader {
  40. Tags {
  41. "Queue"="Transparent"
  42. "IgnoreProjector"="True"
  43. "RenderType"="Transparent"
  44. }
  45. LOD 300
  46. Cull [_CullMode]
  47. CGPROGRAM
  48. #pragma surface PixShader Lambert alpha:blend vertex:VertShader noforwardadd nolightmap nodirlightmap
  49. #pragma target 3.0
  50. #pragma shader_feature __ GLOW_ON
  51. #include "TMPro_Properties.cginc"
  52. #include "TMPro.cginc"
  53. half _FaceShininess;
  54. half _OutlineShininess;
  55. struct Input
  56. {
  57. fixed4 color : COLOR;
  58. float2 uv_MainTex;
  59. float2 uv2_FaceTex;
  60. float2 uv2_OutlineTex;
  61. float2 param; // Weight, Scale
  62. float3 viewDirEnv;
  63. };
  64. #include "TMPro_Surface.cginc"
  65. ENDCG
  66. // Pass to render object as a shadow caster
  67. Pass
  68. {
  69. Name "Caster"
  70. Tags { "LightMode" = "ShadowCaster" }
  71. Offset 1, 1
  72. Fog {Mode Off}
  73. ZWrite On ZTest LEqual Cull Off
  74. CGPROGRAM
  75. #pragma vertex vert
  76. #pragma fragment frag
  77. #pragma multi_compile_shadowcaster
  78. #include "UnityCG.cginc"
  79. struct v2f {
  80. V2F_SHADOW_CASTER;
  81. float2 uv : TEXCOORD1;
  82. float2 uv2 : TEXCOORD3;
  83. float alphaClip : TEXCOORD2;
  84. };
  85. uniform float4 _MainTex_ST;
  86. uniform float4 _OutlineTex_ST;
  87. float _OutlineWidth;
  88. float _FaceDilate;
  89. float _ScaleRatioA;
  90. v2f vert( appdata_base v )
  91. {
  92. v2f o;
  93. TRANSFER_SHADOW_CASTER(o)
  94. o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  95. o.uv2 = TRANSFORM_TEX(v.texcoord, _OutlineTex);
  96. o.alphaClip = o.alphaClip = (1.0 - _OutlineWidth * _ScaleRatioA - _FaceDilate * _ScaleRatioA) / 2;
  97. return o;
  98. }
  99. uniform sampler2D _MainTex;
  100. float4 frag(v2f i) : COLOR
  101. {
  102. fixed4 texcol = tex2D(_MainTex, i.uv).a;
  103. clip(texcol.a - i.alphaClip);
  104. SHADOW_CASTER_FRAGMENT(i)
  105. }
  106. ENDCG
  107. }
  108. }
  109. CustomEditor "TMPro.EditorUtilities.TMP_SDFShaderGUI"
  110. }