我正在将Asset文件夹中的png格式更改为MTLTexture。它在透明边缘变黑。
func loadTexture(device: MTLDevice, textureName: String) throws -> MTLTexture {
let textureLoader = MTKTextureLoader(device: device)
return try textureLoader.newTexture(name: textureName, scaleFactor: 1.0, bundle: nil, options: nil)
}
管道描述符是
let pipelineDescriptor = MTLRenderPipelineDescriptor()
pipelineDescriptor.fragmentFunction = fragmentFunction
pipelineDescriptor.vertexFunction = vertexFunction
pipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
pipelineDescriptor.sampleCount = 4
pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
pipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .one
pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha