[Bf-blender-cvs] [52c68574866] greasepencil-refactor: GPencil: Fix Opacity modifier for Fill

Antonio Vazquez noreply at git.blender.org
Sun Jan 19 16:40:49 CET 2020


Commit: 52c68574866931835b0e52fdd3adfe03cdb21a0a
Author: Antonio Vazquez
Date:   Sun Jan 19 16:21:44 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB52c68574866931835b0e52fdd3adfe03cdb21a0a

GPencil: Fix Opacity modifier for Fill

Now the modifier is able to apply opacity to the Fill area as it was in previous versions.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
M	source/blender/draw/intern/draw_cache_impl_gpencil.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
M	source/blender/makesdna/DNA_gpencil_modifier_types.h
M	source/blender/makesdna/DNA_gpencil_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 133b567195e..e9d3f2c0073 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -2042,6 +2042,7 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
         col = split.column()
         col.label(text="Opacity:")
         col.prop(md, "factor")
+        col.prop(md, "modify_color", text="Change")
 
         col = layout.column()
         col.separator()
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 0f50d1d0161..a71735bea65 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -3810,6 +3810,9 @@ void BKE_gpencil_frame_original_pointers_update(const struct bGPDframe *gpf_orig
       if (gps_eval != NULL) {
         gps_eval->runtime.gps_orig = gps_orig;
 
+        /* Reset fill opacity. */
+        gps_eval->runtime.fill_opacity_fac = 1.0f;
+
         /* Assign original point pointer. */
         for (int i = 0; i < gps_orig->totpoints; i++) {
           bGPDspoint *pt_eval = &gps_eval->points[i];
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
index ed44d53140a..72327ccaeac 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -485,7 +485,21 @@ void fill_vertex()
     fill_col.a = 1.0;
   }
 
-  color_output(fill_col, fcol1, 1.0, mix_tex);
+  /* Decode fill opacity. */
+  vec4 fcol_decode = vec4(fcol1.rgb, floor(fcol1.a / 10.0));
+  float fill_opacity = fcol1.a - (fcol_decode.a * 10);
+  fcol_decode.a /= 10000.0f;
+
+  /* Apply opacity. */
+  fill_col.a *= fill_opacity;
+  /* If factor is > 1 force opacity. */
+  if (fill_opacity > 1.0) {
+    fill_col.a += fill_opacity - 1.0f;
+  }
+
+  fill_col.a = clamp(fill_col.a, 0.0, 1.0);
+
+  color_output(fill_col, fcol_decode, 1.0, mix_tex);
 
   matFlag = MATERIAL(m).flag & GP_FILL_FLAGS;
   matFlag |= m << GP_MATID_SHIFT;
diff --git a/source/blender/draw/intern/draw_cache_impl_gpencil.c b/source/blender/draw/intern/draw_cache_impl_gpencil.c
index 84c21cb4696..3158af5eab5 100644
--- a/source/blender/draw/intern/draw_cache_impl_gpencil.c
+++ b/source/blender/draw/intern/draw_cache_impl_gpencil.c
@@ -273,6 +273,12 @@ static void gpencil_buffer_add_point(gpStrokeVert *verts,
   copy_v2_v2(vert->uv_fill, pt->uv_fill);
   copy_v4_v4(col->vcol, pt->vert_color);
   copy_v4_v4(col->fcol, gps->vert_color_fill);
+
+  /* Encode fill opacity defined by opacity modifier in vertex color alpha. If
+   * no opacity modifier, the value will be always 1.0f. The opacity factor can be any
+   * value between 0.0f and 2.0f */
+  col->fcol[3] = (((int)(col->fcol[3] * 10000.0f)) * 10.0f) + gps->runtime.fill_opacity_fac;
+
   vert->strength = (round_cap0) ? pt->strength : -pt->strength;
   vert->u_stroke = pt->uv_fac;
   vert->stroke_id = gps->runtime.stroke_start;
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
index 2c5bd781784..423e04110b9 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
@@ -53,6 +53,7 @@ static void initData(GpencilModifierData *md)
   gpmd->layername[0] = '\0';
   gpmd->materialname[0] = '\0';
   gpmd->vgname[0] = '\0';
+  gpmd->modify_color = GP_MODIFY_COLOR_BOTH;
 }
 
 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
@@ -90,30 +91,38 @@ static void deformStroke(GpencilModifierData *md,
     bGPDspoint *pt = &gps->points[i];
     MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
 
-    /* verify vertex group */
-    float weight = get_modifier_point_weight(
-        dvert, (mmd->flag & GP_OPACITY_INVERT_VGROUP) != 0, def_nr);
-    if (weight < 0.0f) {
-      continue;
-    }
-    if (def_nr < 0) {
-      pt->strength += mmd->factor - 1.0f;
-    }
-    else {
-      /* High factor values, change weight too. */
-      if ((mmd->factor > 1.0f) && (weight < 1.0f)) {
-        weight += mmd->factor - 1.0f;
-        CLAMP(weight, 0.0f, 1.0f);
+    /* 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);
+      if (weight < 0.0f) {
+        continue;
+      }
+      if (def_nr < 0) {
+        pt->strength += mmd->factor - 1.0f;
       }
-      pt->strength += (mmd->factor - 1) * weight;
+      else {
+        /* High factor values, change weight too. */
+        if ((mmd->factor > 1.0f) && (weight < 1.0f)) {
+          weight += mmd->factor - 1.0f;
+          CLAMP(weight, 0.0f, 1.0f);
+        }
+        pt->strength += (mmd->factor - 1) * weight;
+      }
+      CLAMP(pt->strength, 0.0f, 1.0f);
     }
-    CLAMP(pt->strength, 0.0f, 1.0f);
+  }
+
+  /* Fill using opacity factor. */
+  if (mmd->modify_color != GP_MODIFY_COLOR_STROKE) {
+    gps->runtime.fill_opacity_fac = mmd->factor;
   }
 }
 
 static void bakeModifier(Main *bmain, Depsgraph *depsgraph, GpencilModifierData *md, Object *ob)
 {
-  bGPdata *gpd = (bGPdata *)ob->data;
+  bGPdata *gpd = ob->data;
 
   LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
     LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h
index 26d86b42aef..45e98c9f6e0 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_types.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h
@@ -277,7 +277,9 @@ typedef struct OpacityGpencilModifierData {
   int flag;
   /** Main Opacity factor. */
   float factor;
-  char _pad[4];
+  /** Modify stroke, fill or both. */
+  char modify_color;
+  char _pad[3];
   /** Custom index for passes. */
   int layer_pass;
   char _pad1[4];
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index dd84e5ca193..442a905c814 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -182,7 +182,8 @@ typedef struct bGPDstroke_Runtime {
   int stroke_start;
   /** Triangle offset in the ibo where this fill starts. */
   int fill_start;
-  int _pad[1];
+  /** Factor of opacity for Fill color (used by opacity modifier). */
+  float fill_opacity_fac;
 
   /** Original stroke (used to dereference evaluated data) */
   struct bGPDstroke *gps_orig;
diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c
index 42c3d5d8d11..fe5e8f5bdc1 100644
--- a/source/blender/makesrna/intern/rna_gpencil_modifier.c
+++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c
@@ -1175,6 +1175,11 @@ static void rna_def_modifier_gpencilopacity(BlenderRNA *brna)
   RNA_def_struct_sdna(srna, "OpacityGpencilModifierData");
   RNA_def_struct_ui_icon(srna, ICON_MOD_OPACITY);
 
+  prop = RNA_def_property(srna, "modify_color", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, modifier_modify_color_items); /* share the enum */
+  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, "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