透明混合

unity着色器书写时,如果想使用透明效果,需要使用混合(Blend).并需要指定Tags.
插入在SubShader中,与Pass同级.
如下:
Tags { "Queue" = "Transparent" } 
Blend SrcAlpha DstAlpha

完整的shader参考:
Shader "Level4/alpha1"{
	Properties{
		_MainTex("base rgb",2d) = ""{}
		_alpha("alpha",range(0,1)) = 0.5
	}
	
	CGINCLUDE
	#include "UnityCG.cginc"
	sampler2D _MainTex;
	float _alpha;
	
	struct v2f{
		float4 pos:POSITION;
		float2 uv:TEXCOORD;
	};
	v2f vert(appdata_full v):POSITION{
		v2f o;
		o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
		o.uv = v.texcoord.xy;
		return o;
	}
	float4 frag(v2f v):COLOR{
		float4 texColor = tex2D(_MainTex,v.uv);
		texColor.a = _alpha;
		return texColor;
	}
	
	ENDCG
	
	SubShader{
		 Tags { "Queue" = "Transparent" } 
		 // ZWrite Off
		 Blend SrcAlpha DstAlpha
		Pass{
			CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
			ENDCG
		}
	}
}

你可能感兴趣的:(unity,shader)