Skip to content

Instantly share code, notes, and snippets.

@craigmjohnston
Created October 27, 2013 08:13
Show Gist options
  • Save craigmjohnston/7179065 to your computer and use it in GitHub Desktop.
Save craigmjohnston/7179065 to your computer and use it in GitHub Desktop.
Slight modification to the Texture Mask shader on the Unity3D wiki (http://wiki.unity3d.com/index.php?title=Texture_Mask). It multiplies the main texture's alpha channel with the mask's, so it preserves any transparency your main texture has.
Shader "MaskedTexture"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
SubShader
{
Tags {"Queue"="Transparent"}
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass
{
SetTexture [_Mask] {combine texture}
SetTexture [_MainTex] {combine texture, previous * texture}
}
}
}
@craigmjohnston
Copy link
Author

I wish github had shaderlab syntax highlighting :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment