You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.4 KiB

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