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:
authorAntonio Vazquez <blendergit@gmail.com>2021-07-02 13:04:07 +0300
committerAntonio Vazquez <blendergit@gmail.com>2021-07-02 13:04:07 +0300
commit29b65f5345128ee035599aa7233315a74fe6afe6 (patch)
tree7ba21663688b5eca67c1884a8da5e0aa9a125c64 /source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c
parent9f5c0ffb5ec293af2e4f003c2178d21e20805b47 (diff)
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
Diffstat (limited to 'source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c')
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c
index 4a6e3df59c7..358b5577b97 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c
@@ -127,6 +127,8 @@ static void deformStroke(GpencilModifierData *md,
const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
const bool use_curve = (mmd->flag & GP_TINT_CUSTOM_CURVE) != 0 && mmd->curve_intensity;
+ bool is_inverted = ((mmd->flag & GP_TINT_WEIGHT_FACTOR) == 0) &&
+ ((mmd->flag & GP_TINT_INVERT_VGROUP) != 0);
if (!is_stroke_affected_by_modifier(ob,
mmd->layername,
@@ -169,6 +171,17 @@ static void deformStroke(GpencilModifierData *md,
if (!fill_done) {
/* Apply to fill. */
if (mmd->mode != GPPAINT_MODE_STROKE) {
+ float fill_factor = mmd->factor;
+
+ /* Use weightened factor. */
+ if (mmd->flag & GP_TINT_WEIGHT_FACTOR) {
+ /* Use first point for weight. */
+ MDeformVert *dvert = (gps->dvert != NULL) ? &gps->dvert[0] : NULL;
+ float weight = get_modifier_point_weight(dvert, is_inverted, def_nr);
+ if (weight >= 0.0f) {
+ fill_factor = ((mmd->flag & GP_TINT_INVERT_VGROUP) ? 1.0f - weight : weight);
+ }
+ }
/* If not using Vertex Color, use the material color. */
if ((gp_style != NULL) && (gps->vert_color_fill[3] == 0.0f) &&
@@ -188,13 +201,13 @@ static void deformStroke(GpencilModifierData *md,
BKE_colorband_evaluate(mmd->colorband, mix_factor, coba_res);
interp_v3_v3v3(gps->vert_color_fill, gps->vert_color_fill, coba_res, mmd->factor);
- gps->vert_color_fill[3] = clamp_f(mmd->factor, 0.0f, 1.0f);
+ gps->vert_color_fill[3] = clamp_f(fill_factor, 0.0f, 1.0f);
}
else {
interp_v3_v3v3(gps->vert_color_fill,
gps->vert_color_fill,
mmd->rgb,
- clamp_f(mmd->factor, 0.0f, 1.0f));
+ clamp_f(fill_factor, 0.0f, 1.0f));
}
/* If no stroke, cancel loop. */
if (mmd->mode != GPPAINT_MODE_BOTH) {
@@ -207,11 +220,13 @@ static void deformStroke(GpencilModifierData *md,
/* Verify vertex group. */
if (mmd->mode != GPPAINT_MODE_FILL) {
- float weight = get_modifier_point_weight(
- dvert, (mmd->flag & GP_TINT_INVERT_VGROUP) != 0, def_nr);
+ float weight = get_modifier_point_weight(dvert, is_inverted, def_nr);
if (weight < 0.0f) {
continue;
}
+
+ float factor = mmd->factor;
+
/* Custom curve to modulate value. */
if (use_curve) {
float value = (float)i / (gps->totpoints - 1);
@@ -224,6 +239,12 @@ static void deformStroke(GpencilModifierData *md,
pt->vert_color[3] = 1.0f;
}
+ /* Apply weight directly. */
+ if (mmd->flag & GP_TINT_WEIGHT_FACTOR) {
+ factor = ((mmd->flag & GP_TINT_INVERT_VGROUP) ? 1.0f - weight : weight);
+ weight = 1.0f;
+ }
+
if (is_gradient) {
/* Calc world position of point. */
float pt_loc[3];
@@ -237,11 +258,11 @@ static void deformStroke(GpencilModifierData *md,
interp_v3_v3v3(pt->vert_color,
pt->vert_color,
coba_res,
- clamp_f(mmd->factor, 0.0f, 1.0f) * weight * coba_res[3]);
+ clamp_f(factor, 0.0f, 1.0f) * weight * coba_res[3]);
}
else {
interp_v3_v3v3(
- pt->vert_color, pt->vert_color, mmd->rgb, clamp_f(mmd->factor * weight, 0.0, 1.0f));
+ pt->vert_color, pt->vert_color, mmd->rgb, clamp_f(factor * weight, 0.0, 1.0f));
}
}
}
@@ -338,7 +359,15 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
uiLayoutSetPropSep(layout, true);
uiItemR(layout, ptr, "vertex_mode", 0, NULL, ICON_NONE);
- uiItemR(layout, ptr, "factor", 0, NULL, ICON_NONE);
+
+ const bool is_weighted = !RNA_boolean_get(ptr, "use_weight_factor");
+ uiLayout *row = uiLayoutRow(layout, true);
+ uiLayoutSetActive(row, is_weighted);
+ uiItemR(row, ptr, "factor", 0, NULL, ICON_NONE);
+ uiLayout *sub = uiLayoutRow(row, true);
+ uiLayoutSetActive(sub, true);
+ uiItemR(row, ptr, "use_weight_factor", 0, "", ICON_MOD_VERTEX_WEIGHT);
+
uiItemR(layout, ptr, "tint_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
if (tint_type == GP_TINT_UNIFORM) {