2
\$\begingroup\$

For instance, when loading an image that is SRGB, which of these is correct?

  • Simple premultiply:
    • Take SRGB color from file and multiply RGB by alpha

or

  • Convert to linear before premultiply:
    • Take SRGB color from and convert RGB to Linear
    • Multiply Linear RGB by alpha
    • Take Linear RGB and convert back to SRGB
\$\endgroup\$
1
\$\begingroup\$

This article seems to imply that the most efficient method is the latter: multiply by alpha, then convert to SRGB.

As far as correctness, I realized that if your texture and framebuffer are SRGB, the GPU does SRGB conversion and then blends in linear space. Therefore if you are using SRGB textures and framebuffers, you should premultiply alpha in linear space (the latter approach). If you're rolling your own blending, the order of operations shouldn't matter as long as you undo them in the right order.

This also agrees with the findings that led me to this question: When exporting my premultiplied render target to PNG, my colors had greater RGB values than my alpha value, but converting the RGB value to linear made them equal to alpha.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.