Porting XNA Shader pass, blend and cull mode into Unity shaderlab

241 views Asked by At

I had to port XNA shader into Unity's shader and want to verify that I did this correctly.

The Pass1 section that uses alpha blending like SrcBlend, DestBlend and set's cull to none is the only place I want to make sure I got right.

This is the XNA shader version:

pass Pass1
{
    AlphaBlendEnable = true;
    SrcBlend = SRCALPHA;
    DestBlend = INVSRCALPHA;
    CullMode = None;

    VertexShader = compile vs_2_0 TheVertexShader();
    PixelShader = compile ps_2_0 ThePixelShader();
}

This is the Unity Shaderlab port I made:

Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 100
Blend SrcAlpha One
Blend DstAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off 

It seems to be working fine in Unity but is this the exactly the equivalent pass settings in Unity? If not, then what changes is requred to get the exact equivalency.

1

There are 1 answers

0
Kalle Halvarsson On

You should only put the "Blend" keyword once: the two keywords after it are the blend factors used for the source and destination respectively. You can think of it as being on the format "Blend [SrcBlend] [DstBlend]".

Here is the correct blending:

Blend SrcAlpha OneMinusSrcAlpha

This results in basic alpha blending.