Alpha Test with Alpha Blend?

Is it possible to have two passes in a Surface Shader, one to alpha test and then one to alpha blend and soften edges?

Thanks
Justin

Yes, there’s a sample one in the docs “Vegetation”:

No.

It is possible. It’s how I do my character’s hair.

Here’s a stripped down version using Lambert.

The first surface shader does the “solid” interior bit, the second does the soft edge exterior.

Shader "Custom/Surface Shader Soft Edge" {
	Properties {
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "gray" {}
		_Cutoff ("Alpha Cut-Off Threshold", Range(0,1)) = 0.5
	}

	SubShader {
		Tags { "RenderType" = "TransparentCutout" }

		CGPROGRAM
			#pragma surface surf Lambert

			struct Input
			{
				float2 uv_MainTex;
			};
			
			sampler2D _MainTex;
			float _Cutoff;
				
			void surf (Input IN, inout SurfaceOutput o)
			{
				float4 albedo = tex2D(_MainTex, IN.uv_MainTex);
				clip(albedo.a - _Cutoff);
				
				o.Albedo = albedo.rgb;
				o.Alpha = albedo.a;
			}
		ENDCG

		ZWrite Off

		CGPROGRAM
			#pragma surface surf Lambert

			struct Input
			{
				float2 uv_MainTex;
			};
			
			sampler2D _MainTex;
			float _Cutoff;
				
			void surf (Input IN, inout SurfaceOutput o)
			{
				float4 albedo = tex2D(_MainTex, IN.uv_MainTex);
				clip(-(albedo.a - _Cutoff));
				
				o.Albedo = albedo.rgb;
				o.Alpha = albedo.a;
			}
		ENDCG
	}
	FallBack "Transparent/Cutout/VertexLit"
}

Ah, sorry - missed the “surface shader” somehow. Still, really simple to do as farfarer shows (though I wouldn’t clip the second pass)

You clip the second pass so you don’t draw the same pixels again - they’ve already been drawn in the first pass. Clip as early as possible in the shader.

Ah - really cool! I missed the negative at the beginning. I haven’t done that before, but make perfect sense!

Thanks for all the great replies. They were very helpful. I actually had my shader set up very much like Farfarer suggested and I’m still not quite achieving the results I was hoping for.

1203792--48437--$test.jpg

On the left is what I see in the Editor which is exactly what I want. On the right is in-game. Its somewhat hard to see but it is still alpha testing for the most part without showing any of the 2nd pass alpha blend.

Here is the code, maybe I’m just missing something simple:

Shader "Soft-Edge Testing" {
	Properties {
		_Color ("DOES NOTHING", Color) = (1,1,1,1)
		_Highlight ("Highlight Color", Color) = (.5,.5,.5,1)
	    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
	    _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
	}
	SubShader {
		Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout" }    
	           
	    CGPROGRAM
	    #pragma only_renderers d3d9
	    #pragma surface surf Lambert noambient nolightmap nodirlightmap novertexlights noforwardadd
	    
	    struct Input {
	        float2 uv_MainTex;
	        float4 color : COLOR; // vertexcolor
	    };		
								
		fixed4 _Highlight;
		sampler2D _MainTex;
		half _Cutoff;
		fixed4 _Color;
		
		void surf (Input IN, inout SurfaceOutput o) {
			_Color = (0.5,0.5,0.5,1);
			fixed4 colorMap = tex2D (_MainTex, IN.uv_MainTex);
			o.Albedo = colorMap.rgb * IN.color.a * _Highlight;
			o.Emission = colorMap.rgb * IN.color.a * IN.color.rgb + (_Highlight - 0.5);
			clip(colorMap.a - _Cutoff);
	 	    o.Alpha = 0.0;
		}
	    ENDCG
	    
	    ZWrite Off
		Blend SrcAlpha OneMinusSrcAlpha
	
		Tags { "IgnoreProjector"="True" }
		
		CGPROGRAM
	    #pragma surface surf Lambert noambient nolightmap nodirlightmap novertexlights noforwardadd alpha
	    
		struct Input {
	        float2 uv_MainTex;
	        float4 color : COLOR; // vertexcolor
	    };		
								
		fixed4 _Highlight;
		sampler2D _MainTex;
		half _Cutoff;
		fixed4 _Color;
	
	    void surf (Input IN, inout SurfaceOutput o) {
			_Color = (0.5,0.5,0.5,1);
			fixed4 colorMap = tex2D (_MainTex, IN.uv_MainTex);
			o.Albedo = colorMap.rgb * IN.color.a * _Highlight;
			o.Emission = colorMap.rgb * IN.color.a * IN.color.rgb + (_Highlight - 0.5);
			clip(-(colorMap.a - _Cutoff));
			o.Alpha = colorMap.a;
			}
	    ENDCG
	}
    Fallback "Transparent/Cutout/Diffuse"
}

Any suggestions? Thanks again.

The blended fragments do not write into the ZBuffer so they get overwritten by the skybox which is rendered after solid geometry.
The chosen queue fits only for the AlphaTest part of your shader, the AlphaBlend part should go into queue “Transparent”. You could try to assign the shader to a queue like “Transparent-100”. The standard TreeCreatorLeaves shader uses “Transparent-99” while also writing Z…

Tried messing with all sorts of variations on the queue…still same problem. Guess it may not be possible.

Strange. I gave it a try and setting the RenderQueue to “Transparent-100” did indeed work for me.
Are there other specialities in your setup like shadows, deferred rendering, etc? Do you use the standard Skybox component?