I'm trying to blend a source texture with some snowflakes in Metal, but I can't find blending options that work for my use case.
.
The blending options I'm currently using are:
descriptor.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
descriptor.sourceAlphaBlendFactor = MTLBlendFactorOne;
descriptor.destinationRGBBlendFactor = MTLBlendFactorOne;
descriptor.destinationAlphaBlendFactor = MTLBlendFactorOne;
I've tried these.
I expected the blue portion of the snowflakes to blend with the blue background, not with the underlying one.
Can anyone explain to me what I'm getting wrong, what the correct formula should be and how we arrive to it?
You code is missing something. I think you need an
addblend operation for bothrgbBlendOperationandalphaBlendOperation. If you just want to add a snowflake on top, I think the factors you have should be enough.If you take a look at https://developer.apple.com/documentation/metal/mtlblendoperation/add, it lists some formulas
where
SBFis source blend factor, andDBFis destination blend factor.So, basically, to expand in your case,
Seems like it should do the trick.