Reputation: 841
I am drawing three squares as in the Picture
I am adding color of red with alpha 0.2.
In the overlapping areas also I want the areas to be in the alpha of 0.2. Now It is coming as 0.6. How can I do that suggest. Currently my pipeline Descriptor is
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
Do I need to do it in Pipeline Descriptor or In Shader ?
Upvotes: 0
Views: 510
Reputation: 260
If you want the final result to have the same alpha as which you are drawing, you need to set them as:
pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .zero
Which will mean that the final alpha will have no contribution from the target on which you are rendering.
Upvotes: 1