我有一个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
Run Code Online (Sandbox Code Playgroud)
MTLRenderPassDescriptor:
renderPassDescriptor.colorAttachments[0].loadAction = .clear
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0)
Run Code Online (Sandbox Code Playgroud)
如果我改变了清晰的颜色,我可以在透明色下看到它,如果我跳过清晰的颜色,我会看到"错误噪音".明确的颜色alpha通道实际上做了什么吗?
有谁知道如何使MTKView透明?
更新:
这是使MTKView透明的神奇属性:
self.isOpaque = false
Run Code Online (Sandbox Code Playgroud)
如果a UIView可能具有透明内容或者无法用不透明图形填充自身,那么它应该将其opaque(isOpaque)属性设置为false,以便它可以与其后面的任何内容正确合成.因为,MTKView是一个子类UIView,这也适用于它.