Transparent Cutout Shader?

I’ve been trying to make a circular health bar. Now, there’s a tutorial out there that uses the cutout shader to create one.

My problem is: The health bar is supposed to be semi transparent.

So I looked for addon shaders because as far as I can see, there’s no solution to that built in to Unity - needless to say, I didn’t find any.

I tried writing my own, using the script reference to manage, sadly this one only works on straight bars (also, only really badly since its my first…)

So, my question is really: Can this shader somehow be salvaged to work in a circular manner? Or, even better, does anyone know a Shader with a Transparent Base Texture that also allows a seperate texture for cutouts?

Shader "Transparent/Bar" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
	_Fill ("Fill Percentage", Range(-1.0,1.0)) = 0.5
	_BarSz ("Bar Size", Float) = 3.0
}

SubShader {
	Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
	LOD 200
	Cull Off

CGPROGRAM
#pragma surface surf Lambert alpha

sampler2D _MainTex;
fixed4 _Color;
float _Fill;
float _BarSz;

struct Input {
	float2 uv_MainTex;
	float3 worldPos;
};

void surf (Input IN, inout SurfaceOutput o) {
	float p = _BarSz * _Fill;
	clip(IN.worldPos.x + p);
	fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
	o.Albedo = c.rgb;
	o.Alpha = c.a;
}
ENDCG
}

Fallback "Transparent/VertexLit"
}

Thanks in advance!

For Everyone else looking for a solution; Here it is!

Shader "Transparent/Cutout/Transparent" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
	_CutTex ("Cutout (A)", 2D) = "white" {}
	_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}

SubShader {
	Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
	LOD 200

CGPROGRAM
#pragma surface surf Lambert alpha

sampler2D _MainTex;
sampler2D _CutTex;
fixed4 _Color;
float _Cutoff;

struct Input {
	float2 uv_MainTex;
};

void surf (Input IN, inout SurfaceOutput o) {
	fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
	float ca = tex2D(_CutTex, IN.uv_MainTex).a;
	o.Albedo = c.rgb;
	
	if (ca > _Cutoff)
	  o.Alpha = c.a;
	else
	  o.Alpha = 0;
}
ENDCG
}

Fallback "Transparent/VertexLit"
}

I bumped into this and figured I should suggest this optimization:

if (ca > _Cutoff)
           o.Alpha = c.a;
else
           o.Alpha = 0;

Can be:

o.Alpha = min(ca <= _Cutoff, c.a);

You might be able to assume unity would do this optimization on its own but you’d have to check the compiled shader to figure that out.