金属を使用して、複雑なアルファを持つ 3D オブジェクトを表示しようとしています。
同じオブジェクトからオブジェクトへのアルファ ブレンディングで白いエッジが発生します。しかし、別のオブジェクトでは正常に動作しています。
1 つのオブジェクト内で depthMask を無効にすることで、Android でこの問題を解決しました。
Metal iOSでそれを行う方法を誰か助けてもらえますか?
私の renderEncoder は次のとおりです。
let pipelineStateDescriptor = MTLRenderPipelineDescriptor()
pipelineStateDescriptor.vertexFunction = vertexProgram
pipelineStateDescriptor.fragmentFunction = fragmentProgram
pipelineStateDescriptor.colorAttachments[0].pixelFormat = .BGRA8Unorm
pipelineStateDescriptor.colorAttachments[0].blendingEnabled = true
pipelineStateDescriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperation.Add;
pipelineStateDescriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperation.Add;
pipelineStateDescriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactor.SourceAlpha;
pipelineStateDescriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactor.SourceAlpha;
pipelineStateDescriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactor.OneMinusSourceAlpha;
pipelineStateDescriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactor.OneMinusSourceAlpha;
pipelineStateDescriptor.depthAttachmentPixelFormat = .Depth32Float
pipelineState = try! device.newRenderPipelineStateWithDescriptor(pipelineStateDescriptor)
let depthStencilDescriptor = MTLDepthStencilDescriptor()
depthStencilDescriptor.depthCompareFunction = .Less
depthStencilDescriptor.depthWriteEnabled = true
depthStencilState = device.newDepthStencilStateWithDescriptor(depthStencilDescriptor)
let renderPassDescriptor = MTLRenderPassDescriptor()
renderPassDescriptor.colorAttachments[0].texture = drawable.texture
renderPassDescriptor.colorAttachments[0].loadAction = .Clear
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
renderPassDescriptor.colorAttachments[0].storeAction = .Store
renderPassDescriptor.depthAttachment.loadAction = .Clear
renderPassDescriptor.depthAttachment.clearDepth = 1.0
renderPassDescriptor.depthAttachment.storeAction = .MultisampleResolve
let commandBuffer = commandQueue.commandBuffer()
commandBuffer.addCompletedHandler { (commandBuffer) -> Void in
dispatch_semaphore_signal(self.bufferProvider.avaliableResourcesSemaphore)
}
renderEncoder = commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor)
//For now cull mode is used instead of depth buffer
renderEncoder.setCullMode(MTLCullMode.Front)
renderEncoder.setDepthClipMode(.Clip)
renderEncoder.setRenderPipelineState(pipelineState)
renderEncoder.setDepthStencilState(depthStencilState)