[Bf-blender-cvs] [a5a003ed558] master: GPencil: New option to fade not selected objects

Antonio Vazquez noreply at git.blender.org
Fri Sep 6 17:23:05 CEST 2019


Commit: a5a003ed5589657cc53f41ba6042b28a4631cfed
Author: Antonio Vazquez
Date:   Fri Sep 6 17:20:54 2019 +0200
Branches: master
https://developer.blender.org/rBa5a003ed5589657cc53f41ba6042b28a4631cfed

GPencil: New option to fade not selected objects

Before, it was only possible to fade the active object. The new option allows to fade all non gpencil selected object. This is a common request by artists.

{F7719513}

Reviewers: mendio, pepeland

Reviewed By: mendio

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

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index a86d09c55e6..d144c2ffab6 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -6137,9 +6137,10 @@ class VIEW3D_PT_overlay_gpencil_options(Panel):
 
         row = col.row()
         row.prop(overlay, "use_gpencil_paper", text="")
-        sub = row.row()
+        sub = row.row(align=True)
         sub.active = overlay.use_gpencil_paper
-        sub.prop(overlay, "gpencil_paper_opacity", text="Fade 3D Objects", slider=True)
+        sub.prop(overlay, "gpencil_paper_opacity", text="Fade Objects", slider=True)
+        sub.prop(overlay, "use_gpencil_fade_objects", text="", icon='OUTLINER_OB_GREASEPENCIL')
 
         if context.object.mode == 'PAINT_GPENCIL':
             row = col.row()
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 01c3c10eb9e..e3c3f0b5d12 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -61,6 +61,38 @@
 #define TEXTURE 4
 #define PATTERN 5
 
+/* Verify if must fade object or not. */
+static bool gpencil_fade_object_check(GPENCIL_StorageList *stl, Object *ob)
+{
+  const DRWContextState *draw_ctx = DRW_context_state_get();
+  View3D *v3d = draw_ctx->v3d;
+  const bool is_overlay = (bool)((v3d) && ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) &&
+                                 (v3d->gp_flag & V3D_GP_SHOW_PAPER));
+
+  if ((!is_overlay) || (ob == draw_ctx->obact) ||
+      ((v3d->gp_flag & V3D_GP_FADE_NOACTIVE_GPENCIL) == 0) ||
+      (v3d->overlay.gpencil_paper_opacity == 1.0f)) {
+    return false;
+  }
+
+  const bool playing = stl->storage->is_playing;
+  const bool is_render = (bool)stl->storage->is_render;
+  const bool is_mat_preview = (bool)stl->storage->is_mat_preview;
+  const bool is_select = (bool)(DRW_state_is_select() || DRW_state_is_depth());
+
+  return (bool)((!is_render) && (!playing) && (!is_mat_preview) && (!is_select));
+}
+
+/* Define Fade object uniforms. */
+static void gpencil_set_fade_uniforms(View3D *v3d, DRWShadingGroup *grp, bool status)
+{
+  DRW_shgroup_uniform_bool_copy(grp, "fade_on", status);
+  if (v3d) {
+    DRW_shgroup_uniform_vec3(grp, "fade_color", v3d->shading.background_color, 1);
+    DRW_shgroup_uniform_float(grp, "fade_factor", &v3d->overlay.gpencil_paper_opacity, 1);
+  }
+}
+
 /* Get number of vertex for using in GPU VBOs */
 static void gpencil_calc_vertex(GPENCIL_StorageList *stl,
                                 tGPencilObjectCache *cache_ob,
@@ -435,6 +467,9 @@ static DRWShadingGroup *gpencil_shgroup_fill_create(GPENCIL_Data *vedata,
 
   DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
 
+  /* Fade object uniforms. */
+  gpencil_set_fade_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob));
+
   /* wire color */
   set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, true);
   DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1);
@@ -557,6 +592,9 @@ DRWShadingGroup *gpencil_shgroup_stroke_create(GPENCIL_Data *vedata,
     }
     DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
 
+    /* Fade object uniforms. */
+    gpencil_set_fade_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob));
+
     /* wire color */
     set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false);
     DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1);
@@ -607,6 +645,9 @@ DRWShadingGroup *gpencil_shgroup_stroke_create(GPENCIL_Data *vedata,
     DRW_shgroup_uniform_int(grp, "xraymode", &stl->storage->xray, 1);
   }
 
+  /* Fade object uniforms. */
+  gpencil_set_fade_uniforms(v3d, grp, false);
+
   /* image texture for pattern */
   if ((gp_style) && (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) && (!onion)) {
     ImBuf *ibuf;
@@ -706,6 +747,9 @@ static DRWShadingGroup *gpencil_shgroup_point_create(GPENCIL_Data *vedata,
     }
     DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
 
+    /* Fade object uniforms. */
+    gpencil_set_fade_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob));
+
     /* wire color */
     set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false);
     DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1);
@@ -764,6 +808,9 @@ static DRWShadingGroup *gpencil_shgroup_point_create(GPENCIL_Data *vedata,
     DRW_shgroup_uniform_int(grp, "xraymode", &stl->storage->xray, 1);
   }
 
+  /* Fade object uniforms. */
+  gpencil_set_fade_uniforms(v3d, grp, false);
+
   /* image texture */
   if ((gp_style) && (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) && (!onion)) {
     ImBuf *ibuf;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
index 64bb70f2a3f..7e8f59cf917 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
@@ -26,6 +26,10 @@ uniform int viewport_xray;
 uniform int shading_type[2];
 uniform vec4 wire_color;
 
+uniform bool fade_on;
+uniform vec3 fade_color;
+uniform float fade_factor;
+
 /* keep this list synchronized with list in gpencil_draw_utils.c */
 #define SOLID 0
 #define GRADIENT 1
@@ -211,4 +215,8 @@ void main()
       fragColor.a *= 0.5;
     }
   }
+  /* Apply paper opacity */
+  if (fade_on == true) {
+    fragColor.rgb = mix(fade_color.rgb, fragColor.rgb, fade_factor);
+  }
 }
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
index 34777018a73..f59c08730fe 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
@@ -14,6 +14,10 @@ in vec4 mColor;
 in vec2 mTexCoord;
 out vec4 fragColor;
 
+uniform bool fade_on;
+uniform vec3 fade_color;
+uniform float fade_factor;
+
 #define texture2D texture
 
 #define GPENCIL_MODE_LINE 0
@@ -104,4 +108,9 @@ void main()
   if (fragColor.a < 0.0035) {
     discard;
   }
+
+  /* Apply paper opacity */
+  if (fade_on == true) {
+    fragColor.rgb = mix(fade_color.rgb, fragColor.rgb, fade_factor);
+  }
 }
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
index 73baacb35d4..e64166527a1 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
@@ -8,6 +8,10 @@ uniform vec4 colormix;
 uniform float mix_stroke_factor;
 uniform int shading_type[2];
 
+uniform bool fade_on;
+uniform vec3 fade_color;
+uniform float fade_factor;
+
 in vec4 mColor;
 in vec2 mTexCoord;
 in vec2 uvfac;
@@ -88,4 +92,9 @@ void main()
   if (fragColor.a < 0.0035) {
     discard;
   }
+
+  /* Apply paper opacity */
+  if (fade_on == true) {
+    fragColor.rgb = mix(fade_color.rgb, fragColor.rgb, fade_factor);
+  }
 }
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index 5db0021af22..3a7675eb92a 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -394,8 +394,9 @@ typedef struct View3D {
 #define V3D_GP_SHOW_GRID (1 << 1)  /* Activate paper grid */
 #define V3D_GP_SHOW_EDIT_LINES (1 << 2)
 #define V3D_GP_SHOW_MULTIEDIT_LINES (1 << 3)
-#define V3D_GP_SHOW_ONION_SKIN (1 << 4)      /* main switch at view level */
-#define V3D_GP_FADE_NOACTIVE_LAYERS (1 << 5) /* fade layers not active */
+#define V3D_GP_SHOW_ONION_SKIN (1 << 4)       /* main switch at view level */
+#define V3D_GP_FADE_NOACTIVE_LAYERS (1 << 5)  /* fade layers not active */
+#define V3D_GP_FADE_NOACTIVE_GPENCIL (1 << 6) /* Fade other GPencil objects */
 
 /** #View3DShading.light */
 enum {
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 171da61e483..4da0dd1d4ce 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -3630,10 +3630,10 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
 
   prop = RNA_def_property(srna, "use_gpencil_paper", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "gp_flag", V3D_GP_SHOW_PAPER);
-  RNA_def_property_ui_text(prop,
-                           "Use Paper",
-                           "Cover all viewport with a full color layer to improve visibility "
-                           "while drawing over complex scenes");
+  RNA_def_property_ui_text(
+      prop,
+      "Fade Objects",
+      "Fade all viewport objects with a full color layer to improve visibility");
   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
   prop = RNA_def_property(srna, "use_gpencil_grid", PROP_BOOLEAN, PROP_NONE);
@@ -3647,6 +3647,12 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
       prop, "Fade Layers", "Toggle fading of Grease Pencil layers except the active one");
   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPencil_update");
 
+  prop = RNA_def_property(srna, "use_gpencil_fade_objects", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "gp_flag", V3D_GP_FADE_NOACTIVE_GPENCIL);
+  RNA_def_property_ui_text(
+      prop, "Fade Grease Pencil Objects", "Fade Grease Pencil Objects, except the active one");
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPencil_update");
+
   prop = RNA_def_property(srna, "gpencil_grid_opacity", PROP_FLOAT, PROP_NONE);
   RNA_def_property_float_sdna(prop, NULL, "overlay.gpencil_grid_opacity");
   RNA_def_property_range(prop, 0.1f, 1.0f);
@@ -3659,7 +3665,7 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
   RNA_def_property_float_sdna(prop, NULL, "overlay.gpencil_paper_opacity");
   RNA_def_property_range(prop, 0.0f, 1.0f);
   RNA_def_property_float_default(prop, 0.5f);
- 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list