TMPro_Surface.cginc (3956B)
1 void VertShader(inout appdata_full v, out Input data) 2 { 3 v.vertex.x += _VertexOffsetX; 4 v.vertex.y += _VertexOffsetY; 5 6 UNITY_INITIALIZE_OUTPUT(Input, data); 7 8 float bold = step(v.texcoord1.y, 0); 9 10 // Generate normal for backface 11 float3 view = ObjSpaceViewDir(v.vertex); 12 v.normal *= sign(dot(v.normal, view)); 13 14 #if USE_DERIVATIVE 15 data.param.y = 1; 16 #else 17 float4 vert = v.vertex; 18 float4 vPosition = UnityObjectToClipPos(vert); 19 float2 pixelSize = vPosition.w; 20 21 pixelSize /= float2(_ScaleX, _ScaleY) * mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy); 22 float scale = rsqrt(dot(pixelSize, pixelSize)); 23 scale *= abs(v.texcoord1.y) * _GradientScale * 1.5; 24 scale = lerp(scale * (1 - _PerspectiveFilter), scale, abs(dot(UnityObjectToWorldNormal(v.normal.xyz), normalize(WorldSpaceViewDir(vert))))); 25 data.param.y = scale; 26 #endif 27 28 //float opacity = v.color.a; 29 30 data.param.x = (lerp(_WeightNormal, _WeightBold, bold) / 4.0 + _FaceDilate) * _ScaleRatioA * 0.5; // 31 32 v.texcoord1.xy = UnpackUV(v.texcoord1.x); 33 data.viewDirEnv = mul((float3x3)_EnvMatrix, WorldSpaceViewDir(v.vertex)); 34 } 35 36 void PixShader(Input input, inout SurfaceOutput o) 37 { 38 39 #if USE_DERIVATIVE | BEVEL_ON 40 float3 delta = float3(1.0 / _TextureWidth, 1.0 / _TextureHeight, 0.0); 41 42 float4 smp4x = { tex2D(_MainTex, input.uv_MainTex - delta.xz).a, 43 tex2D(_MainTex, input.uv_MainTex + delta.xz).a, 44 tex2D(_MainTex, input.uv_MainTex - delta.zy).a, 45 tex2D(_MainTex, input.uv_MainTex + delta.zy).a }; 46 #endif 47 48 #if USE_DERIVATIVE 49 // Screen space scaling reciprocal with anisotropic correction 50 float2 edgeNormal = Normalize(float2(smp4x.x - smp4x.y, smp4x.z - smp4x.w)); 51 float2 res = float2(_TextureWidth * input.param.y, _TextureHeight); 52 float2 tdx = ddx(input.uv_MainTex)*res; 53 float2 tdy = ddy(input.uv_MainTex)*res; 54 float lx = length(tdx); 55 float ly = length(tdy); 56 float s = sqrt(min(lx, ly) / max(lx, ly)); 57 s = lerp(1, s, abs(dot(normalize(tdx + tdy), edgeNormal))); 58 float scale = rsqrt(abs(tdx.x * tdy.y - tdx.y * tdy.x)) * (_GradientScale * 2) * s; 59 #else 60 float scale = input.param.y; 61 #endif 62 63 // Signed distance 64 float c = tex2D(_MainTex, input.uv_MainTex).a; 65 float sd = (.5 - c - input.param.x) * scale + .5; 66 float outline = _OutlineWidth*_ScaleRatioA * scale; 67 float softness = _OutlineSoftness*_ScaleRatioA * scale; 68 69 // Color & Alpha 70 float4 faceColor = _FaceColor; 71 float4 outlineColor = _OutlineColor; 72 faceColor *= input.color; 73 outlineColor.a *= input.color.a; 74 faceColor *= tex2D(_FaceTex, float2(input.uv2_FaceTex.x + _FaceUVSpeedX * _Time.y, input.uv2_FaceTex.y + _FaceUVSpeedY * _Time.y)); 75 outlineColor *= tex2D(_OutlineTex, float2(input.uv2_OutlineTex.x + _OutlineUVSpeedX * _Time.y, input.uv2_OutlineTex.y + _OutlineUVSpeedY * _Time.y)); 76 faceColor = GetColor(sd, faceColor, outlineColor, outline, softness); 77 faceColor.rgb /= max(faceColor.a, 0.0001); 78 79 80 #if BEVEL_ON 81 // Face Normal 82 float3 n = GetSurfaceNormal(smp4x, input.param.x); 83 84 // Bumpmap 85 float3 bump = UnpackNormal(tex2D(_BumpMap, input.uv2_FaceTex.xy)).xyz; 86 bump *= lerp(_BumpFace, _BumpOutline, saturate(sd + outline * 0.5)); 87 bump = lerp(float3(0, 0, 1), bump, faceColor.a); 88 n = normalize(n - bump); 89 90 // Cubemap reflection 91 fixed4 reflcol = texCUBE(_Cube, reflect(input.viewDirEnv, mul((float3x3)unity_ObjectToWorld, n))); 92 float3 emission = reflcol.rgb * lerp(_ReflectFaceColor.rgb, _ReflectOutlineColor.rgb, saturate(sd + outline * 0.5)) * faceColor.a; 93 #else 94 float3 n = float3(0, 0, -1); 95 float3 emission = float3(0, 0, 0); 96 #endif 97 98 99 100 #if GLOW_ON 101 float4 glowColor = GetGlowColor(sd, scale); 102 glowColor.a *= input.color.a; 103 emission += glowColor.rgb*glowColor.a; 104 faceColor = BlendARGB(glowColor, faceColor); 105 faceColor.rgb /= max(faceColor.a, 0.0001); 106 #endif 107 108 // Set Standard output structure 109 o.Albedo = faceColor.rgb; 110 o.Normal = -n; 111 o.Emission = emission; 112 o.Specular = lerp(_FaceShininess, _OutlineShininess, saturate(sd + outline * 0.5)); 113 o.Gloss = 1; 114 o.Alpha = faceColor.a; 115 }