Shader "Custom/maskedTransparentDiffuse"
{
Properties
{
_MaskColour("Mask Colour", Color) = (1.0, 1.0, 1.0, 1.0)//default is white
_MaskTexture("Mask Texture", 2D) = "" {}
_DiffuseTexture("Diffuse Texture", 2D) = "" {}
_OverlayTexture("Overlay Texture", 2D) = "" {}
}
SubShader
{
Tags
{
"Queue" = "Transparent"//render after opaque layers
}
Pass//first pass: mask layer
{
Blend SrcAlpha OneMinusSrcAlpha//alpha blending
Color[_MaskColour]//set 'primary' colour
SetTexture[_MaskTexture]
{
Combine texture * primary//apply texture * 'primary' colour
}
}
Pass//second pass: diffuse layer
{
Blend SrcAlpha OneMinusSrcAlpha//alpha blending
SetTexture[_DiffuseTexture]
{
Combine texture//apply texture
}
}
Pass//third pass: overlay layer
{
Blend SrcAlpha OneMinusSrcAlpha//alpha blending
SetTexture[_OverlayTexture]
{
Combine texture//apply texture
}
}
}
Fallback "Transparent/Diffuse"//if all else fails fallback to this shader
}
The shader takes 3 alpha transparent capable images and outputs them one after the other to produce the following:
The mask layer can then be coloured:
There are two problems I wish to resolve.
- If an image is not supplied to the overlay layer the output is darkened and semi transparent. To resolve this I currently supply a fully transparent image to the overlay layer as the layer is not always used, think of it as a decal layer.
- When an object using this shader is behind another object using this shader the foreground object doesn’t calculate the transparency as I’d like, hiding the background object essentially.
I know the solution will be cutting the shader over to CGPROGRAM use, I just need a little help doing so.



