Advertisement
Guest User

FXFire.shader

a guest
Feb 15th, 2018
14,823
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 1 0
  1. Shader "FX/Fire Distort"
  2. {
  3. Properties
  4. {
  5. _ColorA("Main Color A", Color) = (1,1,1) //gradient colors
  6. _ColorB("Main Color B", Color) = (1,1,1)
  7. _TintA("Edge Color A", Color) = (1,1,1)
  8. _TintB("Edge Color B", Color) = (1,1,1)
  9. _ScrollX(" Scroll Noise X", Range(-10,10)) = 1 // noise animation
  10. _ScrollY(" Scroll Noise Y", Range(-10,10)) = 1
  11. _NoiseTex("Noise Texture", 2D) = "white" {}
  12. _DistortTex(" UVDistort Texture", 2D) = "white" {}
  13. _Offset("Offset Gradient A/B", Range(-2,2)) = 1
  14. _Hard("Hard Cutoff", Range(1,40)) = 30
  15. _Height("Height", Range(-4,10)) = 1
  16. _Edge("Edge", Range(0,2)) = 1
  17. _Distort("Distort", Range(0,1)) = 0.2
  18. [MaterialToggle] SHAPE("Use Mask Texture", Float) = 0
  19. [MaterialToggle] SHAPEX("Mulitply Noise", Float) = 0
  20. _ShapeTex("Mask", 2D) = "white" {}
  21.  
  22. }
  23. SubShader
  24. {
  25. Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
  26. LOD 100
  27. Zwrite Off
  28. Blend One One // additive blending
  29.  
  30. Pass
  31. {
  32. CGPROGRAM
  33. #pragma vertex vert
  34. #pragma fragment frag
  35. #pragma multi_compile _ SHAPE_ON
  36. #pragma multi_compile _ SHAPEX_ON
  37. // make fog work
  38. #pragma multi_compile_fog
  39.  
  40. #include "UnityCG.cginc"
  41.  
  42. struct appdata
  43. {
  44. float4 vertex : POSITION;
  45. float2 uv : TEXCOORD0;
  46. };
  47.  
  48. struct v2f
  49. {
  50. float2 uv : TEXCOORD1;
  51. float2 uv2 : TEXCOORD2;
  52. float2 uv3 : TEXCOORD4;
  53. UNITY_FOG_COORDS(3)
  54. float4 vertex : SV_POSITION;
  55. };
  56.  
  57. sampler2D _NoiseTex, _ShapeTex, _DistortTex;
  58. float4 _DistortTex_ST, _ShapeTex_ST, _NoiseTex_ST;
  59. float4 _ColorA, _ColorB, _TintA, _TintB;
  60. float _Offset, _ScrollX, _ScrollY;
  61. float _Height, _Edge, _Distort, _Hard;
  62. v2f vert(appdata v)
  63. {
  64. v2f o;
  65. o.vertex = UnityObjectToClipPos(v.vertex);
  66. o.uv = TRANSFORM_TEX(v.uv, _NoiseTex); // -enable scaling and offset
  67. o.uv2 = TRANSFORM_TEX(v.uv, _ShapeTex); // for the textures
  68. o.uv3 = TRANSFORM_TEX(v.uv, _DistortTex); // we are using-
  69. UNITY_TRANSFER_FOG(o,o.vertex);
  70. return o;
  71. }
  72.  
  73. fixed4 frag(v2f i) : SV_Target
  74. {
  75. float4 gradientMain = lerp(_ColorB, _ColorA, (i.uv3.y + _Offset)); // gradient for color
  76. float4 gradientTint = lerp(_TintB, _TintA, (i.uv3.y + _Offset)); // gradient for color
  77. float4 gradientBlend = lerp(float4(2,2,2,2), float4(0, 0, 0, 0), (i.uv3.y + _Height)); // gradient to fade to top
  78.  
  79. fixed4 uvdistort = tex2D(_DistortTex, i.uv3) * _Distort; // distort texture times distort amount
  80. fixed4 noise = tex2D(_NoiseTex,fixed2((i.uv.x + _Time.x* _ScrollX) + uvdistort.g ,(i.uv.y + _Time.x* _ScrollY) + uvdistort.r)); //noise texture with distortion
  81. fixed4 shapetex = tex2D(_ShapeTex, i.uv2); // mask texture
  82.  
  83.  
  84. #ifdef SHAPE_ON
  85. noise = 1 - (noise * _Height + (1 - (shapetex * _Hard)));// use the shape mask
  86. #else
  87. noise += gradientBlend;// fade the flame at the top
  88. #endif
  89. #ifdef SHAPEX_ON
  90. noise += gradientBlend;// fade the flame at the top over mask
  91. #endif
  92. float4 flame = saturate(noise.a * _Hard); //noise flame
  93. float4 flamecolored =flame *gradientMain; // coloured noise flame
  94. float4 flamerim = saturate((noise.a + _Edge) * _Hard) - flame; // noise flame edge
  95.  
  96. float4 flamecolored2 = flamerim * gradientTint; // coloured flame edge
  97. float4 finalcolor = flamecolored + flamecolored2; // combined edge and flames
  98. return finalcolor;
  99.  
  100.  
  101. }
  102. ENDCG
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement