Advertisement
KaiClavier

STMSurfaceEmission.shader

Feb 5th, 2022
4,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Super Text Mesh/Surface/Emission"
  2. {
  3.    
  4.     //Temporary shader!!
  5.     //pixel snap not yet supported
  6.     //uses full emission, but can be changed at the end of this code.
  7.  
  8.  
  9.    
  10.     Properties
  11.     {
  12.         _MainTex ("Font Texture", 2D) = "white" {}
  13.         _MaskTex ("Mask Texture", 2D) = "white" {}
  14.         [Toggle(SDF_MODE)] _SDFMode ("Toggle SDF Mode", Float) = 0
  15.         [ShowIf(SDF_MODE)] _SDFCutoff ("SDF Cutoff", Range(0,1)) = 0.5
  16.         [ShowIf(SDF_MODE)] _Blend ("Blend Width", Range(0.0001,1)) = 0.05
  17.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
  18.         _ShadowCutoff ("Shadow Cutoff", Range(0,1)) = 0.5
  19.         _Cutoff ("Cutoff", Range(0,1)) = 0.0001 //text cutoff
  20.         [Enum(UnityEngine.Rendering.CullMode)] _CullMode ("Cull Mode", Float) = 0
  21.         [Enum(Normal,2,On Top,6)] _ZTestMode ("ZTest Mode", Float) = 2
  22.     }
  23.     SubShader
  24.     {
  25.         Tags
  26.         {
  27.             "Queue"="Transparent"
  28.             "IgnoreProjector"="True"
  29.             "RenderType"="Transparent"
  30.             "PreviewType"="Plane"
  31.             "STMUberShader"="Yes"
  32.         }
  33.         LOD 100
  34.  
  35.         Lighting Off
  36.         Cull [_CullMode]
  37.         ZTest [_ZTestMode]
  38.         ZWrite Off
  39.        
  40.         CGPROGRAM
  41.         // Physically based Standard lighting model, and enable shadows on all light types
  42.         #pragma surface surf Standard fullforwardshadows alpha:fade addshadow
  43.         #pragma shader_feature SDF_MODE
  44.  
  45.  
  46.         sampler2D _MainTex;
  47.         sampler2D _MaskTex;
  48.         float _SDFCutoff;
  49.         float _Blend;
  50.  
  51.         struct Input
  52.         {
  53.             float2 uv_MainTex : TEXCOORD0;
  54.             float2 uv2_MaskTex : TEXCOORD1;
  55.             fixed4 color : COLOR;
  56.             float4 vertex : POSITION;
  57.         };
  58.  
  59.         float4 when_lt(float4 x, float4 y)
  60.         {
  61.             return max(sign(y - x), 0.0);
  62.         }
  63.  
  64.         float4 when_ge(float4 x, float4 y)
  65.         {
  66.             return 1.0 - when_lt(x, y);
  67.         }
  68.  
  69.         void surf (Input i, inout SurfaceOutputStandard o)
  70.         {
  71.             // Albedo comes from a texture tinted by color
  72.             fixed4 text = tex2D(_MainTex, i.uv_MainTex);
  73.             fixed4 mask = tex2D(_MaskTex, i.uv2_MaskTex.xy);
  74.             fixed4 col = fixed4(0,0,0,0);
  75.  
  76.             #if SDF_MODE
  77.             //anything before this point is already cut by (0,0,0,0)
  78.             //transparency to text
  79.             col.rgb += (mask.rgb * i.color.rgb) *
  80.                         when_ge(text.a, _SDFCutoff) *
  81.                         when_lt(text.a, _SDFCutoff + _Blend);
  82.             col.a += ((text.a - _SDFCutoff + (_Blend/100)) / _Blend * mask.a * i.color.a) *
  83.                         //alpha greater or equal than cutoff
  84.                         when_ge(text.a, _SDFCutoff) *
  85.                         //alpha less than blend point
  86.                         when_lt(text.a, _SDFCutoff + _Blend);
  87.             //get color from mask & vertex
  88.             col += (mask * i.color) *
  89.                         //greater than blend point
  90.                         when_ge(text.a, _SDFCutoff + _Blend);
  91.             #else
  92.             col.rgb = mask.rgb * i.color.rgb;
  93.             col.a = text.a * mask.a * i.color.a;
  94.             #endif
  95.  
  96.             o.Emission = col.rgb;
  97.             o.Alpha = col.a;
  98.         }
  99.         ENDCG
  100.     }
  101.     FallBack "GUI/Text Shader"
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement