From 29f3af95272590d26f610ae828b2eeee89c82a00 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Mon, 9 Mar 2020 16:27:24 +0100 Subject: GPencil: Refactor of Draw Engine, Vertex Paint and all internal functions This commit is a full refactor of the grease pencil modules including Draw Engine, Modifiers, VFX, depsgraph update, improvements in operators and conversion of Sculpt and Weight paint tools to real brushes. Also, a huge code cleanup has been done at all levels. Thanks to @fclem for his work and yo @pepeland and @mendio for the testing and help in the development. Differential Revision: https://developer.blender.org/D6293 --- .../gpencil_modifiers/intern/MOD_gpenciltint.c | 116 +++++++++++++-------- 1 file changed, 70 insertions(+), 46 deletions(-) (limited to 'source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c') diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c index 8f3956276dd..96f1f004812 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c @@ -26,7 +26,6 @@ #include "BLI_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_ghash.h" #include "BLI_math_vector.h" #include "DNA_scene_types.h" @@ -34,6 +33,7 @@ #include "DNA_gpencil_types.h" #include "DNA_gpencil_modifier_types.h" +#include "BKE_colortools.h" #include "BKE_gpencil.h" #include "BKE_gpencil_modifier.h" #include "BKE_material.h" @@ -52,13 +52,28 @@ static void initData(GpencilModifierData *md) gpmd->layername[0] = '\0'; gpmd->materialname[0] = '\0'; ARRAY_SET_ITEMS(gpmd->rgb, 1.0f, 1.0f, 1.0f); - gpmd->flag |= GP_TINT_CREATE_COLORS; gpmd->modify_color = GP_MODIFY_COLOR_BOTH; + + gpmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + if (gpmd->curve_intensity) { + CurveMapping *curve = gpmd->curve_intensity; + BKE_curvemapping_initialize(curve); + } } static void copyData(const GpencilModifierData *md, GpencilModifierData *target) { + TintGpencilModifierData *gmd = (TintGpencilModifierData *)md; + TintGpencilModifierData *tgmd = (TintGpencilModifierData *)target; + + if (tgmd->curve_intensity != NULL) { + BKE_curvemapping_free(tgmd->curve_intensity); + tgmd->curve_intensity = NULL; + } + BKE_gpencil_modifier_copyData_generic(md, target); + + tgmd->curve_intensity = BKE_curvemapping_copy(gmd->curve_intensity); } /* tint strokes */ @@ -70,6 +85,7 @@ static void deformStroke(GpencilModifierData *md, bGPDstroke *gps) { TintGpencilModifierData *mmd = (TintGpencilModifierData *)md; + const bool use_curve = (mmd->flag & GP_TINT_CUSTOM_CURVE) != 0 && mmd->curve_intensity; if (!is_stroke_affected_by_modifier(ob, mmd->layername, @@ -86,69 +102,77 @@ static void deformStroke(GpencilModifierData *md, return; } - if (mmd->modify_color != GP_MODIFY_COLOR_FILL) { - interp_v3_v3v3( - gps->runtime.tmp_stroke_rgba, gps->runtime.tmp_stroke_rgba, mmd->rgb, mmd->factor); - /* if factor is > 1, the alpha must be changed to get full tint */ - if (mmd->factor > 1.0f) { - gps->runtime.tmp_stroke_rgba[3] += mmd->factor - 1.0f; + MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 1); + + /* if factor > 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); } - CLAMP4(gps->runtime.tmp_stroke_rgba, 0.0f, 1.0f); } + /* Apply to Vertex Color. */ + float mixfac = mmd->factor; + + CLAMP(mixfac, 0.0, 1.0f); + /* Fill */ if (mmd->modify_color != GP_MODIFY_COLOR_STROKE) { - interp_v3_v3v3(gps->runtime.tmp_fill_rgba, gps->runtime.tmp_fill_rgba, mmd->rgb, mmd->factor); - /* if factor is > 1, the alpha must be changed to get full tint */ - if (mmd->factor > 1.0f && gps->runtime.tmp_fill_rgba[3] > 1e-5) { - gps->runtime.tmp_fill_rgba[3] += mmd->factor - 1.0f; + /* If not using Vertex Color, use the material color. */ + if ((gp_style != NULL) && (gps->vert_color_fill[3] == 0.0f) && + (gp_style->fill_rgba[3] > 0.0f)) { + copy_v4_v4(gps->vert_color_fill, gp_style->fill_rgba); + gps->vert_color_fill[3] = 1.0f; } - CLAMP4(gps->runtime.tmp_fill_rgba, 0.0f, 1.0f); + + interp_v3_v3v3(gps->vert_color_fill, gps->vert_color_fill, mmd->rgb, mixfac); } - /* if factor > 1.0, affect the strength of the stroke */ - if (mmd->factor > 1.0f) { + /* Stroke */ + if (mmd->modify_color != GP_MODIFY_COLOR_FILL) { 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); + /* If not using Vertex Color, use the material color. */ + if ((gp_style != NULL) && (pt->vert_color[3] == 0.0f) && (gp_style->stroke_rgba[3] > 0.0f)) { + copy_v4_v4(pt->vert_color, gp_style->stroke_rgba); + pt->vert_color[3] = 1.0f; + } + + /* Custom curve to modulate value. */ + float mixvalue = mixfac; + if (use_curve) { + float value = (float)i / (gps->totpoints - 1); + mixvalue *= BKE_curvemapping_evaluateF(mmd->curve_intensity, 0, value); + } + + interp_v3_v3v3(pt->vert_color, pt->vert_color, mmd->rgb, mixvalue); } } } -static void bakeModifier(Main *bmain, Depsgraph *depsgraph, GpencilModifierData *md, Object *ob) +static void bakeModifier(Main *UNUSED(bmain), + Depsgraph *depsgraph, + GpencilModifierData *md, + Object *ob) { - TintGpencilModifierData *mmd = (TintGpencilModifierData *)md; bGPdata *gpd = ob->data; - GHash *gh_color = BLI_ghash_str_new("GP_Tint modifier"); - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { - for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { - for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { - - Material *mat = BKE_gpencil_material(ob, gps->mat_nr + 1); - if (mat == NULL) { - continue; - } - MaterialGPencilStyle *gp_style = mat->gp_style; - /* skip stroke if it doesn't have color info */ - if (ELEM(NULL, gp_style)) { - continue; - } - - copy_v4_v4(gps->runtime.tmp_stroke_rgba, gp_style->stroke_rgba); - copy_v4_v4(gps->runtime.tmp_fill_rgba, gp_style->fill_rgba); - + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { deformStroke(md, depsgraph, ob, gpl, gpf, gps); - - gpencil_apply_modifier_material( - bmain, ob, mat, gh_color, gps, (bool)(mmd->flag & GP_TINT_CREATE_COLORS)); } } } - /* free hash buffers */ - if (gh_color) { - BLI_ghash_free(gh_color, NULL, NULL); - gh_color = NULL; +} + +static void freeData(GpencilModifierData *md) +{ + TintGpencilModifierData *gpmd = (TintGpencilModifierData *)md; + + if (gpmd->curve_intensity) { + BKE_curvemapping_free(gpmd->curve_intensity); } } @@ -167,7 +191,7 @@ GpencilModifierTypeInfo modifierType_Gpencil_Tint = { /* remapTime */ NULL, /* initData */ initData, - /* freeData */ NULL, + /* freeData */ freeData, /* isDisabled */ NULL, /* updateDepsgraph */ NULL, /* dependsOnTime */ NULL, -- cgit v1.2.3