You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
5.5 KiB

  1. Shader "Graphy/Graph Mobile"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  6. _Color("Tint", Color) = (1,1,1,1)
  7. [MaterialToggle] PixelSnap("Pixel snap", Float) = 0
  8. _GoodColor("Good Color", Color) = (1,1,1,1)
  9. _CautionColor("Caution Color", Color) = (1,1,1,1)
  10. _CriticalColor("Critical Color", Color) = (1,1,1,1)
  11. _GoodThreshold("Good Threshold", Float) = 0.5
  12. _CautionThreshold("Caution Threshold", Float) = 0.25
  13. }
  14. SubShader
  15. {
  16. // Tags
  17. // {
  18. // "Queue" = "Overlay"
  19. // "IgnoreProjector" = "True"
  20. // "RenderType" = "Transparent"
  21. // "PreviewType" = "Plane"
  22. // "CanUseSpriteAtlas" = "True"
  23. // }
  24. Cull Off
  25. Lighting Off
  26. ZWrite Off
  27. ZTest Off
  28. Blend One OneMinusSrcAlpha
  29. Pass
  30. {
  31. CGPROGRAM
  32. #pragma vertex vert
  33. #pragma fragment frag
  34. #pragma multi_compile _ PIXELSNAP_ON
  35. #include "UnityCG.cginc"
  36. struct appdata_t
  37. {
  38. float4 vertex : POSITION;
  39. float4 color : COLOR;
  40. float2 texcoord : TEXCOORD0;
  41. };
  42. struct v2f
  43. {
  44. float4 vertex : SV_POSITION;
  45. fixed4 color : COLOR;
  46. float2 texcoord : TEXCOORD0;
  47. };
  48. fixed4 _Color;
  49. v2f vert(appdata_t IN)
  50. {
  51. v2f OUT;
  52. OUT.vertex = UnityObjectToClipPos(IN.vertex);
  53. OUT.texcoord = IN.texcoord;
  54. OUT.color = IN.color * _Color;
  55. #ifdef PIXELSNAP_ON
  56. OUT.vertex = UnityPixelSnap(OUT.vertex);
  57. #endif
  58. return OUT;
  59. }
  60. sampler2D _MainTex;
  61. sampler2D _AlphaTex;
  62. float _AlphaSplitEnabled;
  63. fixed4 SampleSpriteTexture(float2 uv)
  64. {
  65. fixed4 color = tex2D(_MainTex, uv);
  66. #if UNITY_TEXTURE_ALPHASPLIT_ALLOWED
  67. if (_AlphaSplitEnabled)
  68. color.a = tex2D(_AlphaTex, uv).r;
  69. #endif //UNITY_TEXTURE_ALPHASPLIT_ALLOWED
  70. return color;
  71. }
  72. fixed4 _GoodColor;
  73. fixed4 _CautionColor;
  74. fixed4 _CriticalColor;
  75. fixed _GoodThreshold;
  76. fixed _CautionThreshold;
  77. uniform float Average;
  78. // NOTE: The size of this array can break compatibility with some older GPUs
  79. // This shader is equal to GraphStandard.shader but with a smaller Array size.
  80. uniform float GraphValues[128];
  81. uniform float GraphValues_Length;
  82. fixed4 frag(v2f IN) : SV_Target
  83. {
  84. fixed4 color = IN.color;
  85. fixed xCoord = IN.texcoord.x;
  86. fixed yCoord = IN.texcoord.y;
  87. float graphValue = GraphValues[floor(xCoord * GraphValues_Length)];
  88. // Define the width of each element of the graph
  89. float increment = 1.0f / (GraphValues_Length - 1);
  90. // Set as transparent the part on top of the current point value
  91. if (yCoord > graphValue)
  92. {
  93. color.a = 0;
  94. }
  95. // Assign the corresponding color
  96. if (graphValue > _GoodThreshold)
  97. {
  98. color *= _GoodColor;
  99. }
  100. else if (graphValue > _CautionThreshold)
  101. {
  102. color *= _CautionColor;
  103. }
  104. else
  105. {
  106. color *= _CriticalColor;
  107. }
  108. // Point coloring
  109. if (graphValue - yCoord > increment * 4)
  110. {
  111. //color.a = yCoord * graphValue * 0.3;
  112. color.a *= yCoord * 0.3 / graphValue;
  113. }
  114. // Average white bar
  115. if (yCoord < Average && yCoord > Average - 0.02)
  116. {
  117. color = fixed4(1, 1, 1, 1);
  118. }
  119. // CautionColor bar
  120. if (yCoord < _CautionThreshold && yCoord > _CautionThreshold - 0.02)
  121. {
  122. color = _CautionColor;
  123. }
  124. // GoodColor bar
  125. if (yCoord < _GoodThreshold && yCoord > _GoodThreshold - 0.02)
  126. {
  127. color = _GoodColor;
  128. }
  129. // Fade the alpha of the sides of the graph
  130. if (xCoord < 0.03)
  131. {
  132. color.a *= 1 - (0.03 - xCoord) / 0.03;
  133. }
  134. else if (xCoord > 0.97)
  135. {
  136. color.a *= (1 - xCoord) / 0.03;
  137. }
  138. fixed4 c = SampleSpriteTexture(IN.texcoord) * color;
  139. c.rgb *= c.a;
  140. return c;
  141. }
  142. ENDCG
  143. }
  144. }
  145. }