TMP_SDF-Surface.shader 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. Shader "TextMeshPro/Distance Field (Surface)" {
  2. Properties {
  3. _FaceTex ("Fill Texture", 2D) = "white" {}
  4. _FaceUVSpeedX ("Face UV Speed X", Range(-5, 5)) = 0.0
  5. _FaceUVSpeedY ("Face UV Speed Y", Range(-5, 5)) = 0.0
  6. [HDR]_FaceColor ("Fill Color", Color) = (1,1,1,1)
  7. _FaceDilate ("Face Dilate", Range(-1,1)) = 0
  8. [HDR]_OutlineColor ("Outline Color", Color) = (0,0,0,1)
  9. _OutlineTex ("Outline Texture", 2D) = "white" {}
  10. _OutlineUVSpeedX ("Outline UV Speed X", Range(-5, 5)) = 0.0
  11. _OutlineUVSpeedY ("Outline UV Speed Y", Range(-5, 5)) = 0.0
  12. _OutlineWidth ("Outline Thickness", Range(0, 1)) = 0
  13. _OutlineSoftness ("Outline Softness", Range(0,1)) = 0
  14. _Bevel ("Bevel", Range(0,1)) = 0.5
  15. _BevelOffset ("Bevel Offset", Range(-0.5,0.5)) = 0
  16. _BevelWidth ("Bevel Width", Range(-.5,0.5)) = 0
  17. _BevelClamp ("Bevel Clamp", Range(0,1)) = 0
  18. _BevelRoundness ("Bevel Roundness", Range(0,1)) = 0
  19. _BumpMap ("Normalmap", 2D) = "bump" {}
  20. _BumpOutline ("Bump Outline", Range(0,1)) = 0.5
  21. _BumpFace ("Bump Face", Range(0,1)) = 0.5
  22. _ReflectFaceColor ("Face Color", Color) = (0,0,0,1)
  23. _ReflectOutlineColor ("Outline Color", Color) = (0,0,0,1)
  24. _Cube ("Reflection Cubemap", Cube) = "black" { /* TexGen CubeReflect */ }
  25. _EnvMatrixRotation ("Texture Rotation", vector) = (0, 0, 0, 0)
  26. [HDR]_SpecColor ("Specular Color", Color) = (0,0,0,1)
  27. _FaceShininess ("Face Shininess", Range(0,1)) = 0
  28. _OutlineShininess ("Outline Shininess", Range(0,1)) = 0
  29. [HDR]_GlowColor ("Color", Color) = (0, 1, 0, 0.5)
  30. _GlowOffset ("Offset", Range(-1,1)) = 0
  31. _GlowInner ("Inner", Range(0,1)) = 0.05
  32. _GlowOuter ("Outer", Range(0,1)) = 0.05
  33. _GlowPower ("Falloff", Range(1, 0)) = 0.75
  34. _WeightNormal ("Weight Normal", float) = 0
  35. _WeightBold ("Weight Bold", float) = 0.5
  36. // Should not be directly exposed to the user
  37. _ShaderFlags ("Flags", float) = 0
  38. _ScaleRatioA ("Scale RatioA", float) = 1
  39. _ScaleRatioB ("Scale RatioB", float) = 1
  40. _ScaleRatioC ("Scale RatioC", float) = 1
  41. _MainTex ("Font Atlas", 2D) = "white" {}
  42. _TextureWidth ("Texture Width", float) = 512
  43. _TextureHeight ("Texture Height", float) = 512
  44. _GradientScale ("Gradient Scale", float) = 5.0
  45. _ScaleX ("Scale X", float) = 1.0
  46. _ScaleY ("Scale Y", float) = 1.0
  47. _PerspectiveFilter ("Perspective Correction", Range(0, 1)) = 0.875
  48. _Sharpness ("Sharpness", Range(-1,1)) = 0
  49. _VertexOffsetX ("Vertex OffsetX", float) = 0
  50. _VertexOffsetY ("Vertex OffsetY", float) = 0
  51. _CullMode ("Cull Mode", Float) = 0
  52. //_MaskCoord ("Mask Coords", vector) = (0,0,0,0)
  53. //_MaskSoftness ("Mask Softness", float) = 0
  54. }
  55. SubShader {
  56. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  57. LOD 300
  58. Cull [_CullMode]
  59. CGPROGRAM
  60. #pragma surface PixShader BlinnPhong alpha:blend vertex:VertShader nolightmap nodirlightmap
  61. #pragma target 3.0
  62. #pragma shader_feature __ GLOW_ON
  63. #pragma glsl
  64. #include "TMPro_Properties.cginc"
  65. #include "TMPro.cginc"
  66. half _FaceShininess;
  67. half _OutlineShininess;
  68. struct Input
  69. {
  70. fixed4 color : COLOR;
  71. float2 uv_MainTex;
  72. float2 uv2_FaceTex;
  73. float2 uv2_OutlineTex;
  74. float2 param; // Weight, Scale
  75. float3 viewDirEnv;
  76. };
  77. #define BEVEL_ON 1
  78. #include "TMPro_Surface.cginc"
  79. ENDCG
  80. // Pass to render object as a shadow caster
  81. Pass
  82. {
  83. Name "Caster"
  84. Tags { "LightMode" = "ShadowCaster" }
  85. Offset 1, 1
  86. Fog {Mode Off}
  87. ZWrite On
  88. ZTest LEqual
  89. Cull Off
  90. CGPROGRAM
  91. #pragma vertex vert
  92. #pragma fragment frag
  93. #pragma multi_compile_shadowcaster
  94. #include "UnityCG.cginc"
  95. struct v2f {
  96. V2F_SHADOW_CASTER;
  97. float2 uv : TEXCOORD1;
  98. float2 uv2 : TEXCOORD3;
  99. float alphaClip : TEXCOORD2;
  100. };
  101. uniform float4 _MainTex_ST;
  102. uniform float4 _OutlineTex_ST;
  103. float _OutlineWidth;
  104. float _FaceDilate;
  105. float _ScaleRatioA;
  106. v2f vert( appdata_base v )
  107. {
  108. v2f o;
  109. TRANSFER_SHADOW_CASTER(o)
  110. o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  111. o.uv2 = TRANSFORM_TEX(v.texcoord, _OutlineTex);
  112. o.alphaClip = (1.0 - _OutlineWidth * _ScaleRatioA - _FaceDilate * _ScaleRatioA) / 2;
  113. return o;
  114. }
  115. uniform sampler2D _MainTex;
  116. float4 frag(v2f i) : COLOR
  117. {
  118. fixed4 texcol = tex2D(_MainTex, i.uv).a;
  119. clip(texcol.a - i.alphaClip);
  120. SHADOW_CASTER_FRAGMENT(i)
  121. }
  122. ENDCG
  123. }
  124. }
  125. CustomEditor "TMPro.EditorUtilities.TMP_SDFShaderGUI"
  126. }