Shader "BF/Effect/eff_air_distortion" { Properties { _NormalTex("法线贴图", 2D) = "white" {} _tex_uv_speed("贴图UV速度向量", Vector) = (0,0,0,0) [Toggle(_HIDE_Y)] _HIDE_Y("隐藏Y轴坐标0以下的部分", int) = 0 _DistortIntensity("扭曲强度", Range(0, 1)) = 1 [Toggle(_DISTORTION_DISAPPEAR_CUSTOM)]_DISTORTION_DISAPPEAR_CUSTOM("粒子custom1.x(uv1.z)控制扭曲消失",int) = 0 [Toggle(_USE_MASK)]_USE_MASK("使用贴图遮罩",int) = 0 _tex_mask("贴图遮罩", 2D) = "white" {} _tex_mask_uv_speed("贴图遮罩UV速度向量", Vector) = (0,0,0,0) } CGINCLUDE #include "UnityCG.cginc" struct a2v { float4 vertex : POSITION; float3 texcoord : TEXCOORD0; }; struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float4 uvgrab : TEXCOORD1; #if _USE_MASK float2 uv_mask : TEXCOORD2; #if _DISTORTION_DISAPPEAR_CUSTOM fixed disappear_custom : TEXCOORD3; #if _HIDE_Y fixed worldPosY : TEXCOORD4; #endif #else #if _HIDE_Y fixed worldPosY : TEXCOORD3; #endif #endif #else #if _DISTORTION_DISAPPEAR_CUSTOM fixed disappear_custom : TEXCOORD2; #if _HIDE_Y fixed worldPosY : TEXCOORD3; #endif #else #if _HIDE_Y fixed worldPosY : TEXCOORD2; #endif #endif #endif }; sampler2D _NormalTex; float4 _NormalTex_ST; sampler2D _GrabTex; float _DistortIntensity; float4 _tex_uv_speed; #if _USE_MASK sampler _tex_mask; float4 _tex_mask_ST; float4 _tex_mask_uv_speed; #endif v2f vert (a2v v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.texcoord, _NormalTex); o.uvgrab = ComputeGrabScreenPos(o.pos); #if _USE_MASK o.uv_mask = TRANSFORM_TEX(v.texcoord, _tex_mask); #endif #if _DISTORTION_DISAPPEAR_CUSTOM o.disappear_custom = v.texcoord.z; #endif #ifdef _HIDE_Y fixed3 worldPos = mul(unity_ObjectToWorld , v.vertex).xyz; o.worldPosY = worldPos.y; #endif return o; } fixed4 frag (v2f i) : SV_Target { fixed2 uv = i.uv + frac(_Time.y*_tex_uv_speed.xy); fixed3 bump = UnpackNormal(tex2D(_NormalTex, uv)); #if _USE_MASK fixed2 uv_mask = i.uv_mask + frac(_Time.y*_tex_mask_uv_speed.xy); const fixed3 tbl = float3(0.299,0.587,0.114); fixed4 mask = tex2D(_tex_mask,uv_mask); #if _DISTORTION_DISAPPEAR_CUSTOM fixed2 offset = bump * _DistortIntensity*dot(mask.rgb,tbl) * mask.a * i.disappear_custom; #else fixed2 offset = bump * _DistortIntensity*dot(mask.rgb,tbl) * mask.a; #endif #else #if _DISTORTION_DISAPPEAR_CUSTOM fixed2 offset = bump * _DistortIntensity * i.disappear_custom; #else fixed2 offset = bump * _DistortIntensity; #endif #endif // i.uvgrab.xy = (i.uvgrab.xy + offset) / i.uvgrab.w; fixed4 grabCol = tex2D(_GrabTex, i.uvgrab.xy); #ifdef _HIDE_Y fixed3 col = grabCol.rgb*step(0, i.worldPosY); #else fixed3 col = grabCol.rgb; #endif return fixed4(col, 0); } fixed4 fragBloom (v2f i) : SV_Target { fixed2 uv = i.uv + frac(_Time.y*_tex_uv_speed.xy); fixed3 bump = UnpackNormal(tex2D(_NormalTex, uv)); #if _USE_MASK fixed2 uv_mask = i.uv_mask + frac(_Time.y*_tex_mask_uv_speed.xy); const fixed3 tbl = float3(0.299,0.587,0.114); fixed4 mask = tex2D(_tex_mask,uv_mask); #if _DISTORTION_DISAPPEAR_CUSTOM fixed2 offset = bump * _DistortIntensity*dot(mask.rgb,tbl) * mask.a * i.disappear_custom; #else fixed2 offset = bump * _DistortIntensity*dot(mask.rgb,tbl) * mask.a; #endif #else #if _DISTORTION_DISAPPEAR_CUSTOM fixed2 offset = bump * _DistortIntensity * i.disappear_custom; #else fixed2 offset = bump * _DistortIntensity; #endif #endif // i.uvgrab.xy = (i.uvgrab.xy + offset) / i.uvgrab.w; fixed4 grabCol = tex2D(_GrabTex, i.uvgrab.xy); fixed alpha = grabCol.a; return fixed4(0, 0, 0, alpha); } ENDCG SubShader { Tags { "RenderType"="Transparent" "Queue"="Transparent" "IgnoreProjector"="True"} ZWrite Off Cull Off GrabPass{ "_GrabTex" } Pass { COLORMASK RGB Blend One Zero CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma shader_feature_local _USE_MASK #pragma shader_feature_local _DISTORTION_DISAPPEAR_CUSTOM #pragma shader_feature_local _HIDE_Y ENDCG } } CustomEditor "AirDistortionShaderGUI" }