我有一个简单的管道描述符
let p = MTLRenderPipelineDescriptor()
...
p.colorAttachments[0].pixelFormat = .bgra8Unorm
背景是纯蓝色
let bg = MTLClearColor(red: 0, green: 0, blue: 1, alpha: 1)
let pass = MTLRenderPassDescriptor()
pass.colorAttachments[0].loadAction = .clear
pass.colorAttachments[0].clearColor = bg
我只是在上面画一个多边形,说一个红色的:
fragment half4 fattie_fragment() {
return half4(1,0,0, 1);
}
还是绿色...
fragment half4 fattie_fragment() {
return half4(0,1,0, 1);
}
如果您希望三角形颜色透明,在金属中该怎么办?
fragment half4 fattie_fragment() {
return half4(0,1,0, 0.275);
}
(注意 - 待定 我不希望整体视图是透明的。只是着色器,绘制的三角形。
配置渲染管线描述符时,请启用混合并选择一组合适的混合因子和操作。例如:
let p = MTLRenderPipelineDescriptor()
...
p.colorAttachments[0].isBlendingEnabled = true
p.colorAttachments[0].rgbBlendOperation = .add
p.colorAttachments[0].alphaBlendOperation = .add
p.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
p.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
p.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
p.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha