From 591db72ee2ee4c731968754f0be288e9222c012d Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Mon, 2 Sep 2019 13:31:05 +0200 Subject: GPencil: New Strength mode for Opacity modifier This new option applies the opacity using the strength of the stroke instead to use the alpha channel of the material. Tested in greasepencil-object branch {F7712796} The vertex group filter has been removed because this filter is not logic in Material mode and must be valid only in Strength mode. {F7713147} Reviewers: pepeland, mendio Reviewed By: mendio Differential Revision: https://developer.blender.org/D5650 --- .../gpencil_modifiers/intern/MOD_gpencilopacity.c | 60 ++++++++++++++-------- 1 file changed, 40 insertions(+), 20 deletions(-) (limited to 'source/blender/gpencil_modifiers/intern') diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c index c2ab672b68b..22610771045 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c @@ -89,38 +89,56 @@ 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]; + pt->strength += mmd->factor - 1.0f; + 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; /* verify vertex group */ - const float weight = get_modifier_point_weight( + 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 { - pt->strength += (mmd->factor - 1.0f) * weight; + /* 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); } @@ -152,8 +170,10 @@ static void bakeModifier(Main *bmain, Depsgraph *depsgraph, GpencilModifierData deformStroke(md, depsgraph, ob, gpl, gpf, gps); - gpencil_apply_modifier_material( - bmain, ob, mat, gh_color, gps, (bool)(mmd->flag & GP_OPACITY_CREATE_COLORS)); + if (mmd->opacity_mode == GP_OPACITY_MODE_MATERIAL) { + gpencil_apply_modifier_material( + bmain, ob, mat, gh_color, gps, (bool)(mmd->flag & GP_OPACITY_CREATE_COLORS)); + } } } } -- cgit v1.2.3