Unlit Texture Transparent Shader

I would like to have a unlit texture shader with transparency. The shader here works, but doesn’t have z-write, so it doesn’t render in front of objects. Basically, i need the Unity’s built-in Unlit/Transparent shader’s code. Does anybody have the source?

You can find builtin shaders here.

// Unlit alpha-blended shader.
// - no lighting
// - no lightmap support
// - no per-material color

Shader "Unlit/Transparent" {
Properties {
	_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}

SubShader {
	Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
	LOD 100
	
	ZWrite Off
	Blend SrcAlpha OneMinusSrcAlpha 
	
	Pass {  
		CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_fog
			
			#include "UnityCG.cginc"

			struct appdata_t {
				float4 vertex : POSITION;
				float2 texcoord : TEXCOORD0;
			};

			struct v2f {
				float4 vertex : SV_POSITION;
				half2 texcoord : TEXCOORD0;
				UNITY_FOG_COORDS(1)
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			
			v2f vert (appdata_t v)
			{
				v2f o;
				o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
				o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
				UNITY_TRANSFER_FOG(o,o.vertex);
				return o;
			}
			
			fixed4 frag (v2f i) : SV_Target
			{
				fixed4 col = tex2D(_MainTex, i.texcoord);
				UNITY_APPLY_FOG(i.fogCoord, col);
				return col;
			}
		ENDCG
	}
}

}

[73623-builtin-shaders-534f1.zip|73623]

For the most part, transparency typically works because z-writing is off for them.

When the 3D environment is processed and sent to the screen, Unity wants the video card wants to do as little as it needs to. When you have opaque shaders, you’ll only draw the pixel at the very front, closest to the camera, unobstructed by any other pixel.

When using transparency, you’re simply telling Unity not to discard a pixel and not draw it when there’s another pixel to draw in front of it. This means that pixel takes two passes of varying complexity (two different shaders to process) to draw, rather than only one pass for that front-most pixel.

That said, some game engines try to improve efficiency by disallowing endless layering of transparent shaders, so it’s not unusual for only the transparent shader in front to be allowed to be drawn. There are workarounds for that (usually related to foliage shaders), but I haven’t gotten around to researching that much yet since some of the Unity 5 changes to shaders have deprecated older approaches to transparency sorting.