ios - 以相同的 Alpha 混合 Metal

标签 ios swift metal metalkit

我正在画三个正方形,如图所示 enter image description here

我正在添加 alpha 0.2 的红色。

在重叠区域中,我也希望这些区域的 alpha 为 0.2。现在它以 0.6 的形式出现。我该怎么做建议。目前我的管道描述符是

 pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
 pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
 pipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
 pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .one
 pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
 pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
 pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha

我需要在管道描述符或着色器中执行吗?

最佳答案

如果您希望最终结果具有与您正在绘制的相同的 alpha,您需要将它们设置为:

 pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
 pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .zero

这意味着最终的 alpha 将没有来自您正在渲染的目标的贡献。

关于ios - 以相同的 Alpha 混合 Metal ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51739101/

相关文章:

ios - 将 NSData 转换为 NSDictionary

ios - Bitbucket 无法识别我的 Swift 项目

ios - Metal 。为什么将 MTLCullMode 设置为 none 会关闭深度比较?

swift - 启用混合导致 renderPipelineState 无法在 MetalKit MTKView 中构建

ios - 在 Storyboard 中使用 Material 样式时,iOS 13.0 之前的系统模糊样式警告

ios - 将字节数组代码从 c 转换为 swift

swift - 设置自定义 UINavigationBar 的 titleView

iOS Metal : The fastest way to read read-only data?

ios - 从CloudKit删除记录时如何防止孤儿?

swift - 如何公开此 OptionSetType 结构?