[Bf-blender-cvs] [ea6cd1c8f05] master: Overlay: Fade Inactive Geometry

Pablo Dobarro noreply at git.blender.org
Fri Sep 18 19:26:56 CEST 2020


Commit: ea6cd1c8f05b27a81e835251e779f047a3488203
Author: Pablo Dobarro
Date:   Fri Sep 18 19:20:22 2020 +0200
Branches: master
https://developer.blender.org/rBea6cd1c8f05b27a81e835251e779f047a3488203

Overlay: Fade Inactive Geometry

This implements a new overlay that blends the bakground color over the
objects that are not in the same mode as the active object, making
them fade with the background.
This is especially needed for sculpt mode as there is no other overlay
or indication in the viewport to display which object is active.

This is intended to be used with D7510 in order to have a faster
workflow when sculpting models with multiple objects.

Reviewed By: fclem

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

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

M	release/scripts/addons
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/overlay/overlay_engine.c
A	source/blender/draw/engines/overlay/overlay_fade.c
M	source/blender/draw/engines/overlay/overlay_private.h
M	source/blender/makesdna/DNA_view3d_defaults.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/tools

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

diff --git a/release/scripts/addons b/release/scripts/addons
index 49c39f59fbc..1f043682f95 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 49c39f59fbc464dd34388990123f271c39eacbf4
+Subproject commit 1f043682f9568fed02e3b877b31e8244b1b7a5c2
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 269237e804c..9cf61dc297a 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -6122,6 +6122,10 @@ class VIEW3D_PT_overlay_geometry(Panel):
         col.active = display_all
 
         col.prop(overlay, "show_face_orientation")
+        row = col.row(align=True)
+        row.prop(overlay, "show_fade_inactive", text="")
+        sub = row.row()
+        sub.prop(overlay, "fade_inactive_alpha", text="Fade Inactive Geometry")
 
         # sub.prop(overlay, "show_onion_skins")
 
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 022a720b2ef..1d4912db330 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -735,5 +735,20 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
    */
   {
     /* Keep this block, even when empty. */
+
+    /* Darken Inactive Overlay. */
+    if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "fade_alpha")) {
+      for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+        LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+          LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+            if (sl->spacetype == SPACE_VIEW3D) {
+              View3D *v3d = (View3D *)sl;
+              v3d->overlay.fade_alpha = 0.40f;
+              v3d->overlay.flag |= V3D_OVERLAY_FADE_INACTIVE;
+            }
+          }
+        }
+      }
+    }
   }
 }
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 089b656d76c..11aea544c65 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -134,6 +134,7 @@ set(SRC
   engines/overlay/overlay_engine.c
   engines/overlay/overlay_extra.c
   engines/overlay/overlay_facing.c
+  engines/overlay/overlay_fade.c
   engines/overlay/overlay_gpencil.c
   engines/overlay/overlay_grid.c
   engines/overlay/overlay_image.c
diff --git a/source/blender/draw/engines/overlay/overlay_engine.c b/source/blender/draw/engines/overlay/overlay_engine.c
index 9cdd371ec4e..e93b505e8b7 100644
--- a/source/blender/draw/engines/overlay/overlay_engine.c
+++ b/source/blender/draw/engines/overlay/overlay_engine.c
@@ -196,6 +196,7 @@ static void OVERLAY_cache_init(void *vedata)
   OVERLAY_antialiasing_cache_init(vedata);
   OVERLAY_armature_cache_init(vedata);
   OVERLAY_background_cache_init(vedata);
+  OVERLAY_fade_cache_init(vedata);
   OVERLAY_extra_cache_init(vedata);
   OVERLAY_facing_cache_init(vedata);
   OVERLAY_gpencil_cache_init(vedata);
@@ -259,6 +260,27 @@ static bool overlay_object_is_edit_mode(const OVERLAY_PrivateData *pd, const Obj
   return false;
 }
 
+static bool overlay_should_fade_object(Object *ob, Object *active_object)
+{
+  if (!active_object || !ob) {
+    return false;
+  }
+
+  if (ELEM(active_object->mode, OB_MODE_OBJECT, OB_MODE_POSE)) {
+    return false;
+  }
+
+  if ((active_object->mode & ob->mode) != 0) {
+    return false;
+  }
+
+  if (ob->base_flag & BASE_FROM_DUPLI) {
+    return false;
+  }
+
+  return true;
+}
+
 static void OVERLAY_cache_populate(void *vedata, Object *ob)
 {
   OVERLAY_Data *data = vedata;
@@ -295,6 +317,8 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob)
   const bool draw_surface = (ob->dt >= OB_WIRE) && (renderable || (ob->dt == OB_WIRE));
   const bool draw_facing = draw_surface && (pd->overlay.flag & V3D_OVERLAY_FACE_ORIENTATION) &&
                            !is_select;
+  const bool draw_fade = draw_surface && (pd->overlay.flag & V3D_OVERLAY_FADE_INACTIVE) &&
+                         overlay_should_fade_object(ob, draw_ctx->obact);
   const bool draw_bones = (pd->overlay.flag & V3D_OVERLAY_HIDE_BONES) == 0;
   const bool draw_wires = draw_surface && has_surface &&
                           (pd->wireframe_mode || !pd->hide_overlays);
@@ -315,6 +339,9 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob)
   bool do_init;
   OVERLAY_DupliData *dupli = OVERLAY_duplidata_get(ob, vedata, &do_init);
 
+  if (draw_fade) {
+    OVERLAY_fade_cache_populate(vedata, ob);
+  }
   if (draw_facing) {
     OVERLAY_facing_cache_populate(vedata, ob);
   }
@@ -511,6 +538,7 @@ static void OVERLAY_draw_scene(void *vedata)
   }
 
   OVERLAY_image_draw(vedata);
+  OVERLAY_fade_draw(vedata);
   OVERLAY_facing_draw(vedata);
   OVERLAY_extra_blend_draw(vedata);
 
@@ -538,6 +566,7 @@ static void OVERLAY_draw_scene(void *vedata)
     GPU_framebuffer_bind(fbl->overlay_in_front_fb);
   }
 
+  OVERLAY_fade_infront_draw(vedata);
   OVERLAY_facing_infront_draw(vedata);
 
   if (DRW_state_is_fbo()) {
diff --git a/source/blender/draw/engines/overlay/overlay_fade.c b/source/blender/draw/engines/overlay/overlay_fade.c
new file mode 100644
index 00000000000..0971021f1c0
--- /dev/null
+++ b/source/blender/draw/engines/overlay/overlay_fade.c
@@ -0,0 +1,99 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2020, Blender Foundation.
+ */
+
+/** \file
+ * \ingroup draw_engine
+ */
+
+#include "BKE_paint.h"
+#include "DRW_render.h"
+
+#include "ED_view3d.h"
+
+#include "overlay_private.h"
+
+void OVERLAY_fade_init(OVERLAY_Data *UNUSED(vedata))
+{
+}
+
+void OVERLAY_fade_cache_init(OVERLAY_Data *vedata)
+{
+  OVERLAY_PassList *psl = vedata->psl;
+  OVERLAY_PrivateData *pd = vedata->stl->pd;
+
+  for (int i = 0; i < 2; i++) {
+    /* Non Meshes Pass (Camera, empties, lights ...) */
+    DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA;
+    DRW_PASS_CREATE(psl->fade_ps[i], state | pd->clipping_state);
+
+    GPUShader *sh = OVERLAY_shader_uniform_color();
+    pd->fade_grp[i] = DRW_shgroup_create(sh, psl->fade_ps[i]);
+    DRW_shgroup_uniform_block(pd->fade_grp[i], "globalsBlock", G_draw.block_ubo);
+
+    const DRWContextState *draw_ctx = DRW_context_state_get();
+    float color[4];
+    ED_view3d_background_color_get(draw_ctx->scene, draw_ctx->v3d, color);
+    color[3] = pd->overlay.fade_alpha;
+    if (draw_ctx->v3d->shading.background_type == V3D_SHADING_BACKGROUND_THEME) {
+      srgb_to_linearrgb_v4(color, color);
+    }
+    DRW_shgroup_uniform_vec4_copy(pd->fade_grp[i], "color", color);
+  }
+
+  if (!pd->use_in_front) {
+    pd->fade_grp[IN_FRONT] = pd->fade_grp[NOT_IN_FRONT];
+  }
+}
+
+void OVERLAY_fade_cache_populate(OVERLAY_Data *vedata, Object *ob)
+{
+  OVERLAY_PrivateData *pd = vedata->stl->pd;
+
+  if (pd->xray_enabled) {
+    return;
+  }
+
+  const DRWContextState *draw_ctx = DRW_context_state_get();
+  const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) &&
+                               !DRW_state_is_image_render();
+  const bool is_xray = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
+
+  if (use_sculpt_pbvh) {
+    DRW_shgroup_call_sculpt(pd->fade_grp[is_xray], ob, false, false);
+  }
+  else {
+    struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
+    if (geom) {
+      DRW_shgroup_call(pd->fade_grp[is_xray], geom, ob);
+    }
+  }
+}
+
+void OVERLAY_fade_draw(OVERLAY_Data *vedata)
+{
+  OVERLAY_PassList *psl = vedata->psl;
+
+  DRW_draw_pass(psl->fade_ps[NOT_IN_FRONT]);
+}
+
+void OVERLAY_fade_infront_draw(OVERLAY_Data *vedata)
+{
+  OVERLAY_PassList *psl = vedata->psl;
+
+  DRW_draw_pass(psl->fade_ps[IN_FRONT]);
+}
diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h
index b84b66ca83d..2cf2ca34801 100644
--- a/source/blender/draw/engines/overlay/overlay_private.h
+++ b/source/blender/draw/engines/overlay/overlay_private.h
@@ -100,6 +100,7 @@ typedef struct OVERLAY_PassList {
   DRWPass *extra_grid_ps;
   DRWPass *gpencil_canvas_ps;
   DRWPass *facing_ps[2];
+  DRWPass *fade_ps[2];
   DRWPass *grid_ps;
   DRWPass *image_background_ps;
   DRWPass *image_empties_ps;
@@ -268,6 +269,7 @@ typedef struct OVERLAY_PrivateData {
   DRWShadingGroup *edit_uv_stretching_grp;
   DRWShadingGroup *extra_grid_grp;
   DRWShadingGroup *facing_grp[2];
+  DRWShadingGroup *fade_grp[2];
   DRWShadingGroup *motion_path_lines_grp;
   DRWShadingGroup *motion_path_points_grp;
   DRWShadingGroup *outlines_grp;
@@ -566,6 +568,12 @@ void OVERLAY_facing_cache_populate(OVERLAY_Data *vedata, Object *ob);
 void OVERLAY_facing_draw(OVERLAY_Data *vedata);
 void OVERLAY_facing_infront_draw(OVERLAY_Data *vedata);
 
+void OVERLAY_fade_init(OVERLAY_Data *vedata);
+void OVERLAY_fade_cache_init(OVERLAY_Data *vedata);
+void OVERLAY_fade_cache_populate(OVERLAY_Data *vedata, Object *ob);
+void OVERLAY_fade_draw(OVERLAY_Data *vedata);
+void OVERLAY_fade_infront_draw(OVERLAY_Data *vedata);
+
 void OVERLAY_grid_init(OVERLAY_Data *vedata);
 void OVERLAY_grid_cache_init(OVERLAY_Data *vedata);
 void OVERLAY_grid_draw(OVERLAY_Data *vedata);
diff --git a/source/blender/makesdna/DNA_view3d_defaults.h b/source/blender/makesdna/DNA_view3d_defaults.h
index 62e3d14bd0c..68f23b33d07 100644
--- a/source/blender/makesdna/DNA_view3d_defaults.h
+++ b/source/blender/makesdna/DNA_view3d_defaults.h
@@ -52,6 +52,7 @@
   { \
     .wireframe_threshol

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list