From d73130cc287690539a0509a44abd4c85ffb30188 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 17 Nov 2020 15:23:47 +0100 Subject: Fix T82770: Artifacts when painting on generated transparent image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regression introduced by {b17cca6966}. When centralizing the gpu texture premultiplication setting it was assumed that generated images (`IMA_TYPE_UV_TEST`) were stored as premultiplied. That assumption was totally wrong as the alpha association is determined by the existing of the float/byte buffer. NOTE: This change will render generated images with pure emissive colors (show colors when alpha=0.0) what might add more reports. Any reports could be merged in the next report {T82790}. Reviewed By: Clément Foucault, Philipp Oeser Differential Revision: https://developer.blender.org/D9585 --- source/blender/blenkernel/intern/image_gpu.c | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/image_gpu.c b/source/blender/blenkernel/intern/image_gpu.c index 4d4013e5d1d..026edb0850b 100644 --- a/source/blender/blenkernel/intern/image_gpu.c +++ b/source/blender/blenkernel/intern/image_gpu.c @@ -52,16 +52,25 @@ static void image_free_gpu(Image *ima, const bool immediate); /* Is the alpha of the `GPUTexture` for a given image/ibuf premultiplied. */ bool BKE_image_has_gpu_texture_premultiplied_alpha(Image *image, ImBuf *ibuf) { - const bool type_is_premultiplied = (image == NULL) || ELEM(image->type, - IMA_TYPE_R_RESULT, - IMA_TYPE_COMPOSITE, - IMA_TYPE_UV_TEST); - const bool store_premultiplied = - type_is_premultiplied || - ((ibuf != NULL) && - (ibuf->rect_float ? (image ? (image->alpha_mode != IMA_ALPHA_STRAIGHT) : false) : - (image ? (image->alpha_mode == IMA_ALPHA_PREMUL) : true))); - return store_premultiplied; + if (image) { + /* Render result and compositor output are always premultiplied */ + if (ELEM(image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) { + return true; + } + /* Generated images use pre multiplied float buffer, but straight alpha for byte buffers. */ + if (image->type == IMA_TYPE_UV_TEST && ibuf) { + return ibuf->rect_float != NULL; + } + } + else if (ibuf) { + if (ibuf->rect_float) { + return image ? (image->alpha_mode != IMA_ALPHA_STRAIGHT) : false; + } + else { + return image ? (image->alpha_mode == IMA_ALPHA_PREMUL) : true; + } + } + return false; } /* -------------------------------------------------------------------- */ -- cgit v1.2.3