[Bf-blender-cvs] [d73130cc287] blender-v2.91-release: Fix T82770: Artifacts when painting on generated transparent image

Jeroen Bakker noreply at git.blender.org
Tue Nov 17 16:11:12 CET 2020


Commit: d73130cc287690539a0509a44abd4c85ffb30188
Author: Jeroen Bakker
Date:   Tue Nov 17 15:23:47 2020 +0100
Branches: blender-v2.91-release
https://developer.blender.org/rBd73130cc287690539a0509a44abd4c85ffb30188

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

===================================================================

M	source/blender/blenkernel/intern/image_gpu.c

===================================================================

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;
 }
 
 /* -------------------------------------------------------------------- */



More information about the Bf-blender-cvs mailing list