Wrong alpha blending in shader
Hi, i’m trying to achieve simple effect: given color of texture to be transparent. I wrote following shader for this:
Shader "alpha"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" { }
}
SubShader
{
Pass
{
Blend SrcAlpha OneMinusSrcAlpha // turn on alpha blending
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#include "UnityCG.cginc"
sampler2D _MainTex;
struct v2f {
V2F_POS_FOG;
float2 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.uv = TRANSFORM_UV(0);
return o;
}
half4 frag (v2f i) : COLOR
{
half4 texcol = tex2D( _MainTex, i.uv );
if (texcol.x == 1 texcol.z == 1) texcol.w = 0.0; // here i use (255,0,255) color as a mask
return texcol;
}
ENDCG
}
}
}
Unfortunately the results I’m getting are weird, instead of alpha blending I get artefacts on the screen (look screen shot).
Have I missed something?
P.S. I know all about TGA/PSD/ALpha channel and etc. In this example I need to make transparence by some color in picture (some kind of REAR Projection).