我有一个 Metal 片段着色器,它返回一些带有 alpha 通道的透明颜色,我想在 MTKView 下显示一个 UIView,但我得到的唯一背景结果是黑色和“错误噪声”。
MTL渲染管道描述符:
pipelineStateDescriptor.isAlphaToCoverageEnabled = true
pipelineStateDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
pipelineStateDescriptor.colorAttachments[0].isBlendingEnabled = true
pipelineStateDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
pipelineStateDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
MTL渲染通道描述符:
renderPassDescriptor.colorAttachments[0].loadAction = .clear
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0)
如果我更改透明颜色,我可以在透明颜色下看到它,但如果我跳过透明颜色,我会看到“错误噪声”。清晰的颜色 Alpha 通道实际上有什么作用吗?
有谁知道如何使 MTKView 透明吗?
Update:
这是使 MTKView 透明的神奇属性:
self.isOpaque = false
If a UIView
可能有透明内容或无法用不透明绘图填充自身,那么它应该设置其opaque
(isOpaque
) 属性设置为 false,以便它将与其后面的任何内容正确组合。自从,MTKView
是一个子类UIView
,这也适用于它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)