Fix: Curve and Line stroke types can have incorrect spacing behavior
The intent of the Curve and Line stroke types is generally to perform a set of equally spaced points. Unlike drawing with a tablet using the Spacing stroke type, pressure should have no influence on this input. Previously, the code would pass in a hardcoded value of 1.0f for the line & curve pressure. This is incorrect, as it results in a factor of 0.5f, not 1.0f, causing behavior to differ on this stroke type depending on if the corresponding brush pressure flag was enabled or not. Additionally, an extra check is used to ensure that only the Spacing stroke type can have pressure modulated in this way. Pull Request: https://projects.blender.org/blender/blender/pulls/146120
This commit is contained in:
@@ -712,7 +712,7 @@ static float paint_space_stroke_spacing(const bContext *C,
|
||||
float spacing = stroke->brush->spacing;
|
||||
|
||||
/* apply spacing pressure */
|
||||
if (stroke->brush->flag & BRUSH_SPACING_PRESSURE) {
|
||||
if (stroke->brush->flag & BRUSH_SPACE && stroke->brush->flag & BRUSH_SPACING_PRESSURE) {
|
||||
spacing = spacing * (1.5f - pressure);
|
||||
}
|
||||
|
||||
@@ -736,6 +736,13 @@ static float paint_space_stroke_spacing(const bContext *C,
|
||||
return max_ff(stroke->zoom_2d, size_clamp * spacing / 50.0f);
|
||||
}
|
||||
|
||||
static float paint_space_stroke_spacing_no_pressure(const bContext *C, PaintStroke *stroke)
|
||||
{
|
||||
/* Unlike many paint pressure curves, spacing assumes that a stroke without pressure (e.g. with
|
||||
* the mouse, or with the setting turned off) represents an input of 0.5, not 1.0. */
|
||||
return paint_space_stroke_spacing(C, stroke, 1.0f, 0.5f);
|
||||
}
|
||||
|
||||
static float paint_stroke_overlapped_curve(const Brush &br, const float x, const float spacing)
|
||||
{
|
||||
/* Avoid division by small numbers, can happen
|
||||
@@ -856,7 +863,7 @@ static int paint_space_stroke(bContext *C,
|
||||
|
||||
float pressure = stroke->last_pressure;
|
||||
float pressure_delta = final_pressure - stroke->last_pressure;
|
||||
const float no_pressure_spacing = paint_space_stroke_spacing(C, stroke, 1.0f, 1.0f);
|
||||
const float no_pressure_spacing = paint_space_stroke_spacing_no_pressure(C, stroke);
|
||||
int count = 0;
|
||||
while (length > 0.0f) {
|
||||
const float spacing = paint_space_stroke_spacing_variable(
|
||||
@@ -1358,7 +1365,7 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str
|
||||
|
||||
Paint *paint = BKE_paint_get_active_from_context(C);
|
||||
bke::PaintRuntime *paint_runtime = stroke->paint->runtime;
|
||||
const float spacing = paint_space_stroke_spacing(C, stroke, 1.0f, 1.0f);
|
||||
const float no_pressure_spacing = paint_space_stroke_spacing_no_pressure(C, stroke);
|
||||
const PaintCurve *pc = br.paint_curve;
|
||||
|
||||
if (!pc) {
|
||||
@@ -1424,13 +1431,18 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str
|
||||
|
||||
if (stroke->stroke_started) {
|
||||
paint_brush_stroke_add_step(C, op, stroke, data + 2 * j, 1.0);
|
||||
paint_line_strokes_spacing(
|
||||
C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1));
|
||||
paint_line_strokes_spacing(C,
|
||||
op,
|
||||
stroke,
|
||||
no_pressure_spacing,
|
||||
&length_residue,
|
||||
data + 2 * j,
|
||||
data + 2 * (j + 1));
|
||||
}
|
||||
}
|
||||
else {
|
||||
paint_line_strokes_spacing(
|
||||
C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1));
|
||||
C, op, stroke, no_pressure_spacing, &length_residue, data + 2 * j, data + 2 * (j + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user