I need to render textures that have transparency and I cannot figure out the correct colorAttachment rgb and alpha blend factors.
Where I'm at:
1) PNG file saved from Photoshop with 50% opacity. No alpha channel added. Just 50% opacity setting in the Levels panel.
2) My texture shader is trivial. Here is the fragment shader:
fragment float4 textureFragmentShader(_Vertex_ vert [[ stage_in ]], texture2d<float> texas [[ texture(0) ]]) {
constexpr sampler defaultSampler;
float4 rgba = texas.sample(defaultSampler, vert.st).rgba;
return rgba;
}
3) This is my colorAttachment setup:
renderToTexturePipelineDescriptor.colorAttachments[ 0 ].isBlendingEnabled = true
renderToTexturePipelineDescriptor.colorAttachments[ 0 ].rgbBlendOperation = .add
renderToTexturePipelineDescriptor.colorAttachments[ 0 ].alphaBlendOperation = .add
renderToTexturePipelineDescriptor.colorAttachments[ 0 ].sourceRGBBlendFactor = .sourceAlpha
renderToTexturePipelineDescriptor.colorAttachments[ 0 ].sourceAlphaBlendFactor = .sourceAlpha
renderToTexturePipelineDescriptor.colorAttachments[ 0 ].destinationRGBBlendFactor = .oneMinusSourceAlpha
renderToTexturePipelineDescriptor.colorAttachments[ 0 ].destinationAlphaBlendFactor = .oneMinusSourceAlpha
4) The rendered result - here a textured rectangle against a white background is clearly wrong:
What are the correct blend factors?
Thanks,
Doug