Shader "Particles/PPOffset"
{
Properties
{
_MainTex ("Maks1", 2D) = "white" {}
_GradientA("GradientA", Color) = (0, 0, 0, 1)
_GradientB("GradientB", Color) = (0, 0, 0, 1)
[Enum(One,1,SrcAlpha,5)] _SrcBlend ("SrcBlend", Float) = 1
[Enum(OneMinusSrcAlpha,10,DstAlpha,7)] _DstBlend ("DstBlend", Float) = 7
_AmountX ("AmountX", Float) = 0
_AmountY ("AmountY", Float) = 0
_PanSpeed ("PanSpeed", Float) = 0
}
SubShader
{
//Transparent
Tags
{
"Queue" = "Transparent"
"IgnoreProjectors" = "True"
"RenderType" = "Transparent"
}
Lighting Off
ZWrite Off
Cull Off
Blend [_SrcBlend] [_DstBlend]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
//Init shader parameters
//Textures
sampler2D _MainTex;
float4 _MainTex_ST;
//Colors
half4 _GradientA;
half4 _GradientB;
//Other
float _AmountX;
float _AmountY;
float _PanSpeed;
struct appdata
{
float4 vertex : POSITION;
float2 uv0 : TEXCOORD0;
float4 color : COLOR;
};
struct v2f
{
float4 color : COLOR;
float2 uv0 : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
//Get Random UV offset from vertex color.
//This is set per particle in the script.
_MainTex_ST.z += v.color.b;
_MainTex_ST.w += v.color.a;
//Pan UV coordinates based on _Amount and _PanSpeed.
_MainTex_ST.z += (_Time.y * _AmountX) * _PanSpeed;
_MainTex_ST.w += (_Time.y * _AmountY) * _PanSpeed;
//Transform UV coordinates with the input of _MainTex (Tiling / Offset).
o.uv0.xy = TRANSFORM_TEX(v.uv0, _MainTex);
o.color = v.color;
return o;
}
float4 frag (v2f i) : COLOR
{
// sample the texture
fixed4 tex = tex2D(_MainTex, i.uv0);
//Color over Lifetime lerp based on per particle vertex color.
//Currently supports only 2 colors at positions 0 and 1.
half4 lerpS = lerp(_GradientA, _GradientB, i.color.r);
return half4(lerpS * tex);
}
ENDCG
}
}
}