[Bf-blender-cvs] [69b8215797d] greasepencil-object: GPencil: Add HSV randomness at Stroke level
Antonio Vazquez
noreply at git.blender.org
Mon Apr 20 22:24:34 CEST 2020
Commit: 69b8215797d7c8eddb2a1ab4bf634a589fae04b2
Author: Antonio Vazquez
Date: Mon Apr 20 22:24:25 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB69b8215797d7c8eddb2a1ab4bf634a589fae04b2
GPencil: Add HSV randomness at Stroke level
===================================================================
M release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M release/scripts/startup/bl_ui/space_view3d_toolbar.py
M source/blender/editors/gpencil/gpencil_intern.h
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
M source/blender/makesdna/DNA_brush_types.h
M source/blender/makesrna/intern/rna_brush.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 4562c4dee70..7960e38fdb8 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -79,9 +79,17 @@ def gpencil_active_brush_settings_simple(context, layout):
col = layout.column()
col.enabled = mode == 'VERTEXCOLOR'
- col.prop(brush, "random_hue_factor", slider=True)
- col.prop(brush, "random_saturation_factor", slider=True)
- col.prop(brush, "random_value_factor", slider=True)
+ row = col.row(align=True)
+ row.prop(gp_settings, "random_hue_factor", slider=True)
+ row.prop(gp_settings, "use_stroke_random_hue", text="", icon='MOD_THICKNESS')
+
+ row = col.row(align=True)
+ row.prop(gp_settings, "random_saturation_factor", slider=True)
+ row.prop(gp_settings, "use_stroke_random_sat", text="", icon='MOD_THICKNESS')
+
+ row = col.row(align=True)
+ row.prop(gp_settings, "random_value_factor", slider=True)
+ row.prop(gp_settings, "use_stroke_random_val", text="", icon='MOD_THICKNESS')
# XXX: To be replaced with active tools
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index cb5c6d8f305..96efbbcc1db 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1630,9 +1630,17 @@ class VIEW3D_PT_tools_grease_pencil_brush_random(View3DPanel, Panel):
col = layout.column()
col.enabled = mode == 'VERTEXCOLOR' and gp_settings.use_settings_random
col.separator()
- col.prop(gp_settings, "random_hue_factor", slider=True)
- col.prop(gp_settings, "random_saturation_factor", slider=True)
- col.prop(gp_settings, "random_value_factor", slider=True)
+ row = col.row(align=True)
+ row.prop(gp_settings, "random_hue_factor", slider=True)
+ row.prop(gp_settings, "use_stroke_random_hue", text="", icon='MOD_THICKNESS')
+
+ row = col.row(align=True)
+ row.prop(gp_settings, "random_saturation_factor", slider=True)
+ row.prop(gp_settings, "use_stroke_random_sat", text="", icon='MOD_THICKNESS')
+
+ row = col.row(align=True)
+ row.prop(gp_settings, "random_value_factor", slider=True)
+ row.prop(gp_settings, "use_stroke_random_val", text="", icon='MOD_THICKNESS')
# Grease Pencil drawingcurves
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 2fa79b6acfd..09fa367a933 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -230,6 +230,10 @@ typedef struct tGPDprimitive {
/** size in pixels for uv calculation */
float totpixlen;
+
+ /** Random vertex color by stroke */
+ float gps_random_color[3];
+
} tGPDprimitive;
/* Modal Operator Drawing Callbacks ------------------------ */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 6ea01831e6f..242c7361207 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -255,6 +255,10 @@ typedef struct tGPsdata {
tGPguide guide;
ReportList *reports;
+
+ /** Random vertex color by stroke */
+ float gps_random_color[3];
+
} tGPsdata;
/* ------ */
@@ -746,7 +750,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
/* Set vertex colors for buffer. */
ED_gpencil_sbuffer_vertex_color_set(
- p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material);
+ p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material, p->gps_random_color);
/* get pointer to destination point */
pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used);
@@ -3044,6 +3048,8 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
else {
p = op->customdata;
}
+ /* Init random vertex color. */
+ ED_gpencil_sbuffer_random_color(p->brush, event->mval, p->gps_random_color);
/* TODO: set any additional settings that we can take from the events?
* if eraser is on, draw radial aid */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index bd54ef70162..4cad3345099 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -125,7 +125,7 @@ static void gp_session_validatebuffer(tGPDprimitive *p)
/* Set vertex colors for buffer. */
ED_gpencil_sbuffer_vertex_color_set(
- p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material);
+ p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material, p->gps_random_color);
if (ELEM(p->type, GP_STROKE_BOX, GP_STROKE_CIRCLE)) {
gpd->runtime.sbuffer_sflag |= GP_STROKE_CYCLIC;
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index ef8cecffb99..004378c9d09 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2713,7 +2713,36 @@ void ED_gpencil_point_vertex_color_set(ToolSettings *ts,
}
}
-void ED_gpencil_sbuffer_vertex_color_random(bGPdata *gpd, Brush *brush, tGPspoint *tpt)
+void ED_gpencil_sbuffer_random_color(Brush *brush, const int mval[2], float r_value[3])
+{
+ /* Use mouse position to get randomness. */
+ int ix = mval[0] / 3;
+ int iy = mval[1];
+ int iz = ix + iy;
+ zero_v3(r_value);
+
+ BrushGpencilSettings *brush_settings = brush->gpencil_settings;
+ /* Apply random to Hue. */
+ if (brush_settings->random_hue > 0.0f) {
+ float rand = BLI_hash_int_01(BLI_hash_int_2d(ix, iy)) * 2.0f - 1.0f;
+ r_value[0] = rand * brush_settings->random_hue * 0.5f;
+ }
+ /* Apply random to Saturation. */
+ if (brush_settings->random_saturation > 0.0f) {
+ float rand = BLI_hash_int_01(BLI_hash_int_2d(iy, ix)) * 2.0f - 1.0f;
+ r_value[1] = rand * brush_settings->random_saturation;
+ }
+ /* Apply random to Value. */
+ if (brush_settings->random_value > 0.0f) {
+ float rand = BLI_hash_int_01(BLI_hash_int_2d(ix * iz, iy * iz)) * 2.0f - 1.0f;
+ r_value[2] = rand * brush_settings->random_value;
+ }
+}
+
+void ED_gpencil_sbuffer_vertex_color_random(bGPdata *gpd,
+ Brush *brush,
+ tGPspoint *tpt,
+ float random_color[3])
{
BrushGpencilSettings *brush_settings = brush->gpencil_settings;
if (brush_settings->flag & GP_BRUSH_GROUP_RANDOM) {
@@ -2727,18 +2756,34 @@ void ED_gpencil_sbuffer_vertex_color_random(bGPdata *gpd, Brush *brush, tGPspoin
/* Apply random to Hue. */
if (brush_settings->random_hue > 0.0f) {
- float rand = BLI_hash_int_01(BLI_hash_int_2d(ix, gpd->runtime.sbuffer_used)) * 2.0f - 1.0f;
- factor_value[0] = rand * brush_settings->random_hue * 0.5f;
+ if ((brush_settings->flag2 & GP_BRUSH_USE_HUE_AT_STROKE) == 0) {
+
+ float rand = BLI_hash_int_01(BLI_hash_int_2d(ix, gpd->runtime.sbuffer_used)) * 2.0f - 1.0f;
+ factor_value[0] = rand * brush_settings->random_hue * 0.5f;
+ }
+ else {
+ factor_value[0] = random_color[0];
+ }
}
/* Apply random to Saturation. */
if (brush_settings->random_saturation > 0.0f) {
- float rand = BLI_hash_int_01(BLI_hash_int_2d(iy, gpd->runtime.sbuffer_used)) * 2.0f - 1.0f;
- factor_value[1] = rand * brush_settings->random_saturation;
+ if ((brush_settings->flag2 & GP_BRUSH_USE_SAT_AT_STROKE) == 0) {
+ float rand = BLI_hash_int_01(BLI_hash_int_2d(iy, gpd->runtime.sbuffer_used)) * 2.0f - 1.0f;
+ factor_value[1] = rand * brush_settings->random_saturation;
+ }
+ else {
+ factor_value[1] = random_color[1];
+ }
}
/* Apply random to Value. */
if (brush_settings->random_value > 0.0f) {
- float rand = BLI_hash_int_01(BLI_hash_int_2d(iz, gpd->runtime.sbuffer_used)) * 2.0f - 1.0f;
- factor_value[2] = rand * brush_settings->random_value * 0.5f;
+ if ((brush_settings->flag2 & GP_BRUSH_USE_VAL_AT_STROKE) == 0) {
+ float rand = BLI_hash_int_01(BLI_hash_int_2d(iz, gpd->runtime.sbuffer_used)) * 2.0f - 1.0f;
+ factor_value[2] = rand * brush_settings->random_value;
+ }
+ else {
+ factor_value[2] = random_color[2];
+ }
}
rgb_to_hsv_v(tpt->vert_color, hsv);
add_v3_v3(hsv, factor_value);
@@ -2747,8 +2792,12 @@ void ED_gpencil_sbuffer_vertex_color_random(bGPdata *gpd, Brush *brush, tGPspoin
}
}
-void ED_gpencil_sbuffer_vertex_color_set(
- Depsgraph *depsgraph, Object *ob, ToolSettings *ts, Brush *brush, Material *material)
+void ED_gpencil_sbuffer_vertex_color_set(Depsgraph *depsgraph,
+ Object *ob,
+ ToolSettings *ts,
+ Brush *brush,
+ Material *material,
+ float random_color[3])
{
bGPdata *gpd = (bGPdata *)ob->data;
Object *ob_eval = (Object *)DEG_get_evaluated_id(depsgraph, &ob->id);
@@ -2781,7 +2830,7 @@ void ED_gpencil_sbuffer_vertex_color_set(
/* Random Color. */
if (brush_settings->flag & GP_BRUSH_GROUP_RANDOM) {
- ED_gpencil_sbuffer_vertex_color_random(gpd, brush, tpt);
+ ED_gpencil_sbuffer_vertex_color_random(gpd, brush, tpt, random_color);
}
/* Copy to eval data because paint operators don't tag refresh until end for speedup
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index c582421666a..a0fdcc46559 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -325,10 +325,13 @@ void ED_gpencil_sbuffer_vertex_color_set(struct Depsgraph *depsgraph,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list