[Bf-blender-cvs] [278011e44d4] master: Fix T80748: Render Emissive Colors in Compositor Backdrop

Jeroen Bakker noreply at git.blender.org
Tue Nov 24 13:23:23 CET 2020


Commit: 278011e44d433dc202b2ab8e7907e323fb23c82d
Author: Jeroen Bakker
Date:   Tue Nov 24 13:18:57 2020 +0100
Branches: master
https://developer.blender.org/rB278011e44d433dc202b2ab8e7907e323fb23c82d

Fix T80748: Render Emissive Colors in Compositor Backdrop

This change will use the image engine to draw the backdrop of the compositor. With this patch the alpha blending will be done in Linear Scene Reference space and shows pure emissive colors.

See differential for an example image.

**Technical changes**

As only the backdrop drawing is done using the draw manager there are some technical changes.
1. The overlay buffer is partly drawn outside the draw manager. When drawing the backdrop image the overlay buffer needs to be masked to simulate premultiplied alpha under.
2. The backdrop of the node editor is done in region pixel space. A `DRWView` is constructed with this space.
3. UDIM textures uses world position to generate the UV coordinates. This has been implemented more strict by the `IMAGE_DRAW_FLAG_USE_WORLD_POS`. When the flag isn't used the local coordinates are used to generate the UV coordinates what is image space.
4. The draw manager now checks the actual `eSpaceType` of the space data to use different code paths. In the future the movie clip editor will be added.

NOTE: The preview images in nodes are drawn in display space and cannot show pure emissive colors. As preview images are used on more locations it is best to fix this in a separate patch.

Reviewed By: Clément Foucault

Differential Revision: https://developer.blender.org/D9451

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

M	source/blender/draw/engines/image/image_engine.c
M	source/blender/draw/engines/image/image_private.h
M	source/blender/draw/engines/image/shaders/engine_image_frag.glsl
M	source/blender/draw/engines/image/shaders/engine_image_vert.glsl
M	source/blender/draw/engines/overlay/overlay_background.c
M	source/blender/draw/engines/overlay/overlay_engine.c
M	source/blender/draw/engines/overlay/overlay_grid.c
M	source/blender/draw/engines/overlay/overlay_private.h
M	source/blender/draw/engines/overlay/shaders/background_frag.glsl
M	source/blender/draw/intern/draw_manager.c
M	source/blender/editors/space_node/CMakeLists.txt
M	source/blender/editors/space_node/drawnode.c

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

diff --git a/source/blender/draw/engines/image/image_engine.c b/source/blender/draw/engines/image/image_engine.c
index 3d767f911fa..0c602ba77c8 100644
--- a/source/blender/draw/engines/image/image_engine.c
+++ b/source/blender/draw/engines/image/image_engine.c
@@ -25,9 +25,11 @@
 #include "DRW_render.h"
 
 #include "BKE_image.h"
+#include "BKE_main.h"
 #include "BKE_object.h"
 
 #include "DNA_camera_types.h"
+#include "DNA_screen_types.h"
 
 #include "IMB_imbuf_types.h"
 
@@ -38,26 +40,55 @@
 #include "image_engine.h"
 #include "image_private.h"
 
-#define SIMA_DRAW_FLAG_SHOW_ALPHA (1 << 0)
-#define SIMA_DRAW_FLAG_APPLY_ALPHA (1 << 1)
-#define SIMA_DRAW_FLAG_SHUFFLING (1 << 2)
-#define SIMA_DRAW_FLAG_DEPTH (1 << 3)
-#define SIMA_DRAW_FLAG_DO_REPEAT (1 << 4)
+#define IMAGE_DRAW_FLAG_SHOW_ALPHA (1 << 0)
+#define IMAGE_DRAW_FLAG_APPLY_ALPHA (1 << 1)
+#define IMAGE_DRAW_FLAG_SHUFFLING (1 << 2)
+#define IMAGE_DRAW_FLAG_DEPTH (1 << 3)
+#define IMAGE_DRAW_FLAG_DO_REPEAT (1 << 4)
+#define IMAGE_DRAW_FLAG_USE_WORLD_POS (1 << 5)
 
-static void image_cache_image_add(DRWShadingGroup *grp, Image *image)
+static void image_cache_image_add(DRWShadingGroup *grp, Image *image, ImBuf *ibuf)
 {
+  const DRWContextState *draw_ctx = DRW_context_state_get();
+  const ARegion *region = draw_ctx->region;
+  const char space_type = draw_ctx->space_data->spacetype;
+
+  float zoom_x = 1.0f;
+  float zoom_y = 1.0f;
+  float translate_x = 0.0f;
+  float translate_y = 0.0f;
+
+  /* User can freely move the backdrop in the space of the node editor */
+  if (space_type == SPACE_NODE) {
+    SpaceNode *snode = (SpaceNode *)draw_ctx->space_data;
+    const float ibuf_width = ibuf->x;
+    const float ibuf_height = ibuf->y;
+    const float x = (region->winx - snode->zoom * ibuf_width) / 2 + snode->xof;
+    const float y = (region->winy - snode->zoom * ibuf_height) / 2 + snode->yof;
+
+    zoom_x = ibuf_width * snode->zoom;
+    zoom_y = ibuf_height * snode->zoom;
+    translate_x = x;
+    translate_y = y;
+  }
+
   const bool is_tiled_texture = image && image->source == IMA_SRC_TILED;
   float obmat[4][4];
   unit_m4(obmat);
 
   GPUBatch *geom = DRW_cache_quad_get();
 
+  obmat[0][0] = zoom_x;
+  obmat[1][1] = zoom_y;
+  obmat[3][1] = translate_y;
+  obmat[3][0] = translate_x;
+
   if (is_tiled_texture) {
     LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) {
       const int tile_x = ((tile->tile_number - 1001) % 10);
       const int tile_y = ((tile->tile_number - 1001) / 10);
-      obmat[3][1] = (float)tile_y;
-      obmat[3][0] = (float)tile_x;
+      obmat[3][1] = (float)tile_y + translate_y;
+      obmat[3][0] = (float)tile_x + translate_x;
       DRW_shgroup_call_obmat(grp, geom, obmat);
     }
   }
@@ -66,6 +97,63 @@ static void image_cache_image_add(DRWShadingGroup *grp, Image *image)
   }
 }
 
+static void space_image_gpu_texture_get(Image *image,
+                                        ImageUser *iuser,
+                                        ImBuf *ibuf,
+                                        GPUTexture **r_gpu_texture,
+                                        bool *r_owns_texture,
+                                        GPUTexture **r_tex_tile_data)
+{
+  const DRWContextState *draw_ctx = DRW_context_state_get();
+  SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
+  if (BKE_image_is_multilayer(image)) {
+    /* update multiindex and pass for the current eye */
+    BKE_image_multilayer_index(image->rr, &sima->iuser);
+  }
+  else {
+    BKE_image_multiview_index(image, &sima->iuser);
+  }
+
+  if (ibuf) {
+    if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) {
+      if (ibuf->zbuf) {
+        BLI_assert(!"Integer based depth buffers not supported");
+      }
+      else if (ibuf->zbuf_float) {
+        *r_gpu_texture = GPU_texture_create_2d(
+            __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->zbuf_float);
+        *r_owns_texture = true;
+      }
+      else if (ibuf->rect_float && ibuf->channels == 1) {
+        *r_gpu_texture = GPU_texture_create_2d(
+            __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->rect_float);
+        *r_owns_texture = true;
+      }
+    }
+    else if (image->source == IMA_SRC_TILED) {
+      *r_gpu_texture = BKE_image_get_gpu_tiles(image, iuser, ibuf);
+      *r_tex_tile_data = BKE_image_get_gpu_tilemap(image, iuser, NULL);
+      *r_owns_texture = false;
+    }
+    else {
+      *r_gpu_texture = BKE_image_get_gpu_texture(image, iuser, ibuf);
+      *r_owns_texture = false;
+    }
+  }
+}
+
+static void space_node_gpu_texture_get(Image *image,
+                                       ImageUser *iuser,
+                                       ImBuf *ibuf,
+                                       GPUTexture **r_gpu_texture,
+                                       bool *r_owns_texture,
+                                       GPUTexture **r_tex_tile_data)
+{
+  *r_gpu_texture = BKE_image_get_gpu_texture(image, iuser, ibuf);
+  *r_owns_texture = false;
+  *r_tex_tile_data = NULL;
+}
+
 static void image_gpu_texture_get(Image *image,
                                   ImageUser *iuser,
                                   ImBuf *ibuf,
@@ -73,45 +161,19 @@ static void image_gpu_texture_get(Image *image,
                                   bool *r_owns_texture,
                                   GPUTexture **r_tex_tile_data)
 {
+  if (!image) {
+    return;
+  }
 
   const DRWContextState *draw_ctx = DRW_context_state_get();
-  SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
+  const char space_type = draw_ctx->space_data->spacetype;
 
-  if (image) {
-    if (BKE_image_is_multilayer(image)) {
-      /* update multiindex and pass for the current eye */
-      BKE_image_multilayer_index(image->rr, &sima->iuser);
-    }
-    else {
-      BKE_image_multiview_index(image, &sima->iuser);
-    }
-
-    if (ibuf) {
-      if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) {
-        if (ibuf->zbuf) {
-          BLI_assert(!"Integer based depth buffers not supported");
-        }
-        else if (ibuf->zbuf_float) {
-          *r_gpu_texture = GPU_texture_create_2d(
-              __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->zbuf_float);
-          *r_owns_texture = true;
-        }
-        else if (ibuf->rect_float && ibuf->channels == 1) {
-          *r_gpu_texture = GPU_texture_create_2d(
-              __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->rect_float);
-          *r_owns_texture = true;
-        }
-      }
-      else if (image->source == IMA_SRC_TILED) {
-        *r_gpu_texture = BKE_image_get_gpu_tiles(image, iuser, ibuf);
-        *r_tex_tile_data = BKE_image_get_gpu_tilemap(image, iuser, NULL);
-        *r_owns_texture = false;
-      }
-      else {
-        *r_gpu_texture = BKE_image_get_gpu_texture(image, iuser, ibuf);
-        *r_owns_texture = false;
-      }
-    }
+  if (space_type == SPACE_IMAGE) {
+    space_image_gpu_texture_get(
+        image, iuser, ibuf, r_gpu_texture, r_owns_texture, r_tex_tile_data);
+  }
+  else if (space_type == SPACE_NODE) {
+    space_node_gpu_texture_get(image, iuser, ibuf, r_gpu_texture, r_owns_texture, r_tex_tile_data);
   }
 }
 
@@ -122,8 +184,8 @@ static void image_cache_image(IMAGE_Data *vedata, Image *image, ImageUser *iuser
   IMAGE_PrivateData *pd = stl->pd;
 
   const DRWContextState *draw_ctx = DRW_context_state_get();
+  const char space_type = draw_ctx->space_data->spacetype;
   const Scene *scene = draw_ctx->scene;
-  SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
 
   GPUTexture *tex_tile_data = NULL;
   image_gpu_texture_get(image, iuser, ibuf, &pd->texture, &pd->owns_texture, &tex_tile_data);
@@ -140,36 +202,66 @@ static void image_cache_image(IMAGE_Data *vedata, Image *image, ImageUser *iuser
 
     const bool use_premul_alpha = BKE_image_has_gpu_texture_premultiplied_alpha(image, ibuf);
     const bool is_tiled_texture = tex_tile_data != NULL;
-    const bool do_repeat = (!is_tiled_texture) && ((sima->flag & SI_DRAW_TILE) != 0);
 
     int draw_flags = 0;
-    SET_FLAG_FROM_TEST(draw_flags, do_repeat, SIMA_DRAW_FLAG_DO_REPEAT);
-    if ((sima->flag & SI_USE_ALPHA) != 0) {
-      /* Show RGBA */
-      draw_flags |= SIMA_DRAW_FLAG_SHOW_ALPHA | SIMA_DRAW_FLAG_APPLY_ALPHA;
-    }
-    else if ((sima->flag & SI_SHOW_ALPHA) != 0) {
-      draw_flags |= SIMA_DRAW_FLAG_SHUFFLING;
-      copy_v4_fl4(shuffle, 0.0f, 0.0f, 0.0f, 1.0f);
-    }
-    else if ((sima->flag & SI_SHOW_ZBUF) != 0) {
-      draw_flags |= SIMA_DRAW_FLAG_DEPTH | SIMA_DRAW_FLAG_SHUFFLING;
-      copy_v4_fl4(shuffle, 1.0f, 0.0f, 0.0f, 0.0f);
-    }
-    else if ((sima->flag & SI_SHOW_R) != 0) {
-      draw_flags |= SIMA_DRAW_FLAG_APPLY_ALPHA | SIMA_DRAW_FLAG_SHUFFLING;
-      copy_v4_fl4(shuffle, 1.0f, 0.0f, 0.0f, 0.0f);
-    }
-    else if ((sima->flag & SI_SHOW_G) != 0) {
-      draw_flags |= SIMA_DRAW_FLAG_APPLY_ALPHA | SIMA_DRAW_FLAG_SHUFFLING;
-      copy_v4_fl4(shuffle, 0.0f, 1.0f, 0.0f, 0.0f);
-    }
-    else if ((sima->flag & SI_SHOW_B) != 0) {
-      draw_flags |= SIMA_DRAW_FLAG_APPLY_ALPHA | SIMA_DRAW_FLAG_SHUFFLING;
-      copy_v4_fl4(shuffle, 0.0f, 0.0f, 1.0f, 0.0f);
+    if (space_type == SPACE_IMAGE) {
+      SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
+      const bool do_repeat = (!is_tiled_texture) && ((sima->flag & SI_DRAW_TILE) != 0);
+      SET_FLAG_FROM_TEST(draw_flags, do_repeat, IMAGE_DRAW_FLAG_DO_REPEAT);
+      SET_FLAG_FROM_TEST(draw_flags, is_tiled_texture, IMAGE_DRAW_FLAG_USE_WORLD_POS);
+      if ((sima->flag & SI_USE_ALPHA) != 0) {
+        /* Show RGBA */
+        draw_flags |= IMAGE_DRAW_FLAG_SHOW_ALPHA | IMAGE_DRAW_FLAG_APPLY_ALPHA;
+      }
+      else if ((sima->flag & SI_SHOW_ALPHA) != 0) {
+        draw_flags |= IMAGE_DRAW_FLAG_SHUFFLING;
+        copy_v4_fl4(shuffle, 0.0f, 0.0f, 0.0f, 1.0f);
+      }
+      else if ((sima->flag & SI_SHOW_ZBUF) != 0) {
+        draw_flags |= IMAGE_DRAW_FLAG_DEPTH | IMAGE_DRAW_FLAG_SHUFFLING;
+        copy_v4_fl4(shuffle, 1.0f, 0.0f, 0.0f, 0.0f);
+      }
+      else if ((sima->flag & SI_SHOW_R) != 0) {
+        draw_flags |= IMAGE_DRAW_FLAG_APPLY_ALPHA | IMAGE_DRAW_FLAG_SHUFFLING;
+        copy_v4_fl4(shuff

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list