SpriteCurved.shader 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Shader "CompassNavigatorPro/Sprite Curved"
  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. [HideInInspector] _FXData ("FX Data", Vector) = (0,0,0,0)
  9. }
  10. SubShader
  11. {
  12. Tags
  13. {
  14. "Queue"="Transparent"
  15. "IgnoreProjector"="True"
  16. "RenderType"="Transparent"
  17. "PreviewType"="Plane"
  18. "CanUseSpriteAtlas"="True"
  19. }
  20. Cull Off
  21. Lighting Off
  22. ZWrite Off
  23. Blend One OneMinusSrcAlpha
  24. Pass
  25. {
  26. CGPROGRAM
  27. #pragma vertex vert
  28. #pragma fragment frag
  29. #pragma target 2.0
  30. #pragma multi_compile _ PIXELSNAP_ON
  31. #pragma multi_compile _ ETC1_EXTERNAL_ALPHA
  32. #include "UnityCG.cginc"
  33. struct appdata_t
  34. {
  35. float4 vertex : POSITION;
  36. float4 color : COLOR;
  37. float2 texcoord : TEXCOORD0;
  38. UNITY_VERTEX_INPUT_INSTANCE_ID
  39. };
  40. struct v2f
  41. {
  42. float4 vertex : SV_POSITION;
  43. fixed4 color : COLOR;
  44. float2 texcoord : TEXCOORD0;
  45. UNITY_VERTEX_OUTPUT_STEREO
  46. };
  47. fixed4 _Color;
  48. float4 _FXData;
  49. v2f vert(appdata_t IN)
  50. {
  51. v2f OUT;
  52. UNITY_SETUP_INSTANCE_ID(IN);
  53. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  54. // Get screen position
  55. float4 pos = UnityObjectToClipPos(IN.vertex);
  56. float4 screenPos = ComputeScreenPos(pos);
  57. pos.y -= sin(screenPos.x * 3.1415927) * _FXData.x;
  58. OUT.texcoord = IN.texcoord;
  59. float distToEdge = _FXData.y - abs(screenPos.x - 0.5) * 2 + 0.001;
  60. float fadeOut = saturate((distToEdge - _FXData.w) / (_FXData.z + 0.0001));
  61. OUT.color = IN.color * _Color;
  62. OUT.color.a *= fadeOut;
  63. #ifdef PIXELSNAP_ON
  64. pos = UnityPixelSnap (pos);
  65. #endif
  66. OUT.vertex = pos;
  67. return OUT;
  68. }
  69. sampler2D _MainTex;
  70. sampler2D _AlphaTex;
  71. fixed4 SampleSpriteTexture (float2 uv)
  72. {
  73. fixed4 color = tex2D (_MainTex, uv);
  74. #if ETC1_EXTERNAL_ALPHA
  75. // get the color from an external texture (usecase: Alpha support for ETC1 on android)
  76. color.a = tex2D (_AlphaTex, uv).r;
  77. #endif //ETC1_EXTERNAL_ALPHA
  78. return color;
  79. }
  80. fixed4 frag(v2f IN) : SV_Target
  81. {
  82. fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
  83. c.rgb *= c.a;
  84. return c;
  85. }
  86. ENDCG
  87. }
  88. }
  89. }