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
This commit is contained in:
Pablo Dobarro 2020-09-18 19:20:22 +02:00 committed by Pablo Dobarro
parent 5855f317a7
commit ea6cd1c8f0
Notes: blender-bot 2023-02-14 05:52:32 +01:00
Referenced by issue #82155, Overlay setting "Fade Inactive Geometry" does not work with instance collections.
11 changed files with 178 additions and 2 deletions

@ -1 +1 @@
Subproject commit 49c39f59fbc464dd34388990123f271c39eacbf4
Subproject commit 1f043682f9568fed02e3b877b31e8244b1b7a5c2

View File

@ -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")

View File

@ -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;
}
}
}
}
}
}
}

View File

@ -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

View File

@ -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()) {

View File

@ -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]);
}

View File

@ -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);

View File

@ -52,6 +52,7 @@
{ \
.wireframe_threshold = 1.0f, \
.xray_alpha_bone = 0.5f, \
.fade_alpha = 0.40f, \
.texture_paint_mode_opacity = 1.0f, \
.weight_paint_mode_opacity = 1.0f, \
.vertex_paint_mode_opacity = 1.0f, \

View File

@ -218,6 +218,9 @@ typedef struct View3DOverlay {
/** Armature edit/pose mode settings. */
float xray_alpha_bone;
/** Darken Inactive. */
float fade_alpha;
/** Other settings. */
float wireframe_threshold;
@ -230,6 +233,7 @@ typedef struct View3DOverlay {
float gpencil_vertex_paint_opacity;
/** Handles display type for curves. */
int handle_display;
char _pad[4];
} View3DOverlay;
/* View3DOverlay->handle_display */
@ -503,6 +507,7 @@ enum {
V3D_OVERLAY_HIDE_OBJECT_XTRAS = (1 << 9),
V3D_OVERLAY_HIDE_OBJECT_ORIGINS = (1 << 10),
V3D_OVERLAY_STATS = (1 << 11),
V3D_OVERLAY_FADE_INACTIVE = (1 << 12),
};
/** #View3DOverlay.edit_flag */

View File

@ -3615,6 +3615,20 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Face Orientation", "Show the Face Orientation Overlay");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_fade_inactive", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "overlay.flag", V3D_OVERLAY_FADE_INACTIVE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_ui_text(
prop, "Fade Inactive Objects", "Fade inactive geometry using the viewport background color");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "fade_inactive_alpha", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "overlay.fade_alpha");
RNA_def_property_ui_text(prop, "Opacity", "Strength of the fade effect");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPencil_update");
prop = RNA_def_property(srna, "show_xray_bone", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "overlay.flag", V3D_OVERLAY_BONE_SELECT);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);

@ -1 +1 @@
Subproject commit 896c5f78952adb2d091d28c65086d46992dabdac
Subproject commit 4b309364f65fee1ffafc5a4062125b8b728837a5