Ruban4Axis
Ruban4Axis

Reputation: 841

Blending In Metal with Same Alpha

I am drawing three squares as in the Pictureenter image description here

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

Answers (1)

Abix
Abix

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

Related Questions