Reputation: 361
I’m trying to render an opaque object inside a semi-transparent one.
My approach is:
Depth compare function set to less
descriptor.depthCompareFunction = .less
First a draw call with the opaque object, with not blending enabled.
A second draw call with the semi-transparent object, with blending enabled.
if !opaque {
pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
}
But I get unexpected result: example
all the code here: https://github.com/quaternionboy/Metal-Playground
Upvotes: 1
Views: 85
Reputation: 361
I found, with the help of Caroline Begbie (raywenderlich), the solution: sort front to back the vertices...
https://forums.raywenderlich.com/t/rendering-opaque-object-inside-transparent-one/121942/2
Upvotes: 2