gpt4 book ai didi

ios - 只需将 Metal frag 着色器设为透明颜色?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:00:21 31 4
gpt4 key购买 nike

我有一个简单的管道描述符

 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);
}

在Metal中想要三角形的颜色透明怎么办?

fragment half4 fattie_fragment() {
return half4(0,1,0, 0.275);
}

(注意 - TBC 我不希望整体 View 是透明的。只是着色器,绘制的三角形。)

最佳答案

当您配置渲染管道描述符时,启用混合并选择一组合适的混合因子和操作。例如:

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

关于ios - 只需将 Metal frag 着色器设为透明颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57040279/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com