Advertisement
Guest User

Particle shader

a guest
Mar 17th, 2017
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Effect/fire" {
  2. Properties {
  3.     _OffsetTex ("Offset Tex", 2D) = "white" {}
  4.     _MainTex("Mask(A) ", 2D) = "white" {}
  5.    
  6.     _TxtrScale ("Texture scale", Range(0, 4)) = .125
  7.     _TxtrSpeed ("Texture speed", Range(-2, 2)) = .2
  8.    
  9.    
  10.     _Brightness ("Brightness", Range(0, 4)) = 1
  11.     _Flatten ("Flatten", Range(1, 10)) = 5.72
  12.     _Gamma ("Gamma", Range(0, 3)) = 1
  13.     _AlphaAdd ("Alpha affect", Range (0, 1)) = .612
  14.     _TxtrMult ("Texture multi", Range (0, 4)) = .5
  15.     _TxtrAdd ("Texture add", Range (-1, .01)) = -.192
  16. }
  17.  
  18. Category {
  19.     Tags { "Queue"="Transparent+3000" "RenderType"="Transparent" }
  20.     Blend SrcAlpha One
  21.     AlphaTest Greater .01
  22.     Cull Off Lighting Off ZWrite Off
  23.  
  24.     SubShader {
  25.         Pass {
  26.             Name "BASE"
  27.             Tags { "LightMode" = "Always" }
  28.            
  29.             CGPROGRAM
  30.             #pragma vertex vert
  31.             #pragma fragment frag
  32.             #pragma target 2.0
  33.             #pragma multi_compile_particles
  34.             #pragma multi_compile_fog
  35.             #include "UnityCG.cginc"
  36.  
  37.             struct appdata_t {
  38.                 float4 vertex : POSITION;
  39.                 fixed4 color : COLOR;
  40.                 float2 texcoord: TEXCOORD0;
  41.                 float4 random: TEXCOORD2;
  42.                 float4 center: TEXCOORD1;
  43.             };
  44.  
  45.             struct v2f {
  46.                 float4 vertex : POSITION;
  47.                 fixed4 color : COLOR;
  48.                 float2 uvmain : TEXCOORD0;
  49.                 float2 worldPosition: TEXCOORD1;
  50.                 float4 random: TEXCOORD3;
  51.                 float4 center: TEXCOORD4;
  52.             };
  53.  
  54.             float _Brightness;
  55.             float _Flatten;
  56.             float _Gamma;
  57.             float _TxtrMult;
  58.             float _TxtrAdd;
  59.             float _TxtrScale;
  60.             float _TxtrSpeed;
  61.  
  62.             half4 _DisplacementScrollSpeed;
  63.             half4 _Strength;
  64.             half4 _Params;
  65.             float _AlphaAdd;
  66.             float4 _OffsetTex_ST;
  67.             float4 _CellSize;
  68.             sampler2D _OffsetTex;
  69.             sampler2D _MainTex;
  70.  
  71.         v2f vert (appdata_t v)
  72.         {
  73.             v2f o;
  74.             o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  75.             o.uvmain = v.texcoord;//TRANSFORM_TEX(v.texcoord, _OffsetTex);
  76.             o.worldPosition = mul(UNITY_MATRIX_T_MV, v.vertex);
  77.             o.color = v.color;
  78.             o.center = v.center;// + _Time.yyyy*_DisplacementScrollSpeed.xyxy;
  79.             o.random = v.random;
  80.             return o;
  81.         }
  82.        
  83.        
  84.         float2 quant(float2 f, float2 q ){
  85.             return round(f/q)*q;
  86.         }
  87.        
  88.         float2 ttex(float2 tex, float4 st) {
  89.             return tex.xy * st.xy + st.zw;
  90.         }
  91.  
  92.         float2 rotate(float2 original, float angle ){
  93.             angle = angle * 0.01745329252;
  94.             float sinX = sin ( angle );
  95.             float cosX = cos ( angle );
  96.             float2x2 rotationMatrix = float2x2( cosX, -sinX, sinX, cosX);
  97.             return mul(original, rotationMatrix );
  98.         }
  99.  
  100.         half4 frag( v2f i ) : COLOR
  101.         {
  102.             half2 uv = i.uvmain;
  103.            
  104.             fixed4 txtr = tex2D(_MainTex, uv);
  105.            
  106.             uv = i.worldPosition * _TxtrScale
  107.                     - i.center * _TxtrSpeed
  108.                     + i.random.xy;
  109.            
  110.             fixed offset = tex2D(_OffsetTex, uv).r;
  111.                    
  112.             offset = saturate( offset + (i.color.a-1)*_AlphaAdd + _TxtrAdd);
  113.             float f = exp(_Flatten);
  114.             txtr = clamp(txtr.r * offset * _TxtrMult , 0, 1/f) * f * _Brightness;
  115.            
  116.             return pow( txtr * i.color, _Gamma);
  117.         }
  118.     ENDCG
  119.     }
  120. }
  121.         // ------------------------------------------------------------------
  122.         // Fallback
  123.         SubShader{
  124.             Blend DstColor Zero
  125.             Pass{
  126.             Name "BASE"
  127.             SetTexture[_MainTex]{ combine texture }
  128.             }
  129.         }
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement