[Bf-blender-cvs] [366663e47b1] greasepencil-refactor: GPencil: Convert Vertex Color to Linear from Palette or Brush color
Antonio Vazquez
noreply at git.blender.org
Mon Jan 20 13:28:50 CET 2020
Commit: 366663e47b1757d3a4b59ec15795f5053b40eff1
Author: Antonio Vazquez
Date: Mon Jan 20 13:16:28 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB366663e47b1757d3a4b59ec15795f5053b40eff1
GPencil: Convert Vertex Color to Linear from Palette or Brush color
Grease pencil works in linear, but the brushes and palettes no.
===================================================================
M source/blender/editors/gpencil/gpencil_fill.c
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/gpencil/gpencil_primitive.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index aceea646650..47778a99442 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -1094,11 +1094,8 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
copy_v2_v2(gps->gradient_s, brush->gpencil_settings->gradient_s);
gps->inittime = 0.0f;
- /* Apply the mix color to fill. */
- if (GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush)) {
- copy_v3_v3(gps->vert_color_fill, brush->rgb);
- gps->vert_color_fill[3] = brush->gpencil_settings->vertex_factor;
- }
+ /* Apply the vertex color to fill. */
+ ED_gpencil_fill_vertex_color_set(ts, brush, gps);
/* the polygon must be closed, so enabled cyclic */
gps->flag |= GP_STROKE_CYCLIC;
@@ -1152,11 +1149,8 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
pt->strength = 1.0f;
pt->time = 0.0f;
- /* Point mix color. */
- copy_v3_v3(pt->vert_color, brush->rgb);
- pt->vert_color[3] = GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush) ?
- brush->gpencil_settings->vertex_factor :
- 0.0f;
+ /* Apply the vertex color to point. */
+ ED_gpencil_point_vertex_color_set(ts, brush, pt);
if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) {
MDeformWeight *dw = defvert_verify_index(dvert, def_nr);
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index bf3a3e9d39f..158f00c698e 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -927,11 +927,8 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
dvert = gps->dvert + (gps->totpoints - totelem);
}
- /* Apply the mix color to fill for stroke. */
- if (GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush)) {
- copy_v3_v3(gps->vert_color_fill, brush->rgb);
- gps->vert_color_fill[3] = brush->gpencil_settings->vertex_factor;
- }
+ /* Apply the vertex color to fill. */
+ ED_gpencil_fill_vertex_color_set(ts, brush, gps);
/* copy points from the buffer to the stroke */
if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
@@ -947,11 +944,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_v3_v3(pt->vert_color, brush->rgb);
- pt->vert_color[3] = GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush) ?
- brush->gpencil_settings->vertex_factor :
- 0.0f;
+ /* Apply the vertex color to point. */
+ ED_gpencil_point_vertex_color_set(ts, brush, pt);
pt++;
@@ -983,11 +977,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_v3_v3(pt->vert_color, brush->rgb);
- pt->vert_color[3] = GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush) ?
- brush->gpencil_settings->vertex_factor :
- 0.0f;
+ /* Apply the vertex color to point. */
+ ED_gpencil_point_vertex_color_set(ts, brush, pt);
if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) {
BKE_gpencil_dvert_ensure(gps);
@@ -1109,11 +1100,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_v3_v3(pt->vert_color, brush->rgb);
- pt->vert_color[3] = GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush) ?
- brush->gpencil_settings->vertex_factor :
- 0.0f;
+ /* Apply the vertex color to point. */
+ ED_gpencil_point_vertex_color_set(ts, brush, pt);
if (dvert != NULL) {
dvert->totweight = 0;
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 052ba55460f..b90a52dfe9b 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -366,11 +366,8 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
gps->uv_scale = 1.0f;
gps->inittime = 0.0f;
- /* Apply the mix color to fill. */
- if (GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush)) {
- copy_v3_v3(gps->vert_color_fill, brush->rgb);
- gps->vert_color_fill[3] = brush->gpencil_settings->vertex_factor;
- }
+ /* Apply the vertex color to fill. */
+ ED_gpencil_fill_vertex_color_set(ts, brush, gps);
gps->flag &= ~GP_STROKE_SELECT;
/* the polygon must be closed, so enabled cyclic */
@@ -1047,11 +1044,8 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
pt->time = 0.0f;
pt->flag = 0;
pt->uv_fac = tpt->uv_fac;
- /* Point mix color. */
- copy_v3_v3(pt->vert_color, brush->rgb);
- pt->vert_color[3] = GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush) ?
- brush->gpencil_settings->vertex_factor :
- 0.0f;
+ /* Apply the vertex color to point. */
+ ED_gpencil_point_vertex_color_set(ts, brush, pt);
if (gps->dvert != NULL) {
MDeformVert *dvert = &gps->dvert[i];
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index ab3394c2e92..b1a9484d5de 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2550,3 +2550,27 @@ void ED_gpencil_tag_scene_gpencil(Scene *scene)
WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL);
}
+
+void ED_gpencil_fill_vertex_color_set(ToolSettings *ts, Brush *brush, bGPDstroke *gps)
+{
+ if (GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush)) {
+ copy_v3_v3(gps->vert_color_fill, brush->rgb);
+ gps->vert_color_fill[3] = brush->gpencil_settings->vertex_factor;
+ srgb_to_linearrgb_v4(gps->vert_color_fill, gps->vert_color_fill);
+ }
+ else {
+ zero_v4(gps->vert_color_fill);
+ }
+}
+
+void ED_gpencil_point_vertex_color_set(ToolSettings *ts, Brush *brush, bGPDspoint *pt)
+{
+ if (GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush)) {
+ copy_v3_v3(pt->vert_color, brush->rgb);
+ pt->vert_color[3] = brush->gpencil_settings->vertex_factor;
+ srgb_to_linearrgb_v4(pt->vert_color, pt->vert_color);
+ }
+ else {
+ zero_v4(pt->vert_color);
+ }
+}
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index a458f1b3797..4e5f8f3d27a 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -42,6 +42,7 @@ struct Main;
struct RegionView3D;
struct ReportList;
struct Scene;
+struct ToolSettings;
struct ScrArea;
struct View3D;
struct ViewLayer;
@@ -242,10 +243,10 @@ void ED_gp_project_point_to_plane(const struct Scene *scene,
const int axis,
struct bGPDspoint *pt);
void ED_gpencil_drawing_reference_get(const struct Scene *scene,
- const struct Object *ob,
- struct bGPDlayer *gpl,
- char align_flag,
- float vec[3]);
+ const struct Object *ob,
+ struct bGPDlayer *gpl,
+ char align_flag,
+ float vec[3]);
void ED_gpencil_project_stroke_to_view(struct bContext *C,
struct bGPDlayer *gpl,
struct bGPDstroke *gps);
@@ -295,4 +296,12 @@ struct tGPspoint *ED_gpencil_sbuffer_ensure(struct tGPspoint *buffer_array,
/* Tag all scene grease pencil object to update. */
void ED_gpencil_tag_scene_gpencil(struct Scene *scene);
+/* Vertex color set. */
+void ED_gpencil_fill_vertex_color_set(struct ToolSettings *ts,
+ struct Brush *brush,
+ struct bGPDstroke *gps);
+void ED_gpencil_point_vertex_color_set(struct ToolSettings *ts,
+ struct Brush *brush,
+ struct bGPDspoint *pt);
+
#endif /* __ED_GPENCIL_H__ */
More information about the Bf-blender-cvs
mailing list