Skip to content

Instantly share code, notes, and snippets.

@pofulu
Last active March 26, 2019 10:37
Show Gist options
  • Save pofulu/39cac4aee75092722881a2a52e0935f1 to your computer and use it in GitHub Desktop.
Save pofulu/39cac4aee75092722881a2a52e0935f1 to your computer and use it in GitHub Desktop.
A simple crossfade unlit shader for Unity
// Origin: http://guidohenkel.com/2013/04/a-simple-cross-fade-shader-for-unity/
Shader "CrossFade"
{
Properties
{
_Blend("Blend", Range(0, 1)) = 0.5
_Color("Main Color", Color) = (1, 1, 1, 1)
_MainTex("Texture 1", 2D) = "white" {}
_Texture2("Texture 2", 2D) = ""
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 300
Pass
{
SetTexture[_MainTex]
SetTexture[_Texture2]
{
ConstantColor(0, 0, 0,[_Blend])
Combine texture Lerp(constant) previous
}
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Lighting.cginc"
sampler2D _Texture2;
float _Blend;
fixed4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
struct a2v
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD2;
};
v2f vert(a2v v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw;
return o;
}
fixed4 frag(v2f i) : SV_TARGET
{
fixed3 t1 = tex2D(_MainTex, i.uv).rgb * _Color.rgb;
fixed3 t2 = tex2D(_Texture2, i.uv).rgb * _Color.rgb;
fixed3 diffuse = lerp(t1, t2, _Blend).rgb;
return fixed4(diffuse , 1.0);
}
ENDCG
}
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment