InvertMask.shader 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //对图片的mask处理,只有椭圆部分
  2. Shader "Custom/InvertMask"
  3. {
  4. Properties
  5. {
  6. _MainTex("Base (RGB), Alpha (A)", 2D) = "black" {}
  7. _CenterX("CenterX", float) = 0.5
  8. _CenterY("CenterY", float) = 0.5
  9. _Width("Width", float) = 0.5
  10. _Height("Height", float) = 0.15
  11. _LengthRate("LengthRate", float) = 0.1
  12. _LengthRateTransition("LengthRateLerp", float) = 0.01
  13. }
  14. SubShader
  15. {
  16. LOD 200
  17. Tags
  18. {
  19. "Queue" = "Transparent"
  20. "IgnoreProjector" = "True"
  21. "RenderType" = "Transparent"
  22. }
  23. Pass
  24. {
  25. Cull Off
  26. Lighting Off
  27. ZWrite Off
  28. Fog{ Mode Off }
  29. Offset -1,-1
  30. Blend SrcAlpha OneMinusSrcAlpha
  31. CGPROGRAM
  32. #pragma vertex vert
  33. #pragma fragment frag
  34. #include "UnityCG.cginc"
  35. sampler2D _MainTex;
  36. half4 _MainTex_ST;
  37. half _CenterX;
  38. half _CenterY;
  39. half _Width;
  40. half _Height;
  41. half _LengthRate;
  42. half _LengthRateTransition;
  43. struct appdata_t
  44. {
  45. half4 vertex : POSITION;
  46. half2 texcoord : TEXCOORD0;
  47. fixed4 color : COLOR;
  48. };
  49. struct v2f
  50. {
  51. half4 vertex : SV_POSITION;
  52. half2 texcoord : TEXCOORD0;
  53. fixed4 color : COLOR;
  54. };
  55. v2f o;
  56. v2f vert(appdata_t v)
  57. {
  58. o.vertex = UnityObjectToClipPos(v.vertex);
  59. o.texcoord = v.texcoord;
  60. o.color = v.color;
  61. return o;
  62. }
  63. fixed4 frag(v2f IN) : COLOR
  64. {
  65. half2 pt = IN.texcoord - half2(_CenterX,(1 - _CenterY));
  66. half h = (pt.x*pt.x) / (_Width*_Width) + (pt.y*pt.y) / (_Height*_Height);
  67. half4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
  68. half sub = _LengthRate - h;
  69. if (h < _LengthRate && sub < _LengthRateTransition)
  70. {
  71. c.a = c.a - sub / _LengthRateTransition ;
  72. return c;
  73. }
  74. else if (h < _LengthRate)
  75. {
  76. discard;
  77. }
  78. return c;
  79. }
  80. ENDCG
  81. }
  82. }
  83. SubShader
  84. {
  85. LOD 100
  86. Tags
  87. {
  88. "Queue" = "Transparent"
  89. "IgnoreProjector" = "True"
  90. "RenderType" = "Transparent"
  91. }
  92. Pass
  93. {
  94. Cull Off
  95. Lighting Off
  96. ZWrite Off
  97. Fog{ Mode Off }
  98. Offset -1,-1
  99. ColorMask RGB
  100. Blend SrcAlpha OneMinusSrcAlpha
  101. ColorMaterial AmbientAndDiffuse
  102. SetTexture[_MainTex]
  103. {
  104. Combine Texture * Primary
  105. }
  106. }
  107. }
  108. }