Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_paint.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c169
1 files changed, 120 insertions, 49 deletions
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 961c4e05a28..cb72553c68b 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 settings by stroke */
+ GpRandomSettings random_settings;
+
} tGPsdata;
/* ------ */
@@ -687,6 +691,78 @@ static void gp_smooth_segment(bGPdata *gpd, const float inf, int from_idx, int t
}
}
+static void gp_apply_randomness(tGPsdata *p,
+ BrushGpencilSettings *brush_settings,
+ tGPspoint *pt,
+ const bool press,
+ const bool strength,
+ const bool uv)
+{
+ bGPdata *gpd = p->gpd;
+ GpRandomSettings random_settings = p->random_settings;
+ float value = 0.0f;
+ /* Apply randomness to pressure. */
+ if ((brush_settings->draw_random_press > 0.0f) && (press)) {
+ if ((brush_settings->flag2 & GP_BRUSH_USE_PRESS_AT_STROKE) == 0) {
+ float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
+ value = 1.0 + rand * 2.0 * brush_settings->draw_random_press;
+ }
+ else {
+ value = 1.0 + random_settings.pressure * brush_settings->draw_random_press;
+ }
+
+ /* Apply random curve. */
+ if (brush_settings->flag2 & GP_BRUSH_USE_PRESSURE_RAND_PRESS) {
+ value *= BKE_curvemapping_evaluateF(
+ brush_settings->curve_rand_pressure, 0, random_settings.pen_press);
+ }
+
+ pt->pressure *= value;
+ CLAMP(pt->pressure, 0.1f, 1.0f);
+ }
+
+ /* Apply randomness to color strength. */
+ if ((brush_settings->draw_random_strength) && (strength)) {
+ if ((brush_settings->flag2 & GP_BRUSH_USE_STRENGTH_AT_STROKE) == 0) {
+ float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
+ value = 1.0 + rand * brush_settings->draw_random_strength;
+ }
+ else {
+ value = 1.0 + random_settings.strength * brush_settings->draw_random_strength;
+ }
+
+ /* Apply random curve. */
+ if (brush_settings->flag2 & GP_BRUSH_USE_STRENGTH_RAND_PRESS) {
+ value *= BKE_curvemapping_evaluateF(
+ brush_settings->curve_rand_pressure, 0, random_settings.pen_press);
+ }
+
+ pt->strength *= value;
+ CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
+ }
+
+ /* Apply randomness to uv texture rotation. */
+ if ((brush_settings->uv_random > 0.0f) && (uv)) {
+ if ((brush_settings->flag2 & GP_BRUSH_USE_UV_AT_STROKE) == 0) {
+ float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used)) * 2.0f -
+ 1.0f;
+ value = rand * M_PI_2 * brush_settings->uv_random;
+ }
+ else {
+ value = random_settings.uv * M_PI_2 * brush_settings->uv_random;
+ }
+
+ /* Apply random curve. */
+ if (brush_settings->flag2 & GP_BRUSH_USE_UV_RAND_PRESS) {
+ value *= BKE_curvemapping_evaluateF(
+ brush_settings->curve_rand_uv, 0, random_settings.pen_press);
+ }
+
+ pt->uv_rot += value;
+ CLAMP(pt->uv_rot, -M_PI_2, M_PI_2);
+ }
+}
+
/* add current stroke-point to buffer (returns whether point was successfully added) */
static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure, double curtime)
{
@@ -744,10 +820,6 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
return GP_STROKEADD_INVALID;
}
- /* Set vertex colors for buffer. */
- ED_gpencil_sbuffer_vertex_color_set(
- p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material);
-
/* get pointer to destination point */
pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used);
@@ -768,6 +840,15 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
}
+ /* Set vertex colors for buffer. */
+ ED_gpencil_sbuffer_vertex_color_set(p->depsgraph,
+ p->ob,
+ p->scene->toolsettings,
+ p->brush,
+ p->material,
+ p->random_settings.hsv,
+ p->random_settings.pen_press);
+
if (brush_settings->flag & GP_BRUSH_GROUP_RANDOM) {
/* Apply jitter to position */
if (brush_settings->draw_jitter > 0.0f) {
@@ -781,26 +862,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
const float fac = rand * square_f(exp_factor) * jitpress;
gp_brush_jitter(gpd, pt, fac);
}
- /* apply randomness to pressure */
- if (brush_settings->draw_random_press > 0.0f) {
- float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
- pt->pressure *= 1.0 + rand * 2.0 * brush_settings->draw_random_press;
- CLAMP(pt->pressure, GPENCIL_STRENGTH_MIN, 1.0f);
- }
- /* apply randomness to uv texture rotation */
- if (brush_settings->uv_random > 0.0f) {
- float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used)) *
- 2.0f -
- 1.0f;
- pt->uv_rot += rand * M_PI_2 * brush_settings->uv_random;
- CLAMP(pt->uv_rot, -M_PI_2, M_PI_2);
- }
- /* apply randomness to color strength */
- if (brush_settings->draw_random_strength) {
- float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
- pt->strength *= 1.0 + rand * brush_settings->draw_random_strength;
- CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
- }
+
+ /* Apply other randomness. */
+ gp_apply_randomness(p, brush_settings, pt, true, true, true);
}
/* apply angle of stroke to brush size */
@@ -959,9 +1023,10 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
pt->pressure = ptc->pressure;
pt->strength = ptc->strength;
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
+ copy_v4_v4(pt->vert_color, ptc->vert_color);
pt->time = ptc->time;
/* Apply the vertex color to point. */
- ED_gpencil_point_vertex_color_set(ts, brush, pt);
+ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc);
pt++;
@@ -994,7 +1059,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
pt->time = ptc->time;
/* Apply the vertex color to point. */
- ED_gpencil_point_vertex_color_set(ts, brush, pt);
+ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc);
if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) {
BKE_gpencil_dvert_ensure(gps);
@@ -1113,11 +1178,12 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
pt->pressure = ptc->pressure;
pt->strength = ptc->strength;
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
+ copy_v4_v4(pt->vert_color, ptc->vert_color);
pt->time = ptc->time;
pt->uv_fac = ptc->uv_fac;
pt->uv_rot = ptc->uv_rot;
/* Apply the vertex color to point. */
- ED_gpencil_point_vertex_color_set(ts, brush, pt);
+ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc);
if (dvert != NULL) {
dvert->totweight = 0;
@@ -1751,10 +1817,16 @@ static void gp_init_drawing_brush(bContext *C, tGPsdata *p)
BKE_brush_gpencil_paint_presets(bmain, ts);
changed = true;
}
- /* be sure curves are initializated */
+ /* Be sure curves are initializated. */
BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_sensitivity);
BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_strength);
BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_jitter);
+ BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_pressure);
+ BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_strength);
+ BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_uv);
+ BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_hue);
+ BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_saturation);
+ BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_value);
/* assign to temp tGPsdata */
p->brush = paint->brush;
@@ -2700,6 +2772,8 @@ static void gpencil_draw_apply_event(bContext *C,
/* handle pressure sensitivity (which is supplied by tablets or otherwise 1.0) */
p->pressure = event->tablet.pressure;
+ /* By default use pen pressure for random curves but attenuated. */
+ p->random_settings.pen_press = pow(p->pressure, 3.0f);
/* Hack for pressure sensitive eraser on D+RMB when using a tablet:
* The pen has to float over the tablet surface, resulting in
@@ -3052,6 +3126,8 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
else {
p = op->customdata;
}
+ /* Init random settings. */
+ ED_gpencil_init_random_settings(p->brush, event->mval, &p->random_settings);
/* TODO: set any additional settings that we can take from the events?
* if eraser is on, draw radial aid */
@@ -3175,10 +3251,17 @@ static void gp_brush_angle_segment(tGPsdata *p, tGPspoint *pt_prev, tGPspoint *p
static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
{
bGPdata *gpd = p->gpd;
+ BrushGpencilSettings *brush_settings = p->brush->gpencil_settings;
+
if (gpd->runtime.sbuffer_used < 3) {
+ tGPspoint *points = (tGPspoint *)gpd->runtime.sbuffer;
+ /* Apply other randomness to first points. */
+ for (int i = 0; i < gpd->runtime.sbuffer_used; i++) {
+ tGPspoint *pt = &points[i];
+ gp_apply_randomness(p, brush_settings, pt, false, false, true);
+ }
return;
}
- BrushGpencilSettings *brush_settings = p->brush->gpencil_settings;
int idx_prev = gpd->runtime.sbuffer_used;
/* Add space for new arc points. */
@@ -3233,6 +3316,7 @@ static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
corner[0] = midpoint[0] - (cp1[0] - midpoint[0]);
corner[1] = midpoint[1] - (cp1[1] - midpoint[1]);
+ float stepcolor = 1.0f / segments;
tGPspoint *pt_step = pt_prev;
for (int i = 0; i < segments; i++) {
@@ -3243,6 +3327,9 @@ static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
/* Set pressure and strength equals to previous. It will be smoothed later. */
pt->pressure = pt_prev->pressure;
pt->strength = pt_prev->strength;
+ /* Interpolate vertex color. */
+ interp_v4_v4v4(
+ pt->vert_color, pt_before->vert_color, pt_prev->vert_color, stepcolor * (i + 1));
/* Apply angle of stroke to brush size to interpolated points but slightly attenuated.. */
if (brush_settings->draw_angle_factor != 0.0f) {
@@ -3252,26 +3339,8 @@ static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
pt_step = pt;
}
- /* Apply randomness to pressure. */
- if (brush_settings->draw_random_press > 0.0f) {
- float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
- pt->pressure *= 1.0 + rand * 2.0 * brush_settings->draw_random_press;
- CLAMP(pt->pressure, GPENCIL_STRENGTH_MIN, 1.0f);
- }
- /* Apply randomness to color strength. */
- if (brush_settings->draw_random_strength) {
- float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
- pt->strength *= 1.0 + rand * brush_settings->draw_random_strength;
- CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
- }
- /* Apply randomness to uv texture rotation. */
- if (brush_settings->uv_random > 0.0f) {
- float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used + i)) *
- 2.0f -
- 1.0f;
- pt->uv_rot += rand * M_PI_2 * brush_settings->uv_random;
- CLAMP(pt->uv_rot, -M_PI_2, M_PI_2);
- }
+ /* Apply other randomness. */
+ gp_apply_randomness(p, brush_settings, pt, false, false, true);
a += step;
}
@@ -3323,6 +3392,7 @@ static void gpencil_add_guide_points(const tGPsdata *p,
/* Set pressure and strength equals to previous. It will be smoothed later. */
pt->pressure = pt_before->pressure;
pt->strength = pt_before->strength;
+ copy_v4_v4(pt->vert_color, pt_before->vert_color);
}
}
else {
@@ -3339,6 +3409,7 @@ static void gpencil_add_guide_points(const tGPsdata *p,
/* Set pressure and strength equals to previous. It will be smoothed later. */
pt->pressure = pt_before->pressure;
pt->strength = pt_before->strength;
+ copy_v4_v4(pt->vert_color, pt_before->vert_color);
}
}
}