123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- Shader "URP/Particles_YXJ"
- {
- Properties
- {
- [KeywordEnum(MUL, ADD)] _InputBlend("Input Blend", int) = 0
- _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
- [KeywordEnum(MUL, ADD, SUB, DIFF, COL)] _ColorBlend("Color Blend", int) = 0
- _MainTex ("Texture", 2D) = "white" {}
- [Toggle(MASK)] _MaskOn ("Enable Mask?", float) = 0
- _MaskTex ("Mask (A)", 2D) = "white" {}
- _CutOff ("Alpha CutOff", Range(0,1.0)) = 0.5
- [Toggle(SCROLL)] _ScrollOn ("Enable Scroll?", float) = 0
- [Enum(Manual, 0, AutoMain, 1, AutoMask, 2)] _ScrollType ("Scroll Type", float) = 0
- _UV ("UV Main", vector) = (1,1,0,0)
- _UV2 ("UV Mask", vector) = (1,1,0,0)
- _SpeedU ("Scroll Speed U", float) = 1
- _SpeedV ("Scroll Speed V", float) = 0
- _Up ("Up Level", float) = 1
- [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Src Blend Mode", float) = 5
- [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Dst Blend Mode", float) = 10
- [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest Mode", float) = 4
- [Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull Mode", Float) = 2
- [Enum(Close, 0, Open, 1)] _FogSwitch("Fog", float) = 0
- [Enum(Close, 0, Open, 1)] _NiuQu("Niu Qu", float) = 0
- _AphaCorrect("GammaApha", Range(1, 3)) = 1
- _DistortStrength("NQ Stength", Range(0,1)) = 0.5
- _DistortVelocity("NQ Veloctiy", Range(0,1)) = 0.5
- _NoiseTex("Noise Texture", 2D) = "white" {}
- _ColorMask("Color Mask", float) = 14
- }
- SubShader
- {
- Tags{"Queue"="Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" "PreviewType" = "Plane" "PerformanceChecks" = "False" "RenderPipeline" = "UniversalPipeline"}
-
- Pass
- {
- Name "YXJParticles"
- Blend[_SrcBlend][_DstBlend]
- Cull[_Cull]
- ZTest[_ZTest]
- ZWrite Off
- ColorMask [_ColorMask]
-
- HLSLPROGRAM
- #pragma prefer_hlslcc gles
- #pragma exclude_renderers d3d11_9x
- #pragma target 2.0
-
- #pragma vertex vert
- #pragma fragment frag
- #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- #pragma multi_compile_fog
- #pragma shader_feature _ MASK
- #pragma shader_feature _ SCROLL
- #pragma shader_feature _INPUTBLEND_MUL _INPUTBLEND_ADD
- #pragma shader_feature _COLORBLEND_MUL _COLORBLEND_ADD _COLORBLEND_SUB _COLORBLEND_DIFF _COLORBLEND_COL
- #pragma shader_feature _ GammaCorrect
- struct AttributesParticle
- {
- float4 vertex : POSITION;
- float4 color : COLOR;
- float2 texcoord : TEXCOORD0;
- #if defined(MASK)
- float2 texcoordm : TEXCOORD1;
- #endif
- };
- struct VaryingsParticle
- {
- float4 vertex : SV_POSITION;
- float4 color : COLOR;
- float fogFactor : TEXCOORD0;
- float2 texcoord : TEXCOORD1;
- float2 texcoord1 : TEXCOORD2;
- #if defined(MASK)
- float2 texcoordm : TEXCOORD3;
- #endif
- UNITY_VERTEX_OUTPUT_STEREO
- };
- TEXTURE2D(_MainTex);
- SAMPLER(sampler_MainTex);
- #if defined(MASK)
- TEXTURE2D(_MaskTex);
- SAMPLER(sampler_MaskTex);
- #endif
- TEXTURE2D(_NoiseTex);
- SAMPLER(sampler_NoiseTex);
- CBUFFER_START(UnityPerMaterial)
- float4 _TintColor;
- float4 _MainTex_ST;
- float4 _MaskTex_ST;
- float4 _NoiseTex_ST;
- float _CutOff;
- float _ScrollType;
- float4 _UV;
- float4 _UV2;
- float _SpeedU;
- float _SpeedV;
- float _FogSwitch;
- float _Up;
- float _NiuQu;
- float _DistortStrength;
- float _DistortVelocity;
- float _AphaCorrect;
- CBUFFER_END
- float4 MixParticleColor(float4 baseColor, float4 particleColor)
- {
- #if defined(_COLORBLEND_MUL)
- return baseColor * particleColor;
- #elif defined(_COLORBLEND_COL)
- half3 aHSL = RgbToHsv(baseColor.rgb);
- half3 bHSL = RgbToHsv(particleColor.rgb);
- half3 rHSL = half3(bHSL.x, bHSL.y, aHSL.z);
- return half4(HsvToRgb(rHSL), baseColor.a * particleColor.a);
- #else
- half4 colorAddSubDiff = half4(0, 0, 0, 0);
- #if defined(_COLORBLEND_ADD)
- colorAddSubDiff = half4(1.0, 0, 0, 0);
- #elif defined(_COLORBLEND_DIFF)
- colorAddSubDiff = half4(-1.0, 1.0, 0, 0);
- #elif defined(_COLORBLEND_SUB)
- colorAddSubDiff = half4(-1.0, 0, 0, 0);
- #endif
- float4 output = baseColor;
- output.rgb = baseColor.rgb + particleColor.rgb * colorAddSubDiff.x;
- output.rgb = lerp(output.rgb, abs(output.rgb), colorAddSubDiff.y);
- output.a *= particleColor.a;
- return output;
- #endif
- }
- VaryingsParticle vert(AttributesParticle v)
- {
- VaryingsParticle o = (VaryingsParticle)0;
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- float3 ws = TransformObjectToWorld(v.vertex.xyz);
- float4 cs = TransformWorldToHClip(ws);
- if(_FogSwitch == 1) o.fogFactor = ComputeFogFactor(cs.z);
- o.vertex = cs;
- o.color = v.color;
- o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
- if(_NiuQu == 1)
- {
- o.texcoord1 = TRANSFORM_TEX(v.texcoord, _NoiseTex);
- o.texcoord1 -= _Time.y * _DistortVelocity;
- }
- #if defined(MASK)
- o.texcoordm = TRANSFORM_TEX(v.texcoordm, _MaskTex);
- #if defined(SCROLL)
- if(_ScrollType == 0) o.texcoordm = float2(o.texcoordm.x * _UV2.x + _UV2.z, o.texcoordm.y * _UV2.y + _UV2.w);
- else if(_ScrollType == 2) o.texcoordm += _Time.x * float2(_SpeedU, _SpeedV);
- #endif
- #endif
- #if defined(SCROLL)
- if (_ScrollType == 0) o.texcoord = float2(o.texcoord.x * _UV.x + _UV.z, o.texcoord.y * _UV.y + _UV.w);
- else if (_ScrollType == 1) o.texcoord += _Time.x * float2(_SpeedU, _SpeedV);
- #endif
- return o;
- }
- half4 frag(VaryingsParticle i) : SV_Target
- {
- half4 _col = half4(0, 0, 0, 0);
- #if defined (_INPUTBLEND_MUL)
- _col = i.color * _TintColor;
- #elif defined(_INPUTBLEND_ADD)
- _col = i.color + _TintColor;
- #endif
-
- if(_NiuQu == 1)
- {
- float2 _offset = SAMPLE_TEXTURE2D(_NoiseTex, sampler_NoiseTex, i.texcoord1).xy;
- _offset = (_offset - 0.5) * 2 * _DistortStrength;
- i.texcoord += _offset;
- }
-
- half4 mainTex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
- half4 col = MixParticleColor(mainTex, _col);
- #if defined(MASK)
- col.a *= SAMPLE_TEXTURE2D_X(_MaskTex, sampler_MaskTex, i.texcoordm).a;
- clip(col.a - _CutOff);
- #endif
- col *= _Up;
- if(_FogSwitch == 1) col.xyz = MixFog(col.xyz, i.fogFactor);
- col.a = pow(col.a, _AphaCorrect);
- return col;
- }
- ENDHLSL
- }
- }
- FallBack "Hidden/InternalErrorShader"
-
- }
|