AlphaBlendedCustom.shader 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. Shader "YXJ/Particles/AlphaBlendedCustom"
  2. {
  3. Properties
  4. {
  5. _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
  6. _MainTex ("Texture", 2D) = "white" {}
  7. [Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull Mode", Float) = 0
  8. [Space]
  9. [Toggle(MASK)] _MaskOn ("Enable Mask?", float) = 0
  10. _MaskTex ("Mask (A)", 2D) = "white" {}
  11. _CutOff ("Alpha CutOff", Range(0,1.0)) = 0.5
  12. [Space]
  13. [Toggle(SCROLL)] _ScrollOn ("Enable Scroll?", float) = 0
  14. [Enum(Manual, 0, AutoMain, 1, AutoMask, 2)] _ScrollType ("Scroll Type", float) = 0
  15. [Space]
  16. _UV ("UV Main", vector) = (1,1,0,0)
  17. _UV2 ("UV Mask", vector) = (1,1,0,0)
  18. _SpeedU ("Scroll Speed U", float) = 1
  19. _SpeedV ("Scroll Speed V", float) = 0
  20. [Enum(Close, 0, Open, 1)] _FogSwitch("Fog", float) = 0
  21. }
  22. Category
  23. {
  24. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  25. Blend SrcAlpha OneMinusSrcAlpha
  26. ColorMask RGB
  27. Cull [_Cull] Lighting Off ZWrite Off
  28. SubShader
  29. {
  30. Pass
  31. {
  32. CGPROGRAM
  33. #pragma vertex vert
  34. #pragma fragment frag
  35. #pragma multi_compile_fog
  36. #pragma multi_compile __ MASK
  37. #pragma multi_compile __ SCROLL
  38. #include "UnityCG.cginc"
  39. sampler2D _MainTex;
  40. fixed4 _TintColor;
  41. float4 _MainTex_ST;
  42. float _FogSwitch;
  43. #if MASK
  44. sampler2D _MaskTex;
  45. float4 _MaskTex_ST;
  46. float _CutOff;
  47. struct appdata_t {
  48. float4 vertex : POSITION;
  49. fixed4 color : COLOR;
  50. float2 texcoord : TEXCOORD0;
  51. float2 texcoordm : TEXCOORD1;
  52. };
  53. struct v2f {
  54. float4 vertex : SV_POSITION;
  55. fixed4 color : COLOR;
  56. float2 texcoord : TEXCOORD0;
  57. float2 texcoordm : TEXCOORD1;
  58. UNITY_FOG_COORDS(2)
  59. };
  60. #else
  61. struct appdata_t {
  62. float4 vertex : POSITION;
  63. fixed4 color : COLOR;
  64. float2 texcoord : TEXCOORD0;
  65. };
  66. struct v2f {
  67. float4 vertex : SV_POSITION;
  68. fixed4 color : COLOR;
  69. float2 texcoord : TEXCOORD0;
  70. UNITY_FOG_COORDS(1)
  71. };
  72. #endif
  73. #if SCROLL
  74. float _ScrollType;
  75. float4 _UV;
  76. float4 _UV2;
  77. float _SpeedU;
  78. float _SpeedV;
  79. #endif
  80. v2f vert (appdata_t v)
  81. {
  82. v2f o;
  83. o.vertex = UnityObjectToClipPos(v.vertex);
  84. o.color = v.color;
  85. o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  86. if(_FogSwitch == 1) { UNITY_TRANSFER_FOG(o, o.vertex); }
  87. #if SCROLL
  88. if (_ScrollType == 0){
  89. o.texcoord = float2(o.texcoord.x * _UV.x + _UV.z, o.texcoord.y * _UV.y + _UV.w);
  90. }
  91. else if (_ScrollType == 1){
  92. o.texcoord += _Time.x * float2(_SpeedU, _SpeedV);
  93. }
  94. #endif
  95. #if MASK
  96. o.texcoordm = TRANSFORM_TEX(v.texcoordm, _MaskTex);
  97. #if SCROLL
  98. if (_ScrollType == 0){
  99. o.texcoordm = float2(o.texcoordm.x * _UV2.x + _UV2.z, o.texcoordm.y * _UV2.y + _UV2.w);
  100. }
  101. else if (_ScrollType == 2){
  102. o.texcoordm += _Time.x * float2(_SpeedU, _SpeedV);
  103. }
  104. #endif
  105. #endif
  106. return o;
  107. }
  108. fixed4 frag (v2f i) : SV_Target
  109. {
  110. fixed4 col = tex2D(_MainTex, i.texcoord) * i.color;
  111. #if MASK
  112. col.a *= UNITY_SAMPLE_1CHANNEL(_MaskTex, i.texcoordm);
  113. clip(col.a - _CutOff);
  114. #endif
  115. col *= _TintColor * 2.44;
  116. if(_FogSwitch == 1) { UNITY_APPLY_FOG(i.fogCoord, col); }
  117. return col;
  118. }
  119. ENDCG
  120. }
  121. }
  122. }
  123. }