Particles_YXJ.shader 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. Shader "URP/Particles_YXJ"
  2. {
  3. Properties
  4. {
  5. [KeywordEnum(MUL, ADD)] _InputBlend("Input Blend", int) = 0
  6. _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
  7. [KeywordEnum(MUL, ADD, SUB, DIFF, COL)] _ColorBlend("Color Blend", int) = 0
  8. _MainTex ("Texture", 2D) = "white" {}
  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. [Toggle(SCROLL)] _ScrollOn ("Enable Scroll?", float) = 0
  13. [Enum(Manual, 0, AutoMain, 1, AutoMask, 2)] _ScrollType ("Scroll Type", float) = 0
  14. _UV ("UV Main", vector) = (1,1,0,0)
  15. _UV2 ("UV Mask", vector) = (1,1,0,0)
  16. _SpeedU ("Scroll Speed U", float) = 1
  17. _SpeedV ("Scroll Speed V", float) = 0
  18. _Up ("Up Level", float) = 1
  19. [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Src Blend Mode", float) = 5
  20. [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Dst Blend Mode", float) = 10
  21. [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest Mode", float) = 4
  22. [Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull Mode", Float) = 2
  23. [Enum(Close, 0, Open, 1)] _FogSwitch("Fog", float) = 0
  24. [Enum(Close, 0, Open, 1)] _NiuQu("Niu Qu", float) = 0
  25. _AphaCorrect("GammaApha", Range(1, 3)) = 1
  26. _DistortStrength("NQ Stength", Range(0,1)) = 0.5
  27. _DistortVelocity("NQ Veloctiy", Range(0,1)) = 0.5
  28. _NoiseTex("Noise Texture", 2D) = "white" {}
  29. _ColorMask("Color Mask", float) = 14
  30. }
  31. SubShader
  32. {
  33. Tags{"Queue"="Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" "PreviewType" = "Plane" "PerformanceChecks" = "False" "RenderPipeline" = "UniversalPipeline"}
  34. Pass
  35. {
  36. Name "YXJParticles"
  37. Blend[_SrcBlend][_DstBlend]
  38. Cull[_Cull]
  39. ZTest[_ZTest]
  40. ZWrite Off
  41. ColorMask [_ColorMask]
  42. HLSLPROGRAM
  43. #pragma prefer_hlslcc gles
  44. #pragma exclude_renderers d3d11_9x
  45. #pragma target 2.0
  46. #pragma vertex vert
  47. #pragma fragment frag
  48. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  49. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  50. #pragma multi_compile_fog
  51. #pragma shader_feature _ MASK
  52. #pragma shader_feature _ SCROLL
  53. #pragma shader_feature _INPUTBLEND_MUL _INPUTBLEND_ADD
  54. #pragma shader_feature _COLORBLEND_MUL _COLORBLEND_ADD _COLORBLEND_SUB _COLORBLEND_DIFF _COLORBLEND_COL
  55. #pragma shader_feature _ GammaCorrect
  56. struct AttributesParticle
  57. {
  58. float4 vertex : POSITION;
  59. float4 color : COLOR;
  60. float2 texcoord : TEXCOORD0;
  61. #if defined(MASK)
  62. float2 texcoordm : TEXCOORD1;
  63. #endif
  64. };
  65. struct VaryingsParticle
  66. {
  67. float4 vertex : SV_POSITION;
  68. float4 color : COLOR;
  69. float fogFactor : TEXCOORD0;
  70. float2 texcoord : TEXCOORD1;
  71. float2 texcoord1 : TEXCOORD2;
  72. #if defined(MASK)
  73. float2 texcoordm : TEXCOORD3;
  74. #endif
  75. UNITY_VERTEX_OUTPUT_STEREO
  76. };
  77. TEXTURE2D(_MainTex);
  78. SAMPLER(sampler_MainTex);
  79. #if defined(MASK)
  80. TEXTURE2D(_MaskTex);
  81. SAMPLER(sampler_MaskTex);
  82. #endif
  83. TEXTURE2D(_NoiseTex);
  84. SAMPLER(sampler_NoiseTex);
  85. CBUFFER_START(UnityPerMaterial)
  86. float4 _TintColor;
  87. float4 _MainTex_ST;
  88. float4 _MaskTex_ST;
  89. float4 _NoiseTex_ST;
  90. float _CutOff;
  91. float _ScrollType;
  92. float4 _UV;
  93. float4 _UV2;
  94. float _SpeedU;
  95. float _SpeedV;
  96. float _FogSwitch;
  97. float _Up;
  98. float _NiuQu;
  99. float _DistortStrength;
  100. float _DistortVelocity;
  101. float _AphaCorrect;
  102. CBUFFER_END
  103. float4 MixParticleColor(float4 baseColor, float4 particleColor)
  104. {
  105. #if defined(_COLORBLEND_MUL)
  106. return baseColor * particleColor;
  107. #elif defined(_COLORBLEND_COL)
  108. half3 aHSL = RgbToHsv(baseColor.rgb);
  109. half3 bHSL = RgbToHsv(particleColor.rgb);
  110. half3 rHSL = half3(bHSL.x, bHSL.y, aHSL.z);
  111. return half4(HsvToRgb(rHSL), baseColor.a * particleColor.a);
  112. #else
  113. half4 colorAddSubDiff = half4(0, 0, 0, 0);
  114. #if defined(_COLORBLEND_ADD)
  115. colorAddSubDiff = half4(1.0, 0, 0, 0);
  116. #elif defined(_COLORBLEND_DIFF)
  117. colorAddSubDiff = half4(-1.0, 1.0, 0, 0);
  118. #elif defined(_COLORBLEND_SUB)
  119. colorAddSubDiff = half4(-1.0, 0, 0, 0);
  120. #endif
  121. float4 output = baseColor;
  122. output.rgb = baseColor.rgb + particleColor.rgb * colorAddSubDiff.x;
  123. output.rgb = lerp(output.rgb, abs(output.rgb), colorAddSubDiff.y);
  124. output.a *= particleColor.a;
  125. return output;
  126. #endif
  127. }
  128. VaryingsParticle vert(AttributesParticle v)
  129. {
  130. VaryingsParticle o = (VaryingsParticle)0;
  131. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  132. float3 ws = TransformObjectToWorld(v.vertex.xyz);
  133. float4 cs = TransformWorldToHClip(ws);
  134. if(_FogSwitch == 1) o.fogFactor = ComputeFogFactor(cs.z);
  135. o.vertex = cs;
  136. o.color = v.color;
  137. o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  138. if(_NiuQu == 1)
  139. {
  140. o.texcoord1 = TRANSFORM_TEX(v.texcoord, _NoiseTex);
  141. o.texcoord1 -= _Time.y * _DistortVelocity;
  142. }
  143. #if defined(MASK)
  144. o.texcoordm = TRANSFORM_TEX(v.texcoordm, _MaskTex);
  145. #if defined(SCROLL)
  146. if(_ScrollType == 0) o.texcoordm = float2(o.texcoordm.x * _UV2.x + _UV2.z, o.texcoordm.y * _UV2.y + _UV2.w);
  147. else if(_ScrollType == 2) o.texcoordm += _Time.x * float2(_SpeedU, _SpeedV);
  148. #endif
  149. #endif
  150. #if defined(SCROLL)
  151. if (_ScrollType == 0) o.texcoord = float2(o.texcoord.x * _UV.x + _UV.z, o.texcoord.y * _UV.y + _UV.w);
  152. else if (_ScrollType == 1) o.texcoord += _Time.x * float2(_SpeedU, _SpeedV);
  153. #endif
  154. return o;
  155. }
  156. half4 frag(VaryingsParticle i) : SV_Target
  157. {
  158. half4 _col = half4(0, 0, 0, 0);
  159. #if defined (_INPUTBLEND_MUL)
  160. _col = i.color * _TintColor;
  161. #elif defined(_INPUTBLEND_ADD)
  162. _col = i.color + _TintColor;
  163. #endif
  164. if(_NiuQu == 1)
  165. {
  166. float2 _offset = SAMPLE_TEXTURE2D(_NoiseTex, sampler_NoiseTex, i.texcoord1).xy;
  167. _offset = (_offset - 0.5) * 2 * _DistortStrength;
  168. i.texcoord += _offset;
  169. }
  170. half4 mainTex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
  171. half4 col = MixParticleColor(mainTex, _col);
  172. #if defined(MASK)
  173. col.a *= SAMPLE_TEXTURE2D_X(_MaskTex, sampler_MaskTex, i.texcoordm).a;
  174. clip(col.a - _CutOff);
  175. #endif
  176. col *= _Up;
  177. if(_FogSwitch == 1) col.xyz = MixFog(col.xyz, i.fogFactor);
  178. col.a = pow(col.a, _AphaCorrect);
  179. return col;
  180. }
  181. ENDHLSL
  182. }
  183. }
  184. FallBack "Hidden/InternalErrorShader"
  185. //CustomEditor "ParticlesYXJShaderGUI"
  186. }