[Bf-blender-cvs] [29b65f53451] master: GPencil: New modifier to generate weights dynamically

Antonio Vazquez noreply at git.blender.org
Fri Jul 2 12:05:15 CEST 2021


Commit: 29b65f5345128ee035599aa7233315a74fe6afe6
Author: Antonio Vazquez
Date:   Fri Jul 2 12:04:07 2021 +0200
Branches: master
https://developer.blender.org/rB29b65f5345128ee035599aa7233315a74fe6afe6

GPencil: New modifier to generate weights dynamically

his new modifier allows to generate weights base on:

* Angle of the stroke relative to object or world orientation. For example, if the value is 90, the maximum weights will be for vertical lines and minimum for horizontal lines.

* Distance to Target object. The distance calculated is normalized to get valid weights between 0 and 1.0.

The weights are created in an existing vertex group and the data can be replaced or mixed with the existing value to combine different weight effects. The minimum parameter, allows to define the minimum weight generated. This is useful to avoid very low weights.

The generated weights can be used in any modifier. For example, the angle weight value can be used to mimic FreeStyle Caligraphy modifier using the weight with the thickness modifier.

Also some modifier has been changed to inlude a new option to use the weights as factor of the effect.
As result of this change, the fading option has been removed from Thickness and Opacity modifiers because this can be done using the new modifier, it's not logic to repeat the same.

Reviewed By: mendio, filedescriptor

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

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

M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/gpencil_modifiers/CMakeLists.txt
M	source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.h
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
M	source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c
A	source/blender/gpencil_modifiers/intern/MOD_gpencilweight.c
M	source/blender/makesdna/DNA_gpencil_modifier_defaults.h
M	source/blender/makesdna/DNA_gpencil_modifier_types.h
M	source/blender/makesdna/intern/dna_defaults.c
M	source/blender/makesrna/intern/rna_gpencil_modifier.c

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

diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 4fe29d4e9bd..69680f57d98 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -2356,6 +2356,9 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te)
             case eGpencilModifierType_Texture:
               data.icon = ICON_TEXTURE;
               break;
+            case eGpencilModifierType_Weight:
+              data.icon = ICON_MOD_VERTEX_WEIGHT;
+              break;
 
               /* Default */
             default:
diff --git a/source/blender/gpencil_modifiers/CMakeLists.txt b/source/blender/gpencil_modifiers/CMakeLists.txt
index f39306ac9d0..ec965c9a29f 100644
--- a/source/blender/gpencil_modifiers/CMakeLists.txt
+++ b/source/blender/gpencil_modifiers/CMakeLists.txt
@@ -68,6 +68,7 @@ set(SRC
   intern/MOD_gpencilthick.c
   intern/MOD_gpenciltime.c
   intern/MOD_gpenciltint.c
+  intern/MOD_gpencilweight.c
 
   MOD_gpencil_lineart.h
   MOD_gpencil_modifiertypes.h
diff --git a/source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h b/source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
index f8a28f2e5cb..18310bd5dff 100644
--- a/source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
+++ b/source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
@@ -44,6 +44,7 @@ extern GpencilModifierTypeInfo modifierType_Gpencil_Armature;
 extern GpencilModifierTypeInfo modifierType_Gpencil_Time;
 extern GpencilModifierTypeInfo modifierType_Gpencil_Multiply;
 extern GpencilModifierTypeInfo modifierType_Gpencil_Texture;
+extern GpencilModifierTypeInfo modifierType_Gpencil_Weight;
 extern GpencilModifierTypeInfo modifierType_Gpencil_Lineart;
 
 /* MOD_gpencil_util.c */
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
index 94285b5032e..a156fca5b7b 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
@@ -203,20 +203,6 @@ void gpencil_modifier_curve_panel_draw(const bContext *UNUSED(C), Panel *panel)
   uiTemplateCurveMapping(layout, ptr, "curve", 0, false, false, false, false);
 }
 
-void gpencil_modifier_fading_draw(const bContext *UNUSED(C), Panel *panel)
-{
-  PointerRNA *ptr = gpencil_modifier_panel_get_property_pointers(panel, NULL);
-
-  uiLayout *layout = panel->layout;
-  uiLayoutSetPropSep(layout, true);
-
-  uiItemR(layout, ptr, "object", 0, NULL, ICON_CUBE);
-  uiLayout *sub = uiLayoutColumn(layout, true);
-  uiItemR(sub, ptr, "fading_start", 0, NULL, ICON_NONE);
-  uiItemR(sub, ptr, "fading_end", 0, IFACE_("End"), ICON_NONE);
-  uiItemR(layout, ptr, "fading_end_factor", 0, NULL, ICON_NONE);
-}
-
 /**
  * Draw modifier error message.
  */
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.h b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.h
index 75907aaa781..782b36d47ed 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.h
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.h
@@ -37,8 +37,6 @@ void gpencil_modifier_masking_panel_draw(Panel *panel, bool use_material, bool u
 void gpencil_modifier_curve_header_draw(const bContext *C, Panel *panel);
 void gpencil_modifier_curve_panel_draw(const bContext *C, Panel *panel);
 
-void gpencil_modifier_fading_draw(const bContext *UNUSED(C), Panel *panel);
-
 void gpencil_modifier_panel_end(struct uiLayout *layout, PointerRNA *ptr);
 
 struct PointerRNA *gpencil_modifier_panel_get_property_pointers(struct Panel *panel,
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
index b28a44a0521..6409c86b6e3 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
@@ -63,6 +63,7 @@ void gpencil_modifier_type_init(GpencilModifierTypeInfo *types[])
   INIT_GP_TYPE(Time);
   INIT_GP_TYPE(Multiply);
   INIT_GP_TYPE(Texture);
+  INIT_GP_TYPE(Weight);
   INIT_GP_TYPE(Lineart);
 #undef INIT_GP_TYPE
 }
@@ -152,16 +153,16 @@ float get_modifier_point_weight(MDeformVert *dvert, bool inverse, int def_nr)
   if ((dvert != NULL) && (def_nr != -1)) {
     MDeformWeight *dw = BKE_defvert_find_index(dvert, def_nr);
     weight = dw ? dw->weight : -1.0f;
-    if ((weight >= 0.0f) && (inverse == 1)) {
+    if ((weight >= 0.0f) && (inverse)) {
       return -1.0f;
     }
 
-    if ((weight < 0.0f) && (inverse == 0)) {
+    if ((weight < 0.0f) && (!inverse)) {
       return -1.0f;
     }
 
     /* if inverse, weight is always 1 */
-    if ((weight < 0.0f) && (inverse == 1)) {
+    if ((weight < 0.0f) && (inverse)) {
       return 1.0f;
     }
   }
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
index 9f03e493ea8..fb75b1e99ac 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
@@ -47,8 +47,6 @@
 #include "BKE_screen.h"
 
 #include "DEG_depsgraph.h"
-#include "DEG_depsgraph_build.h"
-#include "DEG_depsgraph_query.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
@@ -86,39 +84,6 @@ static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
   tgmd->curve_intensity = BKE_curvemapping_copy(gmd->curve_intensity);
 }
 
-static float give_opacity_fading_factor(OpacityGpencilModifierData *mmd,
-                                        Object *ob_this,
-                                        float *pos,
-                                        bool apply_obmat)
-{
-  float factor_depth = 1.0f;
-
-  if (((mmd->flag & GP_OPACITY_FADING) == 0) || ((mmd->object) == NULL)) {
-    return factor_depth;
-  }
-
-  float gvert[3];
-  if (apply_obmat) {
-    mul_v3_m4v3(gvert, ob_this->obmat, pos);
-  }
-  float dist = len_v3v3(mmd->object->obmat[3], gvert);
-  float fading_max = MAX2(mmd->fading_start, mmd->fading_end);
-  float fading_min = MIN2(mmd->fading_start, mmd->fading_end);
-
-  /* Better with ratiof() function from line art. */
-  if (dist > fading_max) {
-    factor_depth = 0.0f;
-  }
-  else if (dist <= fading_max && dist > fading_min) {
-    factor_depth = (fading_max - dist) / (fading_max - fading_min);
-  }
-  else {
-    factor_depth = 1.0f;
-  }
-
-  return factor_depth;
-}
-
 /* opacity strokes */
 static void deformStroke(GpencilModifierData *md,
                          Depsgraph *UNUSED(depsgraph),
@@ -130,6 +95,9 @@ static void deformStroke(GpencilModifierData *md,
   OpacityGpencilModifierData *mmd = (OpacityGpencilModifierData *)md;
   const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
   const bool use_curve = (mmd->flag & GP_OPACITY_CUSTOM_CURVE) != 0 && mmd->curve_intensity;
+  const bool is_normalized = (mmd->flag & GP_OPACITY_NORMALIZE);
+  bool is_inverted = ((mmd->flag & GP_OPACITY_WEIGHT_FACTOR) == 0) &&
+                     ((mmd->flag & GP_OPACITY_INVERT_VGROUP) != 0);
 
   if (!is_stroke_affected_by_modifier(ob,
                                       mmd->layername,
@@ -161,11 +129,17 @@ static void deformStroke(GpencilModifierData *md,
     /* Stroke using strength. */
     if (mmd->modify_color != GP_MODIFY_COLOR_FILL) {
       /* verify vertex group */
-      float weight = get_modifier_point_weight(
-          dvert, (mmd->flag & GP_OPACITY_INVERT_VGROUP) != 0, def_nr);
+      float weight = get_modifier_point_weight(dvert, is_inverted, def_nr);
       if (weight < 0.0f) {
         continue;
       }
+
+      /* Apply weight directly. */
+      if ((mmd->flag & GP_OPACITY_WEIGHT_FACTOR) && (!is_normalized)) {
+        pt->strength *= ((mmd->flag & GP_OPACITY_INVERT_VGROUP) ? 1.0f - weight : weight);
+        continue;
+      }
+
       /* Custom curve to modulate value. */
       float factor_curve = mmd->factor;
       if (use_curve) {
@@ -173,9 +147,6 @@ static void deformStroke(GpencilModifierData *md,
         factor_curve *= BKE_curvemapping_evaluateF(mmd->curve_intensity, 0, value);
       }
 
-      float factor_depth = give_opacity_fading_factor(mmd, ob, &pt->x, true);
-      factor_curve = interpf(factor_curve, mmd->fading_end_factor, factor_depth);
-
       if (def_nr < 0) {
         if (mmd->flag & GP_OPACITY_NORMALIZE) {
           pt->strength = factor_curve;
@@ -204,9 +175,19 @@ static void deformStroke(GpencilModifierData *md,
 
   /* Fill using opacity factor. */
   if (mmd->modify_color != GP_MODIFY_COLOR_STROKE) {
-    float factor_depth = give_opacity_fading_factor(mmd, ob, ob->obmat[3], true);
-    gps->fill_opacity_fac = interpf(mmd->factor, mmd->fading_end_factor, factor_depth);
+    float fill_factor = mmd->factor;
 
+    if ((mmd->flag & GP_OPACITY_WEIGHT_FACTOR) && (!is_normalized)) {
+      /* Use first point for weight. */
+      MDeformVert *dvert = (gps->dvert != NULL) ? &gps->dvert[0] : NULL;
+      float weight = get_modifier_point_weight(
+          dvert, (mmd->flag & GP_OPACITY_INVERT_VGROUP) != 0, def_nr);
+      if (weight >= 0.0f) {
+        fill_factor = ((mmd->flag & GP_OPACITY_INVERT_VGROUP) ? 1.0f - weight : weight);
+      }
+    }
+
+    gps->fill_opacity_fac = fill_factor;
     CLAMP(gps->fill_opacity_fac, 0.0f, 1.0f);
   }
 }
@@ -241,18 +222,6 @@ static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk,
   OpacityGpencilModifierData *mmd = (OpacityGpencilModifierData *)md;
 
   walk(userData, ob, (ID **)&mmd->material, IDWALK_CB_USER);
-  walk(userData, ob, (ID **)&mmd->object, IDWALK_CB_NOP);
-}
-
-static void updateDepsgraph(GpencilModifierData *md,
-                            const ModifierUpdateDepsgraphContext *ctx,
-                            const int UNUSED(mode))
-{
-  OpacityGpencilModifierData *mmd = (OpacityGpencilModifierData *)md;
-  if (mmd->object != NULL) {
-    DEG_add_object_relation(ctx->node, mmd->object, DEG_OB_COMP_TRANSFORM, "Opacity Modifier");
-  }
-  DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "O

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list