Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Dobarro <pablodp606>2020-09-18 20:20:22 +0300
committerPablo Dobarro <pablodp606@gmail.com>2020-09-18 20:24:58 +0300
commitea6cd1c8f05b27a81e835251e779f047a3488203 (patch)
treef474690da2ddba60ca0feb2664141f65cde38a5d /source/blender/draw/engines/overlay
parent5855f317a7070d69dbb94761c5a2c2f53b058a6e (diff)
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
Diffstat (limited to 'source/blender/draw/engines/overlay')
-rw-r--r--source/blender/draw/engines/overlay/overlay_engine.c29
-rw-r--r--source/blender/draw/engines/overlay/overlay_fade.c99
-rw-r--r--source/blender/draw/engines/overlay/overlay_private.h8
3 files changed, 136 insertions, 0 deletions
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);