简体   繁体   中英

Blending In Metal with Same Alpha

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM