SafetyEdge_Confirm.shader 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. Shader "Unlit/SafetyEdge_Confirm"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. //_NearTex ("NearTex", 2D) = "white" {}
  7. _MainTex2("Texture2", 2D) = "white" {}
  8. _MainTex3("Texture3", 2D) = "white" {}
  9. }
  10. SubShader
  11. {
  12. Tags { //"RenderType" = "Opaque"
  13. //"LightMode" = "ShadowCaster"}
  14. }
  15. LOD 100
  16. cull off
  17. Blend SrcAlpha OneMinusSrcAlpha
  18. ZWrite Off
  19. Pass
  20. {
  21. CGPROGRAM
  22. #pragma vertex vert
  23. #pragma fragment frag
  24. // make fog work
  25. //#pragma multi_compile_fog
  26. #include "UnityCG.cginc"
  27. struct appdata
  28. {
  29. float4 vertex : POSITION;
  30. float2 uv : TEXCOORD0;
  31. };
  32. struct v2f
  33. {
  34. float2 uv : TEXCOORD0;
  35. //float2 nearuv : TEXCOORD3;
  36. float2 uv2 : TEXCOORD4;
  37. float2 uv3 : TEXCOORD5;
  38. float viewPosZ : TEXCOORD2;
  39. float4 screenPos : TEXCOORD1;
  40. float4 vertex : SV_POSITION;
  41. };
  42. sampler2D _MainTex;
  43. float4 _MainTex_ST;
  44. //sampler2D _NearTex;
  45. //float4 _NearTex_ST;
  46. sampler2D _MainTex2;
  47. float4 _MainTex2_ST;
  48. sampler2D _MainTex3;
  49. float4 _MainTex3_ST;
  50. fixed3 interactionPosition[3];
  51. int positionCount;
  52. fixed alpha;
  53. int bowHead;
  54. fixed4 _Color1;
  55. fixed4 _Color2;
  56. fixed4 settingsColor;
  57. v2f vert (appdata v)
  58. {
  59. v2f o;
  60. _MainTex2_ST.w = -_Time.y / 2;
  61. _MainTex3_ST.z = -1 + (_Time.y / 2) % 2;
  62. o.vertex = UnityObjectToClipPos(v.vertex);
  63. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  64. //o.nearuv = TRANSFORM_TEX(v.uv, _NearTex);
  65. o.uv2 = TRANSFORM_TEX(v.uv, _MainTex2);
  66. o.uv3 = TRANSFORM_TEX(v.uv, _MainTex3);
  67. o.screenPos = ComputeScreenPos(o.vertex);
  68. o.viewPosZ = UnityObjectToViewPos(v.vertex).z;
  69. return o;
  70. }
  71. fixed getDistance(fixed3 position[3], fixed3 screenPosition)
  72. {
  73. float cdist = 99999.0;
  74. for (uint i = 0; i < positionCount; i++) {
  75. cdist = min(cdist, distance(position[i], screenPosition));
  76. }
  77. return cdist;
  78. }
  79. fixed4 frag (v2f i) : SV_Target
  80. {
  81. fixed4 col = tex2D(_MainTex, i.uv);
  82. //fixed4 nearCol = tex2D(_NearTex, i.nearuv);
  83. fixed4 col2 = tex2D(_MainTex2, i.uv2);
  84. fixed4 col3 = tex2D(_MainTex3, i.uv3);
  85. fixed2 screenPos = fixed2(i.screenPos.xy / i.screenPos.w);
  86. fixed dist = getDistance(interactionPosition, fixed3(screenPos.x, screenPos.y, -i.viewPosZ));
  87. //col = fixed4(settingsColor.r, settingsColor.g, settingsColor.b ,col.a);
  88. fixed4 normalCol = _Color1 * col + col2 * _Color2;
  89. col = fixed4(normalCol.r, normalCol.g, normalCol.b, col.a);
  90. if (alpha > 0.8)
  91. {
  92. col = fixed4(settingsColor.r, settingsColor.g, settingsColor.b, col.a * alpha);
  93. }
  94. if (dist < 0.3)
  95. {
  96. col = fixed4(0, 0, 0, 0);
  97. }
  98. if (dist >= 0.3 && dist < 0.32)
  99. {
  100. col = fixed4(0.9569, 0.0275, 0.1569, 1);
  101. }
  102. if (i.uv.y < 0.05)
  103. {
  104. //col = settingsColor;
  105. col = _Color1 + col3 * _Color2;
  106. }
  107. return col;
  108. }
  109. ENDCG
  110. }
  111. }
  112. }