2

I'm rendering some triangles into multisampled texture. Then blit this texture into normal texture and draw a textured quad onto screen.

I need the final texture to have premultiplied alpha. Is there a way to tell OpenGL to automatically premultiply semi-transparent pixels in multisampled texture (or when blitting)?

Or the only way is using an extra shader pass to perform multiplication manually?

nj16
  • 63
  • 5
  • Ideally, you already want the input textures to have the pre-multiplied alpha, otherwise you will get artifacts when the texture filter interpolates between neighboring texels with differing alpha values. – derhass Jul 25 '21 at 16:45
  • Sure, that's what I'm aiming for, but resolving the multisampled texture will not premultiply alpha at antialiasing pixels that multisampling created. – nj16 Jul 25 '21 at 19:19

1 Answers1

2

A multisample resolve blit can't perform pre-multiplication. You will have to pre-multiply the texture's pixels in the process that reads from the texture.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • That's what I was suspecting. The additional problem though is that I need to draw two types of things into the multisampled texture: 1) blended transparent sprites that already have premultiplied alpha, and 2) fully opaque triangles whose only alpha is created by antialiasing itself (and it's not multiplied). So I end up with multiplied and straight values in the multisampled texture. Not sure what'd be the best way to organize the whole thing so the final result is all multiplied values. – nj16 Jul 25 '21 at 19:12