Re: Metal AlphaBlending in FxPlug
Re: Metal AlphaBlending in FxPlug
- Subject: Re: Metal AlphaBlending in FxPlug
- From: Darrin Cardani via Pro-apps-dev <email@hidden>
- Date: Thu, 02 Apr 2020 11:10:33 -0700
If you want to send me an example, I can take a look at it. You can just modify
FxShape and send that, if you want. What you’ve written below seems like it
should work, but I find it easy to miss things with both Metal and OpenGL.
Darrin
> On Apr 2, 2020, at 10:03 AM, Bret Battey via Pro-apps-dev
> <email@hidden> wrote:
>
> Thanks for that very fast response on question 1!
>
> So now for question 2:
>
> I am converting a plugin to Metal that used alpha blending to layer and mix
> OpenGL points (tells you how behind I am).
>
> I am using the FxShape example as my core model to work from. I have adapted
> the circle draw to take position and RGBA color arguments, have implemented
> MSAA, and now am trying to get alpha blending of overlapped circles to work.
> Piecing together examples from online, it seems like it should be
> (relatively) straightforward. However, I am just getting solid colors, no
> blends.
>
> So am wondering if there might be something odd about doing this in the
> Motion context that I am overlooking. I have noted that some errors in online
> examples have been solved by changing texture types or in one case having to
> a CAMetalLayer ‘opaque’property to false, but it is not clear to me if/how
> any of that would apply within an FxPlug.
>
> In FxMTLDeviceCache, I add code to the Shape Pipeline State descriptor to
> enable blending and set blending options, taking into account that Motion is
> premultiplied alpha:
>
> pipelineStateDescriptor.colorAttachments[0].blendingEnabled = TRUE;
> pipelineStateDescriptor.colorAttachments[0].sourceRGBBlendFactor =
> MTLBlendFactorOne;
> pipelineStateDescriptor.colorAttachments[0].destinationRGBBlendFactor =
> MTLBlendFactorOneMinusSourceAlpha;
> pipelineStateDescriptor.colorAttachments[0].rgbBlendOperation =
> MTLBlendOperationAdd;
> pipelineStateDescriptor.colorAttachments[0].sourceAlphaBlendFactor =
> MTLBlendFactorOne;
> pipelineStateDescriptor.colorAttachments[0].destinationAlphaBlendFactor =
> MTLBlendFactorOneMinusSourceAlpha;
> pipelineStateDescriptor.colorAttachments[0].alphaBlendOperation =
> MTLBlendOperationAdd;
>
> As far as I understand, that should be enough – that there is no need to
> alter the fragment shader. All the fragment shader needs to do is return the
> appropriate color, including its alpha value, and Metal should take care of
> the blending… Of course, I could have this desperately wrong, as well 😉
>
> Thanks,
> -=Bret
>
>
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Pro-apps-dev mailing list (email@hidden
> <mailto:email@hidden>)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden <mailto:email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Pro-apps-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden