Skip to content

Instantly share code, notes, and snippets.

@jimfleming
Created May 8, 2013 02:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimfleming/ad643ef3aca7d0e8a743 to your computer and use it in GitHub Desktop.
Save jimfleming/ad643ef3aca7d0e8a743 to your computer and use it in GitHub Desktop.
Simple diffuse/dissolve shader.
Shader "Custom/DiffuseDissolve" {
Properties {
_DissolveTime ("Dissolve Time", Range (-1, 1)) = -1
_DissolveGuide ("Dissolve Guide (RGB)", 2D) = "white" {}
_MainTex ("Texture 1", 2D) = "white" {}
_Texture2 ("Texture 2", 2D) = "black" {}
}
SubShader {
Tags {
"RenderType" = "Opaque"
}
LOD 200 // equiv: Diffuse
CGPROGRAM
#pragma surface surf Lambert addshadow dualforward
struct Input {
float2 uv_MainTex;
float2 uv_DissolveGuide;
};
// NOTE: Using _MainTex so the property names line up in fallback case
sampler2D _MainTex;
sampler2D _Texture2;
sampler2D _DissolveGuide;
float _DissolveTime;
void surf(Input IN, inout SurfaceOutput o) {
fixed3 _MainTexColor = tex2D(_MainTex, IN.uv_MainTex).rgb;
fixed3 _Texture2Color = tex2D(_Texture2, IN.uv_MainTex).rgb;
fixed _DissolveAmount = tex2D(_DissolveGuide, IN.uv_MainTex).a;
float _DissolveAmountByTime = clamp(_DissolveAmount + _DissolveTime, 0, 1);
o.Albedo = lerp(_MainTexColor, _Texture2Color, _DissolveAmountByTime);
}
ENDCG
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment