Text3DShader.shader 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License. See LICENSE in the project root for license information.
  3. ///
  4. /// Basic 3D TextMesh shader with proper z-sorting and culling options.
  5. ///
  6. Shader "ShadowSDK/Text3DShader"
  7. {
  8. Properties
  9. {
  10. _MainTex("Alpha (A)", 2D) = "white" {}
  11. [Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull", Float) = 0
  12. [HideInInspector] _Color("Main Color", Color) = (1,1,1,1)
  13. [HideInInspector] _StencilComp("Stencil Comparison", Float) = 8
  14. [HideInInspector] _Stencil("Stencil ID", Float) = 0
  15. [HideInInspector] _StencilOp("Stencil Operation", Float) = 0
  16. [HideInInspector] _StencilWriteMask("Stencil Write Mask", Float) = 255
  17. [HideInInspector] _StencilReadMask("Stencil Read Mask", Float) = 255
  18. [HideInInspector] _ColorMask("Color Mask", Float) = 15
  19. }
  20. SubShader
  21. {
  22. LOD 200
  23. Tags
  24. {
  25. "Queue" = "Transparent"
  26. "IgnoreProjector" = "True"
  27. "RenderType" = "Transparent"
  28. "PreviewType" = "Plane"
  29. }
  30. Stencil
  31. {
  32. Ref[_Stencil]
  33. Comp[_StencilComp]
  34. Pass[_StencilOp]
  35. ReadMask[_StencilReadMask]
  36. WriteMask[_StencilWriteMask]
  37. }
  38. Cull[_Cull]
  39. Lighting Off
  40. ZWrite On
  41. ZTest[unity_GUIZTestMode]
  42. Offset -1, -1
  43. Fog { Mode Off }
  44. Blend SrcAlpha OneMinusSrcAlpha
  45. ColorMask[_ColorMask]
  46. Pass
  47. {
  48. CGPROGRAM
  49. #pragma vertex vert
  50. #pragma fragment frag
  51. #pragma multi_compile_instancing
  52. #include "UnityCG.cginc"
  53. struct appdata_t
  54. {
  55. float4 vertex : POSITION;
  56. half4 color : COLOR;
  57. float2 texcoord : TEXCOORD0;
  58. UNITY_VERTEX_INPUT_INSTANCE_ID
  59. };
  60. struct v2f
  61. {
  62. float4 vertex : POSITION;
  63. half4 color : COLOR;
  64. float2 texcoord : TEXCOORD0;
  65. UNITY_VERTEX_INPUT_INSTANCE_ID
  66. UNITY_VERTEX_OUTPUT_STEREO
  67. };
  68. sampler2D _MainTex;
  69. float4 _MainTex_ST;
  70. UNITY_INSTANCING_BUFFER_START(Props)
  71. UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
  72. #define _Color_arr Props
  73. UNITY_INSTANCING_BUFFER_END(Props)
  74. v2f vert(appdata_t v)
  75. {
  76. v2f o;
  77. UNITY_SETUP_INSTANCE_ID(v);
  78. UNITY_TRANSFER_INSTANCE_ID(v, o);
  79. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  80. o.vertex = UnityObjectToClipPos(v.vertex);
  81. o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  82. o.color = v.color;
  83. #ifdef UNITY_HALF_TEXEL_OFFSET
  84. o.vertex.xy += (_ScreenParams.zw - 1.0)*float2(-1,1);
  85. #endif
  86. return o;
  87. }
  88. half4 frag(v2f i) : COLOR
  89. {
  90. UNITY_SETUP_INSTANCE_ID(i);
  91. half4 col = i.color;
  92. col.a *= tex2D(_MainTex, i.texcoord).a;
  93. col = col * UNITY_ACCESS_INSTANCED_PROP(_Color_arr, _Color);
  94. clip(col.a - 0.01);
  95. return col;
  96. }
  97. ENDCG
  98. }
  99. }
  100. }