diff options
Diffstat (limited to 'source')
3 files changed, 63 insertions, 21 deletions
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)); + } } } } diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h index f094d630fc8..7d407dc85bc 100644 --- a/source/blender/makesdna/DNA_gpencil_modifier_types.h +++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h @@ -200,6 +200,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. */ @@ -274,7 +279,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 0b40cc9f7f9..f4458a49768 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", ""}, @@ -1164,6 +1174,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"); |