我有一个 Metal 片段着色器,返回一些带 alpha 通道的透明颜色,我想在 MTKView 下面显示一个 UIView,但是我得到的唯一背景结果是黑色和“错误噪声”。
MTLRenderPipelineDescriptor:
pipelineStateDescriptor.isAlphaToCoverageEnabled = true
pipelineStateDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
pipelineStateDescriptor.colorAttachments[0].isBlendingEnabled = true
pipelineStateDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
pipelineStateDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
MTLRenderPassDescriptor:
renderPassDescriptor.colorAttachments[0].loadAction = .clear
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0)
如果我更改清除颜色,我可以在透明颜色下看到它,但是如果我跳过清除颜色,我会看到“错误噪声”。清除颜色的alpha通道实际上有用吗?
有人知道如何使MTKView透明吗?
更新:
这是使MTKView透明的神奇属性:
self.isOpaque = false
MTKView
的子类,该子类覆盖了opaque
属性并返回false? - Ken Thomases