////////////////////////////////////////////// /// 2DxFX v3 - by VETASOFT 2018 // ////////////////////////////////////////////// ////////////////////////////////////////////// Shader "2DxFX_Extra_Shaders/TurnFire" { Properties { [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {} _Fire_Displacement_Value("_Fire_Displacement_Value", Range(-0.3, 0.3)) = -0.026 _Fire_Addition_Value("_Fire_Addition_Value", Range(0, 4)) = 0.464 _SpriteFade("SpriteFade", Range(0, 1)) = 1.0 // required for UI.Mask [HideInInspector]_StencilComp("Stencil Comparison", Float) = 8 [HideInInspector]_Stencil("Stencil ID", Float) = 0 [HideInInspector]_StencilOp("Stencil Operation", Float) = 0 [HideInInspector]_StencilWriteMask("Stencil Write Mask", Float) = 255 [HideInInspector]_StencilReadMask("Stencil Read Mask", Float) = 255 [HideInInspector]_ColorMask("Color Mask", Float) = 15 } SubShader { Tags {"Queue" = "Transparent" "IgnoreProjector" = "true" "RenderType" = "Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" } ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off // required for UI.Mask Stencil { Ref [_Stencil] Comp [_StencilComp] Pass [_StencilOp] ReadMask [_StencilReadMask] WriteMask [_StencilWriteMask] } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc" struct appdata_t{ float4 vertex : POSITION; float4 color : COLOR; float2 texcoord : TEXCOORD0; }; struct v2f { float2 texcoord : TEXCOORD0; float4 vertex : SV_POSITION; float4 color : COLOR; }; sampler2D _MainTex; float _SpriteFade; float _Fire_Displacement_Value; float _Fire_Addition_Value; v2f vert(appdata_t IN) { v2f OUT; OUT.vertex = UnityObjectToClipPos(IN.vertex); OUT.texcoord = IN.texcoord; OUT.color = IN.color; return OUT; } float Generate_Fire_hash2D(float2 x) { return frac(sin(dot(x, float2(13.454, 7.405)))*12.3043); } float Generate_Fire_voronoi2D(float2 uv, float precision) { float2 fl = floor(uv); float2 fr = frac(uv); float res = 1.0; for (int j = -1; j <= 1; j++) { for (int i = -1; i <= 1; i++) { float2 p = float2(i, j); float h = Generate_Fire_hash2D(fl + p); float2 vp = p - fr + h; float d = dot(vp, vp); res += 1.0 / pow(d, 8.0); } } return pow(1.0 / res, precision); } float4 Generate_Fire(float2 uv, float posX, float posY, float precision, float smooth, float speed, float black) { uv += float2(posX, posY); float t = _Time*60*speed; float up0 = Generate_Fire_voronoi2D(uv * float2(6.0, 4.0) + float2(0, -t), precision); float up1 = 0.5 + Generate_Fire_voronoi2D(uv * float2(6.0, 4.0) + float2(42, -t ) + 30.0, precision); float finalMask = up0 * up1 + (1.0 - uv.y); finalMask += (1.0 - uv.y)* 0.5; finalMask *= 0.7 - abs(uv.x - 0.5); float4 result = smoothstep(smooth, 0.95, finalMask); result.a = saturate(result.a + black); return result; } float4 Color_PreGradients(float4 rgba, float4 a, float4 b, float4 c, float4 d, float offset, float fade, float speed) { float gray = (rgba.r + rgba.g + rgba.b) / 3; gray += offset+(speed*_Time*20); float4 result = a + b * cos(6.28318 * (c * gray + d)); result.a = rgba.a; result.rgb = lerp(rgba.rgb, result.rgb, fade); return result; } float2 SimpleDisplacementUV(float2 uv,float x, float y, float value) { return lerp(uv,uv+float2(x,y),value); } float4 frag (v2f i) : COLOR { float4 _Generate_Fire_1 = Generate_Fire(i.texcoord,0,0,0.041,0.634,1,0); float2 _Simple_Displacement_1 = SimpleDisplacementUV(i.texcoord,0,_Generate_Fire_1.g*_Generate_Fire_1.a,_Fire_Displacement_Value); float4 _MainTex_1 = tex2D(_MainTex,_Simple_Displacement_1); float4 _PremadeGradients_1 = Color_PreGradients(_Generate_Fire_1,float4(1,0,0.13,1),float4(0.42,0.95,0,1),float4(0.99,0.68,0.99,1),float4(0.39,0.39,1,1),-0.41,1,0); _MainTex_1 = lerp(_MainTex_1,_MainTex_1*_MainTex_1.a + _PremadeGradients_1*_PremadeGradients_1.a,_Fire_Addition_Value * _MainTex_1.a); float4 FinalResult = _MainTex_1; FinalResult.rgb *= i.color.rgb; FinalResult.a = FinalResult.a * _SpriteFade * i.color.a; FinalResult.rgb *= FinalResult.a; FinalResult.a = saturate(FinalResult.a); return FinalResult; } ENDCG } } Fallback "Sprites/Default" }