1
0

TMPro.cginc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. float2 UnpackUV(float uv)
  2. {
  3. float2 output;
  4. output.x = floor(uv / 4096);
  5. output.y = uv - 4096 * output.x;
  6. return output * 0.001953125;
  7. }
  8. fixed4 GetColor(half d, fixed4 faceColor, fixed4 outlineColor, half outline, half softness)
  9. {
  10. half faceAlpha = 1-saturate((d - outline * 0.5 + softness * 0.5) / (1.0 + softness));
  11. half outlineAlpha = saturate((d + outline * 0.5)) * sqrt(min(1.0, outline));
  12. faceColor.rgb *= faceColor.a;
  13. outlineColor.rgb *= outlineColor.a;
  14. faceColor = lerp(faceColor, outlineColor, outlineAlpha);
  15. faceColor *= faceAlpha;
  16. return faceColor;
  17. }
  18. float3 GetSurfaceNormal(float4 h, float bias)
  19. {
  20. bool raisedBevel = step(1, fmod(_ShaderFlags, 2));
  21. h += bias+_BevelOffset;
  22. float bevelWidth = max(.01, _OutlineWidth+_BevelWidth);
  23. // Track outline
  24. h -= .5;
  25. h /= bevelWidth;
  26. h = saturate(h+.5);
  27. if(raisedBevel) h = 1 - abs(h*2.0 - 1.0);
  28. h = lerp(h, sin(h*3.141592/2.0), _BevelRoundness);
  29. h = min(h, 1.0-_BevelClamp);
  30. h *= _Bevel * bevelWidth * _GradientScale * -2.0;
  31. float3 va = normalize(float3(1.0, 0.0, h.y - h.x));
  32. float3 vb = normalize(float3(0.0, -1.0, h.w - h.z));
  33. return cross(va, vb);
  34. }
  35. float3 GetSurfaceNormal(float2 uv, float bias, float3 delta)
  36. {
  37. // Read "height field"
  38. float4 h = {tex2D(_MainTex, uv - delta.xz).a,
  39. tex2D(_MainTex, uv + delta.xz).a,
  40. tex2D(_MainTex, uv - delta.zy).a,
  41. tex2D(_MainTex, uv + delta.zy).a};
  42. return GetSurfaceNormal(h, bias);
  43. }
  44. float3 GetSpecular(float3 n, float3 l)
  45. {
  46. float spec = pow(max(0.0, dot(n, l)), _Reflectivity);
  47. return _SpecularColor.rgb * spec * _SpecularPower;
  48. }
  49. float4 GetGlowColor(float d, float scale)
  50. {
  51. float glow = d - (_GlowOffset*_ScaleRatioB) * 0.5 * scale;
  52. float t = lerp(_GlowInner, (_GlowOuter * _ScaleRatioB), step(0.0, glow)) * 0.5 * scale;
  53. glow = saturate(abs(glow/(1.0 + t)));
  54. glow = 1.0-pow(glow, _GlowPower);
  55. glow *= sqrt(min(1.0, t)); // Fade off glow thinner than 1 screen pixel
  56. return float4(_GlowColor.rgb, saturate(_GlowColor.a * glow * 2));
  57. }
  58. float4 BlendARGB(float4 overlying, float4 underlying)
  59. {
  60. overlying.rgb *= overlying.a;
  61. underlying.rgb *= underlying.a;
  62. float3 blended = overlying.rgb + ((1-overlying.a)*underlying.rgb);
  63. float alpha = underlying.a + (1-underlying.a)*overlying.a;
  64. return float4(blended, alpha);
  65. }