I have a question about blending. I have to planes. First one is a bit on the left and second is on the right and in front of the previous one but they still overlap. The plane on the left has Default Material(Standard Shader) and the one on the right has Material with my custom shader. My custom shader look like this:
Currently the Plane with my custom shaders covers the plane behind. With Blend Zero One command I expected that color of the plane in front would be multiplied with zero and added to the destination color so I should see the plane with default material. With Blend One Zero command I expected that the color of the overlapped section of the planes would be the same as color of the plane on the right(section which is not overlapped). Obviously I am wrong. Could someone explain to me how Blend Zero One/One Zero really works. Thanks for any help.
Blend One Zero is equivalent to no blend, the resulting math is (Src * One) + (Dst * Zero) or (shader output * 1.0) + (frame buffer * 0.0). Inversely Blend Zero One is equivalent to rendering nothing and just showing the background as the shader output is multiplied by zero and the frame buffer is multiplied by one.
Multiply would be Blend DstColor Zero, which means (shader output * frame buffer) + (frame buffer * zero).
However surface shaders will override your blend mode when you use the alpha keyword.
edit: You really want to be using a vertex / fragment shader for this instead of a surface shader. Surface shaders do a lot behind the scenes that you probably don’t want.
I removed alpha keyword from the shader and now it blends as I expected. I’ve added #pragma debug to my shader and looked at compiled code. There was a line Blend SrcAlpha OneMinusSrcAlpha although I put Blend One Zero to my shader. You were right about alpha keyword overriding my blend command. Thank You very much for help
Hi bgolus! I know this is an old thread, but I saw this thread when I search for “difference between Blend One Zero and Blend Off”. I know the result is the same, but I wonder is there any performance difference between “blend off” and “blend one zero”? Will “blend one zero” cause more calculation? Thank you!
At face value if it’s actually implemented as described by the spec, ie: Src * SrcFactor + Dst * DstFactor, then “Blend One Zero” whould be more expensive. However it’s unlikely most GPUs / graphics drivers actually do that and would likely fall back to “Blend Off” when presented with “Blend One Zero”.
But that doesn’t matter since Unity automatically has the logic to disable the blend when a shader is set to “Blend One Zero”, even if being set by shader properties.
So, no, there are no additional calculations. They are exactly the same in practice, at least for Unity.