2
0

TMP_SDF-Surface-Mobile.shader 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. [HDR]_FaceColor ("Fill Color", Color) = (1,1,1,1)
  9. _FaceDilate ("Face Dilate", Range(-1,1)) = 0
  10. [HDR]_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. [HDR]_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. _CullMode ("Cull Mode", Float) = 0
  37. //_MaskCoord ("Mask Coords", vector) = (0,0,0,0)
  38. //_MaskSoftness ("Mask Softness", float) = 0
  39. }
  40. SubShader {
  41. Tags {
  42. "Queue"="Transparent"
  43. "IgnoreProjector"="True"
  44. "RenderType"="Transparent"
  45. }
  46. LOD 300
  47. Cull [_CullMode]
  48. CGPROGRAM
  49. #pragma surface PixShader Lambert alpha:blend vertex:VertShader noforwardadd nolightmap nodirlightmap
  50. #pragma target 3.0
  51. #pragma shader_feature __ GLOW_ON
  52. #include "TMPro_Properties.cginc"
  53. #include "TMPro.cginc"
  54. half _FaceShininess;
  55. half _OutlineShininess;
  56. struct Input
  57. {
  58. fixed4 color : COLOR;
  59. float2 uv_MainTex;
  60. float2 uv2_FaceTex;
  61. float2 uv2_OutlineTex;
  62. float2 param; // Weight, Scale
  63. float3 viewDirEnv;
  64. };
  65. #include "TMPro_Surface.cginc"
  66. ENDCG
  67. // Pass to render object as a shadow caster
  68. Pass
  69. {
  70. Name "Caster"
  71. Tags { "LightMode" = "ShadowCaster" }
  72. Offset 1, 1
  73. Fog {Mode Off}
  74. ZWrite On ZTest LEqual Cull Off
  75. CGPROGRAM
  76. #pragma vertex vert
  77. #pragma fragment frag
  78. #pragma multi_compile_shadowcaster
  79. #include "UnityCG.cginc"
  80. struct v2f {
  81. V2F_SHADOW_CASTER;
  82. float2 uv : TEXCOORD1;
  83. float2 uv2 : TEXCOORD3;
  84. float alphaClip : TEXCOORD2;
  85. };
  86. uniform float4 _MainTex_ST;
  87. uniform float4 _OutlineTex_ST;
  88. float _OutlineWidth;
  89. float _FaceDilate;
  90. float _ScaleRatioA;
  91. v2f vert( appdata_base v )
  92. {
  93. v2f o;
  94. TRANSFER_SHADOW_CASTER(o)
  95. o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  96. o.uv2 = TRANSFORM_TEX(v.texcoord, _OutlineTex);
  97. o.alphaClip = o.alphaClip = (1.0 - _OutlineWidth * _ScaleRatioA - _FaceDilate * _ScaleRatioA) / 2;
  98. return o;
  99. }
  100. uniform sampler2D _MainTex;
  101. float4 frag(v2f i) : COLOR
  102. {
  103. fixed4 texcol = tex2D(_MainTex, i.uv).a;
  104. clip(texcol.a - i.alphaClip);
  105. SHADOW_CASTER_FRAGMENT(i)
  106. }
  107. ENDCG
  108. }
  109. }
  110. CustomEditor "TMPro.EditorUtilities.TMP_SDFShaderGUI"
  111. }