5

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.

Fattie
  • 27,874
  • 70
  • 431
  • 719
Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Looks correct to me. – AresCaelum Sep 27 '18 at 13:38
  • @Eddge Event the `SrcBlend = SRCALPHA;` which I used `Blend SrcAlpha One` on the Unity side? – Programmer Sep 27 '18 at 13:42
  • That is the hard part, my gut says that is correct but my head says that would instantly set the SrcAlpha to 1, which might not be what you want... however my head is also saying that with that line you are saying srcAlpha is multiplied by 1, rather then the inverse, or the oneMinus... – AresCaelum Sep 27 '18 at 13:47
  • I am looking at: https://docs.unity3d.com/Manual/SL-Blend.html specifically the Blend Factor section to try and resolve it in my head lol – AresCaelum Sep 27 '18 at 13:48
  • The OneMinusSrcAlpha is correct which is inverse (INVSRCALPHA) according to Unity's doc. I am not sure about the `SrcAlpha One` – Programmer Sep 27 '18 at 13:51
  • not sure if this is possible but it may just be `Blend SrcAlpha SrcAlpha` – AresCaelum Sep 27 '18 at 13:54
  • actually wouldnt it be `Blend SrcColor SrcAlpha` `Blend SrcAlpha SrcAlpha` `Blend DstColor OneMinusSrcAlpha` and `Blend DstAlpha OneMinusSrcAlpha` – AresCaelum Sep 27 '18 at 13:57
  • 1
    because if I remember correctly XNA tried to follow the same scheme as DirectX(or was HLSL), so SrcBlend would be the SrcColor, and DstBlend would be the DstColor. which would mean they possibly seperated the Alpha as well, so you might not need to do anything with Alpha but just Color. – AresCaelum Sep 27 '18 at 13:59
  • Thanks. I will give that a try and get back to you when I am on my computer. – Programmer Sep 27 '18 at 14:00
  • Alright, hopefully I will have a chance to experiment on my computer then as well. – AresCaelum Sep 27 '18 at 14:01
  • Was wondering if you ever figured this out. – AresCaelum Oct 05 '18 at 00:23
  • 1
    @Eddge Forgot about this question. I tried it and the output looked the-same as the one in my question. Although, that doesn't mean that what you said is not correct. – Programmer Oct 05 '18 at 02:33

1 Answers1

0

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.

Kalle Halvarsson
  • 1,240
  • 1
  • 7
  • 15