I following along with Daniel_Brauer and AntonPetrov’s explanations here but I’ve not been able to figure out how to set ShaderLab commands DestBlend and SrcBlend.
It does sorta blend, but some colours aren’t quite right.
Here’s what I’m getting: And here’s what I’m hoping for:
Would someone please tell me where I’m going wrong?
When you’re blending two textures together within a shader, the DestBlend and SrcBlend aren’t important. That’s just for how the final output color of the shader gets blended with the target. If you want to replicate traditional alpha blending, that’d just be a basic lerp.
return lerp(texture1, texture2, texture2.a);
However the above will cause issues with the alpha. I’d probably do something like this instead:
However, to be honest, I’m not entirely sure what kind of blend you’re looking to do since the png images you posted above don’t have any alpha, and I’m not sure how you produced the “wanted” image. Presumably that was done in photoshop with some specific blend mode? Which one?
makes alpha cutout (which also can be deleted, blending in “then” already exist), then makes Normal blending
also you use “+ texture2.rgb” which assumes your texture2.rgb is already in premultiplied-alpha mode (otherwise you need to change formula to “+ texture2.rgb * texture2.a”)
as a common alpha-blending equation with alpha premultiplied in fragment.rgb:
output = background.rgb * (1 - fragment.a) + fragment.rgb;
this another blending is related to destination-final-step to allow chain-blend of (tex3 over (tex2 over tex1)) etc, where your original shader contains only tex1, tex2
BlendOp Add
Blend One OneMinusSrcAlpha
original case from https://forum.unity.com/threads/wha…-two-transparent-textures-in-a-shader.169313/
was
“I need to blend three transparent textures in one shader to be drawn in one call,”
it is important - by one call… due to this, the solution is in-code-blend formula like
fragment.a = (1 - (1 - texture1.a) * (1 - texture2.a));
or tex3, tex2, tex1 formula from it
if you don’t have case “in one call” (imho you don’t need)
then you can achieve desired effect only by simple blend
delete in-code blending
(with premult in original texture, which is important to order-independent-blend-to-background, otherwise you should change blend in it to Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha)