[Bf-blender-cvs] [63797f217c3] greasepencil-object: GPencil: Add Mix color to paint operators

Antonio Vazquez noreply at git.blender.org
Thu Oct 31 17:01:13 CET 2019


Commit: 63797f217c3fd163d1f1ac136082c6e4cd45d232
Author: Antonio Vazquez
Date:   Thu Oct 31 16:48:26 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB63797f217c3fd163d1f1ac136082c6e4cd45d232

GPencil: Add Mix color to paint operators

===================================================================

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index b445c9b3aa1..686ec673f96 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -346,6 +346,8 @@ class _draw_tool_settings_context_mode:
             )
 
             row.prop(gp_settings, "use_material_pin", text="")
+            row.separator(factor=0.4)
+            row.prop(gp_settings, "mix_color", text="")
 
         row = layout.row(align=True)
         tool_settings = context.scene.tool_settings
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 8006c784190..402f4f496db 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -141,9 +141,12 @@ void gpencil_get_point_geom(GpencilBatchCacheElem *be,
                             bGPDstroke *gps,
                             short thickness,
                             const float ink[4],
-                            const int alignment_mode)
+                            const int alignment_mode,
+                            const bool onion)
 {
+  float mix[4];
   int totvertex = gps->totpoints;
+
   if (be->vbo == NULL) {
     gpencil_elem_format_ensure(be);
     be->pos_id = GPU_vertformat_attr_add(be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
@@ -170,6 +173,11 @@ void gpencil_get_point_geom(GpencilBatchCacheElem *be,
     /* set point */
     alpha = ink[3] * pt->strength;
     CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f);
+    /* Apply the mix color. */
+    if (!onion) {
+      interp_v3_v3v3(ink, ink, pt->mix_color, pt->mix_color[3]);
+    }
+
     ARRAY_SET_ITEMS(col, ink[0], ink[1], ink[2], alpha);
 
     float thick = max_ff(pt->pressure * thickness, 1.0f);
@@ -222,13 +230,15 @@ void gpencil_get_point_geom(GpencilBatchCacheElem *be,
 void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
                              bGPDstroke *gps,
                              short thickness,
-                             const float ink[4])
+                             const float ink[4],
+                             const bool onion)
 {
   bGPDspoint *points = gps->points;
   int totpoints = gps->totpoints;
   /* if cyclic needs more vertex */
   int cyclic_add = (gps->flag & GP_STROKE_CYCLIC) ? 1 : 0;
   int totvertex = totpoints + cyclic_add + 2;
+  float mix_color[4];
 
   if (be->vbo == NULL) {
     gpencil_elem_format_ensure(be);
@@ -248,6 +258,12 @@ void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
   /* draw stroke curve */
   const bGPDspoint *pt = points;
   for (int i = 0; i < totpoints; i++, pt++) {
+    /* Apply the mix color. */
+    copy_v4_v4(mix_color, ink);
+    if (!onion) {
+      interp_v3_v3v3(mix_color, ink, pt->mix_color, pt->mix_color[3]);
+    }
+
     /* first point for adjacency (not drawn) */
     if (i == 0) {
       if (gps->flag & GP_STROKE_CYCLIC && totpoints > 2) {
@@ -259,7 +275,7 @@ void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
                                  be->thickness_id,
                                  be->uvdata_id,
                                  thickness,
-                                 ink);
+                                 mix_color);
         be->vbo_len++;
       }
       else {
@@ -271,7 +287,7 @@ void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
                                  be->thickness_id,
                                  be->uvdata_id,
                                  thickness,
-                                 ink);
+                                 mix_color);
         be->vbo_len++;
       }
     }
@@ -284,7 +300,7 @@ void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
                              be->thickness_id,
                              be->uvdata_id,
                              thickness,
-                             ink);
+                             mix_color);
     be->vbo_len++;
   }
 
@@ -298,7 +314,7 @@ void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
                              be->thickness_id,
                              be->uvdata_id,
                              thickness,
-                             ink);
+                             mix_color);
     be->vbo_len++;
     /* now add adjacency point (not drawn) */
     gpencil_set_stroke_point(be->vbo,
@@ -309,7 +325,7 @@ void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
                              be->thickness_id,
                              be->uvdata_id,
                              thickness,
-                             ink);
+                             mix_color);
     be->vbo_len++;
   }
   /* last adjacency point (not drawn) */
@@ -322,7 +338,7 @@ void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
                              be->thickness_id,
                              be->uvdata_id,
                              thickness,
-                             ink);
+                             mix_color);
     be->vbo_len++;
   }
 }
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 1d0972c2765..fc5097a9e7e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -1075,7 +1075,7 @@ static void gpencil_add_stroke_vertexdata(GpencilBatchCache *cache,
     if ((gps->totpoints > 1) && (gp_style->mode == GP_STYLE_MODE_LINE)) {
       /* create vertex data */
       const int old_len = cache->b_stroke.vbo_len;
-      gpencil_get_stroke_geom(&cache->b_stroke, gps, sthickness, ink);
+      gpencil_get_stroke_geom(&cache->b_stroke, gps, sthickness, ink, onion);
 
       /* add to list of groups */
       if (old_len < cache->b_stroke.vbo_len) {
@@ -1093,7 +1093,7 @@ static void gpencil_add_stroke_vertexdata(GpencilBatchCache *cache,
     else {
       /* create vertex data */
       const int old_len = cache->b_point.vbo_len;
-      gpencil_get_point_geom(&cache->b_point, gps, sthickness, ink, alignment_mode);
+      gpencil_get_point_geom(&cache->b_point, gps, sthickness, ink, alignment_mode, onion);
 
       /* add to list of groups */
       if (old_len < cache->b_point.vbo_len) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 36bc205f41a..de56ebb3851 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -427,11 +427,13 @@ void gpencil_get_point_geom(struct GpencilBatchCacheElem *be,
                             struct bGPDstroke *gps,
                             short thickness,
                             const float ink[4],
-                            const int follow_mode);
+                            const int follow_mode,
+                            const bool onion);
 void gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
                              struct bGPDstroke *gps,
                              short thickness,
-                             const float ink[4]);
+                             const float ink[4],
+                             const bool onion);
 void gpencil_get_fill_geom(struct GpencilBatchCacheElem *be,
                            struct Object *ob,
                            struct bGPDstroke *gps,
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 1eb1c2b13b1..24dacc50dd4 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1002,6 +1002,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
       pt->strength = ptc->strength;
       CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
       pt->time = ptc->time;
+      /* Point mix color. */
+      copy_v4_v4(pt->mix_color, brush->gpencil_settings->mix_color);
+
       pt++;
 
       if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) {
@@ -1032,6 +1035,8 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
       pt->strength = ptc->strength;
       CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
       pt->time = ptc->time;
+      /* Point mix color. */
+      copy_v4_v4(pt->mix_color, brush->gpencil_settings->mix_color);
 
       if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) {
         BKE_gpencil_dvert_ensure(gps);
@@ -1153,6 +1158,8 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
       pt->time = ptc->time;
       pt->uv_fac = ptc->uv_fac;
       pt->uv_rot = ptc->uv_rot;
+      /* Point mix color. */
+      copy_v4_v4(pt->mix_color, brush->gpencil_settings->mix_color);
 
       if (dvert != NULL) {
         dvert->totweight = 0;
@@ -1855,6 +1862,12 @@ static void gp_init_colors(tGPsdata *p)
     gpd->runtime.mode = (short)gp_style->mode;
     gpd->runtime.bstroke_style = gp_style->stroke_style;
     gpd->runtime.bfill_style = gp_style->fill_style;
+
+    /* Apply the mix color to stroke. */
+    interp_v3_v3v3(gpd->runtime.scolor,
+                   gpd->runtime.scolor,
+                   brush->gpencil_settings->mix_color,
+                   brush->gpencil_settings->mix_color[3]);
   }
 }
 
@@ -2507,7 +2520,6 @@ static void gpencil_draw_status_indicators(bContext *C, tGPsdata *p)
 
 /* ------------------------------- */
 
-
 /* Helper to rotate point around origin */
 static void gp_rotate_v2_v2v2fl(float v[2],
                                 const float p[2],
@@ -2769,7 +2781,6 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra
   }
 }
 
-
 /* handle draw event */
 static void gpencil_draw_apply_event(bContext *C,
                                      wmOperator *op,
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 8bad7edc831..86d307a2fdf 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -159,6 +159,12

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list