[Bf-blender-cvs] [35af94cc869] greasepencil-object: GPencil: New Strength mode for Opacity modifier

Antonioya noreply at git.blender.org
Thu Jul 18 18:08:12 CEST 2019


Commit: 35af94cc8697e8bdf5e8f082558e249e56450b9c
Author: Antonioya
Date:   Thu Jul 18 18:07:34 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rB35af94cc8697e8bdf5e8f082558e249e56450b9c

GPencil: New Strength mode for Opacity modifier

Now it's possible to determine the opacity by Material (default) or by point Strength.

This new mode is required to get some effects using weight data.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
M	source/blender/makesdna/DNA_gpencil_modifier_types.h
M	source/blender/makesrna/intern/rna_gpencil_modifier.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 0a4c166d0f7..9a4f35a8d73 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1950,9 +1950,13 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
         col.label(text="Opacity:")
         col.prop(md, "factor")
 
+        row = layout.row()
+        row.prop(md, "opacity_mode", text="Mode")
+
         row = layout.row()
         row.prop(md, "create_materials")
-        row.prop(md, "modify_color")
+        if md.opacity_mode == 'COLOR':
+            row.prop(md, "modify_color", text="Change")
 
         col = layout.column()
         col.separator()
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
index 587cf527118..c2b3ae5f15b 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
@@ -85,26 +85,46 @@ static void deformStroke(GpencilModifierData *md,
     return;
   }
 
-  if (mmd->modify_color != GP_MODIFY_COLOR_FILL) {
-    gps->runtime.tmp_stroke_rgba[3] *= mmd->factor;
-    /* if factor is > 1, then force opacity */
-    if (mmd->factor > 1.0f) {
-      gps->runtime.tmp_stroke_rgba[3] += mmd->factor - 1.0f;
+  if (mmd->opacity_mode == GP_OPACITY_MODE_MATERIAL) {
+    if (mmd->modify_color != GP_MODIFY_COLOR_FILL) {
+      gps->runtime.tmp_stroke_rgba[3] *= mmd->factor;
+      /* if factor is > 1, then force opacity */
+      if (mmd->factor > 1.0f) {
+        gps->runtime.tmp_stroke_rgba[3] += mmd->factor - 1.0f;
+      }
+      CLAMP(gps->runtime.tmp_stroke_rgba[3], 0.0f, 1.0f);
     }
-    CLAMP(gps->runtime.tmp_stroke_rgba[3], 0.0f, 1.0f);
-  }
 
-  if (mmd->modify_color != GP_MODIFY_COLOR_STROKE) {
-    gps->runtime.tmp_fill_rgba[3] *= mmd->factor;
-    /* if factor is > 1, then force opacity */
-    if (mmd->factor > 1.0f && gps->runtime.tmp_fill_rgba[3] > 1e-5) {
-      gps->runtime.tmp_fill_rgba[3] += mmd->factor - 1.0f;
+    if (mmd->modify_color != GP_MODIFY_COLOR_STROKE) {
+      gps->runtime.tmp_fill_rgba[3] *= mmd->factor;
+      /* if factor is > 1, then force opacity */
+      if (mmd->factor > 1.0f && gps->runtime.tmp_fill_rgba[3] > 1e-5) {
+        gps->runtime.tmp_fill_rgba[3] += mmd->factor - 1.0f;
+      }
+      CLAMP(gps->runtime.tmp_fill_rgba[3], 0.0f, 1.0f);
     }
-    CLAMP(gps->runtime.tmp_fill_rgba[3], 0.0f, 1.0f);
-  }
 
-  /* if opacity > 1.0, affect the strength of the stroke */
-  if (mmd->factor > 1.0f) {
+    /* if opacity > 1.0, affect the strength of the stroke */
+    if (mmd->factor > 1.0f) {
+      for (int i = 0; i < gps->totpoints; i++) {
+        bGPDspoint *pt = &gps->points[i];
+        MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
+
+        /* verify vertex group */
+        const float weight = get_modifier_point_weight(
+            dvert, (mmd->flag & GP_OPACITY_INVERT_VGROUP) != 0, def_nr);
+        if (weight < 0.0f) {
+          pt->strength += mmd->factor - 1.0f;
+        }
+        else {
+          pt->strength += (mmd->factor - 1.0f) * weight;
+        }
+        CLAMP(pt->strength, 0.0f, 1.0f);
+      }
+    }
+  }
+  /* Apply opacity by strength */
+  else {
     for (int i = 0; i < gps->totpoints; i++) {
       bGPDspoint *pt = &gps->points[i];
       MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h
index 8b756ff2937..ab6ab3526f5 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_types.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h
@@ -199,6 +199,11 @@ typedef enum eModifyColorGpencil_Flag {
   GP_MODIFY_COLOR_FILL = 2,
 } eModifyColorGpencil_Flag;
 
+typedef enum eOpacityModesGpencil_Flag {
+  GP_OPACITY_MODE_MATERIAL = 0,
+  GP_OPACITY_MODE_STRENGTH = 1,
+} eOpacityModesGpencil_Flag;
+
 typedef struct TintGpencilModifierData {
   GpencilModifierData modifier;
   /** Layer name. */
@@ -265,7 +270,9 @@ typedef struct OpacityGpencilModifierData {
   float factor;
   /** Modify stroke, fill or both. */
   char modify_color;
-  char _pad[3];
+  /** Mode of opacity, colors or strength */
+  char opacity_mode;
+  char _pad[2];
   /** Custom index for passes. */
   int layer_pass;
   char _pad1[4];
diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c
index 2b89225d34d..358562dec4e 100644
--- a/source/blender/makesrna/intern/rna_gpencil_modifier.c
+++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c
@@ -133,6 +133,16 @@ static const EnumPropertyItem modifier_modify_color_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+static const EnumPropertyItem modifier_opacity_mode_items[] = {
+    {GP_OPACITY_MODE_MATERIAL,
+     "MATERIAL",
+     0,
+     "Material",
+     "Modify opacity using alpha channel of material"},
+    {GP_OPACITY_MODE_STRENGTH, "STRENGTH", 0, "Strength", "Modify opacity using point strength"},
+    {0, NULL, 0, NULL, NULL},
+};
+
 static const EnumPropertyItem modifier_gphook_falloff_items[] = {
     {eGPHook_Falloff_None, "NONE", 0, "No Falloff", ""},
     {eGPHook_Falloff_Curve, "CURVE", 0, "Curve", ""},
@@ -1056,6 +1066,11 @@ static void rna_def_modifier_gpencilopacity(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Mode", "Set what colors of the stroke are affected");
   RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
 
+  prop = RNA_def_property(srna, "opacity_mode", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, modifier_opacity_mode_items);
+  RNA_def_property_ui_text(prop, "Opacity Mode", "Set what mode used to define opacity");
+  RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
+
   prop = RNA_def_property(srna, "layer", PROP_STRING, PROP_NONE);
   RNA_def_property_string_sdna(prop, NULL, "layername");
   RNA_def_property_ui_text(prop, "Layer", "Layer name");



More information about the Bf-blender-cvs mailing list