diff options
author | Jeroen Bakker <jbakker> | 2020-11-17 17:23:47 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2020-11-17 18:10:42 +0300 |
commit | d73130cc287690539a0509a44abd4c85ffb30188 (patch) | |
tree | deda0537cfd7d61d9f3b24e45c0e5c4da8d6115e /source/blender | |
parent | cc0b8cb3599f50012bd90a0c41462290007f3328 (diff) |
Fix T82770: Artifacts when painting on generated transparent image
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
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/image_gpu.c | 29 |
1 files changed, 19 insertions, 10 deletions
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; } /* -------------------------------------------------------------------- */ |