[Bf-blender-cvs] [3210924485e] sculpt-dev: Sculpt-dev: Properly fix BKE_brush_curve_strength_ex & revert prior hack
Joseph Eagar
noreply at git.blender.org
Sun May 22 11:47:20 CEST 2022
Commit: 3210924485e1503fab5e05aad8ef58b3e4079d08
Author: Joseph Eagar
Date: Sat May 21 23:10:16 2022 -0700
Branches: sculpt-dev
https://developer.blender.org/rB3210924485e1503fab5e05aad8ef58b3e4079d08
Sculpt-dev: Properly fix BKE_brush_curve_strength_ex & revert prior hack
* BKE_brush_curve_strength_ex now takes an argment on
whether to invert the input.
* BKE_brush_curve is now deprecated, it applies prior
behavior of disabling inversion for custom curves
===================================================================
M release/scripts/startup/bl_ui/properties_paint_common.py
M source/blender/blenkernel/BKE_blender_version.h
M source/blender/blenkernel/BKE_brush.h
M source/blender/blenkernel/BKE_brush_engine.hh
M source/blender/blenkernel/intern/brush.c
M source/blender/blenkernel/intern/brush_engine.c
M source/blender/blenkernel/intern/brush_engine_presets.c
M source/blender/blenloader/intern/versioning_300.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index f78b792e512..8318456b6ce 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -675,7 +675,7 @@ class UnifiedPaintPanel:
row = col.row(align=True)
if not header and mp.curve.curve_preset == "CUSTOM":
- template_curve(col, mp.curve, "curve", path2 + ".curve", use_negative_slope=False)
+ template_curve(col, mp.curve, "curve", path2 + ".curve", use_negative_slope=True)
col.prop(mp, "factor")
col.prop(mp, "blendmode")
@@ -1146,7 +1146,7 @@ class FalloffPanel(BrushPanel):
path += ".curve.curve"
if ch.curve.curve_preset == "CUSTOM":
- template_curve(layout, ch.curve, "curve", path, True)
+ template_curve(layout, ch.curve, "curve", path, False)
UnifiedPaintPanel.channel_unified(layout, context, brush, "falloff_shape", expand=True)
return
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index ab13a2e85d0..2cd753da9d3 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -25,7 +25,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 0
+#define BLENDER_FILE_SUBVERSION 1
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index 77322b97f09..bd3f9c68fa5 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -220,7 +220,8 @@ float BKE_brush_fset_slide_get(const struct Scene *scene, const struct Brush *br
float BKE_brush_curve_strength_ex(int curve_preset,
const struct CurveMapping *curve,
float p,
- const float len);
+ const float len,
+ const bool invert);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/BKE_brush_engine.hh b/source/blender/blenkernel/BKE_brush_engine.hh
index f449a4728f5..64f9196e641 100644
--- a/source/blender/blenkernel/BKE_brush_engine.hh
+++ b/source/blender/blenkernel/BKE_brush_engine.hh
@@ -81,7 +81,7 @@ class BrushCurveIF {
/* ensure that curve is in valid state */
initCurve(false);
- return BKE_brush_curve_strength_ex(_curve->preset, _curve->curve, f, maxval);
+ return BKE_brush_curve_strength_ex(_curve->preset, _curve->curve, f, maxval, true);
}
void initCurve(bool forceCreate = false)
@@ -297,7 +297,7 @@ template<typename T> class BrushChannelIF {
}
double f2 = BKE_brush_curve_strength_ex(
- mp->mapping_curve.preset, mp->mapping_curve.curve, inputf, 1.0f);
+ mp->mapping_curve.preset, mp->mapping_curve.curve, inputf, 1.0f, false);
f2 = mp->min + (mp->max - mp->min) * f2;
/* make sure to update blend_items in rna_brush_engine.c
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 2ca076b9998..0288d5e52ee 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -2816,10 +2816,8 @@ void BKE_brush_randomize_texture_coords(UnifiedPaintSettings *ups, bool mask)
}
}
-float BKE_brush_curve_strength_ex(int curve_preset,
- const CurveMapping *curve,
- float p,
- const float len)
+ATTR_NO_OPT float BKE_brush_curve_strength_ex(
+ int curve_preset, const CurveMapping *curve, float p, const float len, const bool invert)
{
float strength = 1.0f;
@@ -2828,11 +2826,14 @@ float BKE_brush_curve_strength_ex(int curve_preset,
}
p = p / len;
- p = 1.0f - p;
+
+ if (invert) {
+ p = 1.0f - p;
+ }
switch (curve_preset) {
case BRUSH_CURVE_CUSTOM:
- strength = BKE_curvemapping_evaluateF(curve, 0, 1.0f - p);
+ strength = BKE_curvemapping_evaluateF(curve, 0, p);
break;
case BRUSH_CURVE_SHARP:
strength = p * p;
@@ -2866,10 +2867,21 @@ float BKE_brush_curve_strength_ex(int curve_preset,
return strength;
}
-/* Uses the brush curve control to find a strength value between 0 and 1 */
+/* DEPRECATED: use BKE_brush_curve_strength_ex for new code.
+ * Uses the brush curve control to find a strength value between 0 and 1
+ */
float BKE_brush_curve_strength(const Brush *br, float p, const float len)
{
- return BKE_brush_curve_strength_ex(br->curve_preset, br->curve, p, len);
+ if (p >= len) {
+ return 0.0f;
+ }
+
+ /* Invert p to match behavior of master. */
+ if (br->curve_preset == BRUSH_CURVE_CUSTOM) {
+ p = len - p;
+ }
+
+ return BKE_brush_curve_strength_ex(br->curve_preset, br->curve, p, len, true);
}
float BKE_brush_curve_strength_clamped(const Brush *br, float p, const float len)
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index 348239b46d7..fd40215ff99 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -152,7 +152,7 @@ bool BKE_brush_mapping_ensure_write(BrushMapping *mp)
BKE_curvemap_reset(curve->cm,
&(struct rctf){.xmin = 0.0f, .ymin = 0.0f, .xmax = 1.0f, .ymax = 1.0f},
CURVE_PRESET_LINE,
- CURVEMAP_SLOPE_NEGATIVE);
+ CURVEMAP_SLOPE_POSITIVE);
BKE_curvemapping_init(curve);
@@ -525,7 +525,7 @@ void BKE_brush_channel_init(BrushChannel *ch, BrushChannelType *def)
BKE_curvemap_reset(mp->mapping_curve.curve->cm,
&(struct rctf){.xmin = 0.0f, .ymin = 0.0f, .xmax = 1.0f, .ymax = 1.0f},
mdef->curve,
- CURVEMAP_SLOPE_NEGATIVE);
+ CURVEMAP_SLOPE_POSITIVE);
BKE_curvemapping_init(mp->mapping_curve.curve);
@@ -590,7 +590,7 @@ float BKE_brush_channel_curve_evaluate(BrushChannel *ch, float val, const float
{
BKE_brush_channel_curvemapping_get(&ch->curve, false);
- return BKE_brush_curve_strength_ex(ch->curve.preset, ch->curve.curve, val, maxval);
+ return BKE_brush_curve_strength_ex(ch->curve.preset, ch->curve.curve, val, maxval, true);
}
BrushChannelSet *BKE_brush_channelset_create(const char *info)
@@ -1096,7 +1096,7 @@ double BKE_brush_channel_eval_mappings(BrushChannel *ch,
}
double f2 = BKE_brush_curve_strength_ex(
- mp->mapping_curve.preset, mp->mapping_curve.curve, 1.0f - inputf, 1.0f);
+ mp->mapping_curve.preset, mp->mapping_curve.curve, inputf, 1.0f, false);
f2 = mp->min + (mp->max - mp->min) * f2;
/* make sure to update blend_items in rna_brush_engine.c
@@ -2052,16 +2052,6 @@ void BKE_brush_channelset_read(BlendDataReader *reader, BrushChannelSet *chset)
/* Only convert curve if it's not linear. */
if (!BKE_curvemapping_equals(mp->curve, &linear_curve)) {
mp->mapping_curve.preset = BRUSH_CURVE_CUSTOM;
-
- /* TODO: figure out why BKE_brush_curve_strength_ex inverts custom curves
- * but not any other preset.
- */
- for (int i = 0; i < mp->curve->cm->totpoint; i++) {
- mp->curve->cm->curve[i].x = 1.0f - mp->curve->cm->curve[i].x;
- }
-
- BKE_curvemapping_changed(mp->curve, false);
-
mp->mapping_curve.curve = GET_CACHE_CURVE(mp->curve);
}
else {
diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index b4f232e34e8..4195c7726f8 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -1007,7 +1007,7 @@ void BKE_brush_channelset_compat_load(BrushChannelSet *chset, Brush *brush, bool
BKE_curvemap_reset(ch->curve.curve->cm,
&(struct rctf){.xmin = 0, .ymin = 0.0, .xmax = 1.0, .ymax = 1.0},
CURVE_PRESET_LINE,
- CURVEMAP_SLOPE_NEGATIVE);
+ CURVEMAP_SLOPE_POSITIVE);
}
BKE_curvemapping_init(ch->curve.curve);
}
@@ -1043,17 +1043,17 @@ void reset_clay_mappings(BrushChannelSet *chset, bool strips)
BKE_curvemap_reset(curve->cm,
&(struct rctf){.xmin = 0, .ymin = 0.0, .xmax = 1.0, .ymax = 1.0},
CURVE_PRESET_LINE,
- CURVEMAP_SLOPE_NEGATIVE);
+ CURVEMAP_SLOPE_POSITIVE);
BKE_curvemapping_init(curve);
CurveMap *cuma = curve->cm;
if (!strips) { //[[0,0.200], [0.354,0.200], [0.595,0.210], [0.806,0.523], [1,1.000]
#if 0
- cuma->curve[0].x = 1.0f;
- cuma->curve[0].y = 0.2f;
+ cuma->curve[1].x = 1.0f;
+ cuma->curve[1].y = 0.2f;
- cuma->curve[1].x = 0.0f;
+ cuma->curve[0].x = 0.0f;
BKE_curvemap_insert(cuma, 1.0f-0.35f, 0.2f);
BKE_curvemap_insert(cuma, 1.0f-0.6f, 0.210f);
@@ -1064,9 +1064,9 @@ void reset_clay_mappings(BrushChannelSet *chset, bool strips)
}
else {
//[[0,0], [0.250,0.050], [0.500,0.125], [0.750,0.422], [1,1]
- cuma->curve[0].x = 1.0f;
- cuma->curve[0].y = 0.55f;
- cuma->curve[1].x = 0.0f;
+ cuma->curve[1].x = 1.0f;
+ cuma->curve[1].y = 0.55f;
+ cuma->curve[0].x = 0.0f;
BKE_curvemap_insert(cuma, 0.5f, 0.7f);
cuma->curve[2].x = 0.0f;
@@ -1084,7 +1084,7 @@ void reset_clay_mappings(BrushChannelSet *chset, bool strips)
BKE_curvemap_reset(curve->cm,
&
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list