Metal AlphaBlending in FxPlug
Metal AlphaBlending in FxPlug
- Subject: Metal AlphaBlending in FxPlug
- From: Bret Battey via Pro-apps-dev <email@hidden>
- Date: Thu, 2 Apr 2020 17:03:24 +0000
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=dmu.ac.uk; dmarc=pass action=none header.from=dmu.ac.uk; dkim=pass header.d=dmu.ac.uk; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=idcAsZ6i2taDrDq14GTW17x6KugjIQQmb7VYL8WAfUQ=; b=QWVs6WjisT8sJNQlsouWPE+IChSctWjWHhWwK9QPHUUnM39kGDe5FmFqg0QfCfcD/7hiC2jRZk/aYay60Y4sM8PtI3a8fe8ye606gLLd33hns1/VANDdm5bzYRAUFlr9kgx76Hnw+TmOqi1Ms8rmlppINw6zG97snDm5i/suf+Ya36aQFRywuYGG0nqB9M8I7icz8r21qO+l46RsKV2X8sYXMO/DRiirHVzhZlBqh48Dd2b0lRqhtJ8GgD0ckXR9smdwafvGCGYqrNjEFXvpz+oyes8FjMC88PhU0RRATts1AxEedk8P81GJNPA/GXuwK0m8aYRsrBpIJ4ZJn+NV7g==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VqdxdxBuHXUyfFsJu9AgbWZRaT065Kly+5EfOMf4Ks09az8bIgwbbyCtr3/d3OpsI0Wvg5+v1l0/tudpF8co4w/s7w6IwZPnj9o48R9ZKk3vLh/5jUwts5G1bYnFRWEPd6Oz0uei2Z2WXtPth9Ee2FDqEpT4WTFatXeKJr9d5jaa+RZmEi0dR0iHUB55zO6nmYBaxdGG5V0JY+kNJSnW/H3LVTdvTr55ypGok/Tg+tDSPMFIhQ8DjPKMVnwRc98VlB8/WZEO0ZF8i0Dj4Ix4E/rXvcZSMeFI0ZcTaRpgq65lxjLExJ922Q5OchohRFRJT0VpovLAm7TfQ+PrnUBXPw==
- Thread-topic: Metal AlphaBlending in FxPlug
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)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden