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
This commit is contained in:
parent
a6816bf5db
commit
591db72ee2
|
@ -2012,15 +2012,19 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
|
|||
col.prop(md, "factor")
|
||||
|
||||
row = layout.row()
|
||||
row.prop(md, "create_materials")
|
||||
row.prop(md, "modify_color")
|
||||
row.prop(md, "opacity_mode", text="Mode")
|
||||
|
||||
col = layout.column()
|
||||
col.separator()
|
||||
col.label(text="Vertex Group:")
|
||||
row = col.row(align=True)
|
||||
row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
|
||||
row.prop(md, "invert_vertex", text="", icon='ARROW_LEFTRIGHT')
|
||||
if md.opacity_mode == 'MATERIAL':
|
||||
row = layout.row()
|
||||
row.prop(md, "create_materials")
|
||||
row.prop(md, "modify_color", text="Change")
|
||||
else:
|
||||
col = layout.column()
|
||||
col.separator()
|
||||
col.label(text="Vertex Group:")
|
||||
row = col.row(align=True)
|
||||
row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
|
||||
row.prop(md, "invert_vertex", text="", icon='ARROW_LEFTRIGHT')
|
||||
|
||||
col = layout.column()
|
||||
col.separator()
|
||||
|
|
|
@ -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->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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* if opacity > 1.0, affect the strength of the stroke */
|
||||
if (mmd->factor > 1.0f) {
|
||||
gps->runtime.tmp_stroke_rgba[3] += 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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
/* 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue