Skip to content

Instantly share code, notes, and snippets.

@erikccoder
Last active August 29, 2015 14:22
Show Gist options
  • Save erikccoder/e6a8d9cc77e3eb096ed4 to your computer and use it in GitHub Desktop.
Save erikccoder/e6a8d9cc77e3eb096ed4 to your computer and use it in GitHub Desktop.
Unity3d alpha channel shader
Shader "Custom/VideoAlpha" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_AlphaOffsetX ("alpha offset x", float) = 0.5
_AlphaOffsetY ("alpha offset y", float) = 0
_Cutoff ("Cutoff", Range (0,1)) = .5
}
SubShader {
AlphaTest Less [_Cutoff]
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float _AlphaOffsetX;
float _AlphaOffsetY;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
IN.uv_MainTex.x += _AlphaOffsetX;
IN.uv_MainTex.y += _AlphaOffsetY;
half4 d = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = (d.r*-1)+1;
}
ENDCG
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment