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:
authorAntonio Vazquez <blendergit@gmail.com>2020-04-07 21:07:58 +0300
committerAntonio Vazquez <blendergit@gmail.com>2020-04-07 21:07:58 +0300
commit7b4b07a7ddc874efd11b3932f152c7136d720f9c (patch)
treea419ff7e77cbc88939b057b69c2f5f4d501e2568 /source/blender/editors/gpencil
parent6b5857181390033b06f18d5a4b19e03f2829d51a (diff)
GPencil: Fix unreported problems with Chisel brush
With the new sampling, the arc points were not using the angle of the brush and the line was with the same thickness in all orientations.
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 40068b0fb85..9de15c411cc 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -3127,6 +3127,34 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op)
return op->customdata;
}
+/* Apply pressure change depending of the angle of the stroke for a segment. */
+static void gp_brush_angle_segment(tGPsdata *p, tGPspoint *pt_prev, tGPspoint *pt)
+{
+ Brush *brush = p->brush;
+ /* Sensitivity. */
+ const float sen = brush->gpencil_settings->draw_angle_factor;
+ /* Default angle of brush in radians */
+ const float angle = brush->gpencil_settings->draw_angle;
+
+ float mvec[2];
+ float fac;
+ float mpressure;
+
+ /* angle vector of the brush with full thickness */
+ float v0[2] = {cos(angle), sin(angle)};
+
+ mvec[0] = pt->x - pt_prev->x;
+ mvec[1] = pt->y - pt_prev->y;
+ normalize_v2(mvec);
+
+ fac = 1.0f - fabs(dot_v2v2(v0, mvec)); /* 0.0 to 1.0 */
+ /* interpolate with previous point for smoother transitions */
+ mpressure = interpf(pt->pressure - (sen * fac), pt_prev->pressure, 0.3f);
+ pt->pressure = mpressure;
+
+ CLAMP(pt->pressure, pt_prev->pressure * 0.5f, 1.0f);
+}
+
/* Add arc points between two mouse events using the previous segment to determine the vertice of
* the arc.
* /+ CTL
@@ -3209,6 +3237,11 @@ static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
pt->pressure = pt_prev->pressure;
pt->strength = pt_prev->strength;
+ /* Apply angle of stroke to brush size. */
+ if (brush_settings->draw_angle_factor != 0.0f) {
+ gp_brush_angle_segment(p, pt_prev, 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;