LineShader.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. Shader "ARLocation/LineShader"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. _Color ("Color", Color) = (0, 0, 0, 0.6)
  7. _Origin ("Origin", Vector) = (0, 0, 0, 1)
  8. _MaxDistance ("Max Distance", Float) = 4
  9. _FadeDistance ("Fade Distance", Float) = 1
  10. }
  11. SubShader
  12. {
  13. Tags { "RenderType"="Transparent" "Queue"="Transparent" }
  14. LOD 100
  15. ZWrite Off
  16. Blend SrcAlpha OneMinusSrcAlpha
  17. Pass
  18. {
  19. CGPROGRAM
  20. // Upgrade NOTE: excluded shader from DX11; has structs without semantics (struct v2f members worldPos)
  21. #pragma exclude_renderers d3d11
  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. UNITY_FOG_COORDS(1)
  36. float4 vertex : SV_POSITION;
  37. float4 worldPos : TEXCOORD2;
  38. };
  39. sampler2D _MainTex;
  40. float4 _MainTex_ST;
  41. half4 _Color;
  42. float4 _Origin;
  43. float _MaxDistance;
  44. float _FadeDistance;
  45. v2f vert (appdata v)
  46. {
  47. v2f o;
  48. o.vertex = UnityObjectToClipPos(v.vertex);
  49. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  50. o.worldPos = mul(unity_ObjectToWorld, v.vertex);
  51. UNITY_TRANSFER_FOG(o,o.vertex);
  52. return o;
  53. }
  54. fixed4 frag (v2f i) : SV_Target
  55. {
  56. // sample the texture
  57. // apply fog
  58. //UNITY_APPLY_FOG(i.fogCoord, col);
  59. float d = distance(i.worldPos, _Origin);
  60. //i.uv.x -= d;
  61. fixed4 col = tex2D(_MainTex, i.uv);
  62. col *= _Color;
  63. if (d > _MaxDistance)
  64. {
  65. col.a *= 0;
  66. }
  67. else if (d < (_MaxDistance - _FadeDistance))
  68. {
  69. col.a *= 1;
  70. }
  71. else
  72. {
  73. col.a *= (_MaxDistance - d)/_FadeDistance;
  74. }
  75. //float maxDistance = 2.0;
  76. //if (d >= maxDistance)
  77. //{
  78. // col.a = 0;
  79. //}
  80. //else
  81. //{
  82. // col.a = 1 - d/maxDistance;
  83. //}
  84. return col;
  85. }
  86. ENDCG
  87. }
  88. }
  89. }