I am rendering using Metal. I am trying to convert the texture to a png (like a sticker) with a transparent background and a translucent subject (with alpha), but when I convert the MTLTexture to a PNG file and look at the image, the color appears much brighter than the color shown in the view. (It is shown in the png file in the same way as the bright color when isOpaque = false in the CAMetalLayer setting.)
Currently I have set isOpaque = false and I want to convert it to png with the same color.
There can be multiple subjects, and each is shown on the screen after alpha blending.
The pixelformat is bgra8Unorm and the colorspace is using CGColorSpaceCreateDeviceRGB().
Do you have any experience or guesses?
In the case of the output balloon image, the background is given as alpha 0 and the subject as alpha 0.5. (Upper is the resulting image (bright), lower is the expected image (normal))
I am directly blending by importing src and dst into the shader, and the formula I am using is as follows:
let alpha = srcAlpha + dstAlpha * (1 - srcAlpha)
let color = (srcRGB * srcAlpha + dstRGB * dstAlpha * (1 - srcAlpha)) / alpha
Please don't hesitate to let me know anything!!!
I think I've tried all the methods found on google.
Even if the color is returned directly from the shader without blending, there is a difference between the color in the view and the color in the png file.