Shader "YXZ/Effect/FlameSmoke" { Properties { [Toggle(_HASEXTENTDATA)] _ExtentData("使用脚本缩放 勾选后需要挂“GenFlameExtData”脚本,在编辑器下朝向会不准确,运行时才能朝向摄像机,同时继承缩放", float) = 0 [Toggle(_MOVEABLE)] _Moveable("可移动", float) = 0 [NoScaleOffset] _SmokeTex ("烟颜色和形状", 2D) = "black" {} _ChaosTex ("扰动纹理", 2D) = "white" {} _Scale("大小(x,y)(Transform.Scale必须为1)", Vector) = (1,1,1,1) _SmokeSpeed("烟的速度",range(0.1,30)) = 1 _ChaosScale("狂野度", range(0.0,5)) = 0.5 [KeywordEnum(TO_Z, TO_Y, TO_X)] _QuadFace("原始面片朝向", float) = 0 //[Space(20)] //[Toggle(_HUE)] _EnableHue("色调修改(比较费)", float) = 0 //_Hue("色调", range(-0.5, 0.5)) = 0 } SubShader { Tags { "RenderType"="Transparent" "Queue"="Transparent+63"} LOD 300 Pass // 1 { Name "SMOKE" Blend SrcAlpha OneMinusSrcAlpha Cull Off ZWrite Off CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_fog #pragma multi_compile __ _MOVEABLE #pragma multi_compile __ _HUE #pragma multi_compile __ _HASEXTENTDATA #pragma multi_compile _QUADFACE_TO_Z _QUADFACE_TO_Y _QUADFACE_TO_X #include "UnityCG.cginc" sampler2D _SmokeTex; sampler2D _ChaosTex; float4 _ChaosTex_ST; float _SmokeSpeed; float _ChaosScale; #ifdef _HUE float _Hue; #endif //#define _TEXNAME _SmokeTex #define _RAND_A 0.33 #define _RAND_B 0.51 #define BUILD_IN_QUAD_MESH #include "Flame.cginc" fixed4 frag (v2f i) : SV_Target { #ifdef _MOVEABLE fixed2 chaos = tex2D(_ChaosTex, i.uv1 - float2(0, frac(_Time.x * _SmokeSpeed))).yz; #else fixed2 chaos = tex2D(_ChaosTex, i.uv1 - float2(0, i.offset + frac(_Time.x * _SmokeSpeed))).yz; #endif chaos = (chaos - 0.5) * _ChaosScale * 0.2; fixed4 col = tex2D(_SmokeTex, (i.uv + chaos.xy)); //col.a *= 0.5; #ifdef _HUE half h, s, l; rgb2hsl(col, h, s, l); col.xyz = hsl2rgb(h + _Hue, s, l).xyz; #endif UNITY_APPLY_FOG(i.fogCoord, col); return col; } ENDCG } } }