How does blend work?

I try to understand how blend works.

First, I wrote a shader, which paints material with red color.

Then, I added Blend One Zero instruction. According to manual, it should return color already present on screen + 0*(generated color) as output color.

I thought that “color already present on screen” refers to color of pixels hidden by the object and “generated color” to pixels of the object. Thus, the shader should draw picture hidden by the object and represent an invisible material.

I created a cube, assigned material with my shader to it and put the cube between a camera and a sprite. The result looks this way:

It doesn’t differ from Blend One One or completely disabled Blend.

Can you explain it?

Shader "Custom/Test"
{
	SubShader 
	{
        Pass 
        {
        	Blend One Zero
            CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            #pragma target 3.0

            #include "UnityCG.cginc"

            float4 vert(appdata_base v) : POSITION 
            {
                return mul (UNITY_MATRIX_MVP, v.vertex);
            }

            fixed4 frag(float4 sp:WPOS) : COLOR 
            {
                return fixed4(1,0,0,1);
            }

            ENDCG
        }
    }
	
}

You have the two factors confused. The first factor is the SrcFactor which the generated color is multiplied by. The second factor is the DstFactor which the color on the screen is multiplied by. Therefore the color displayed is 1*(generated color)+0*(color already present on screen) which is why it doesn’t differ from no blend. If you use Blend Zero One you will get the results you were looking for.

In addition, I tested Blend One One with a gray diffuse cube and and it works differently from no Blend statement. However you can’t tell the difference with just a black background since 1generated color+1Color(0, 0, 0)=generated color.

You need to make the object appear transparent to the engine, so it’s rendered later and ordered by depth from farthest to closest, that’s what queue and rendertype tags in shader are for. Then you can start experimenting with blendin, without being affected.