[Bf-blender-cvs] [9f911f6] master: Fix T45013 negative curve falloff not working.

Antony Riakiotakis noreply at git.blender.org
Wed Jun 10 13:33:20 CEST 2015


Commit: 9f911f62dcefd3ce4312bb8aa1d522cae6bbf6e9
Author: Antony Riakiotakis
Date:   Wed Jun 10 13:32:11 2015 +0200
Branches: master
https://developer.blender.org/rB9f911f62dcefd3ce4312bb8aa1d522cae6bbf6e9

Fix T45013 negative curve falloff not working.

Was doing clamping as fix for T42984. Seems we can ommit clamping for
sculpting if we make sure overlap is not zero with negative values.

Control for clamping is moved to the "Use Clipping" function of curves
(which is on by default), so both bugs remain squashed and advanced
users can now properly utilize curves in sculpting, though not all
brushes work well with negative curves.

===================================================================

M	source/blender/blenkernel/BKE_brush.h
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/colortools.c
M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/editors/sculpt_paint/paint_image_2d.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/sculpt_uv.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index 023303f..042fba7 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -63,6 +63,7 @@ void BKE_brush_randomize_texture_coords(struct UnifiedPaintSettings *ups, bool m
 
 /* brush curve */
 void BKE_brush_curve_preset(struct Brush *b, int preset);
+float BKE_brush_curve_strength_clamped(struct Brush *br, float p, const float len);
 float BKE_brush_curve_strength(struct Brush *br, float p, const float len);
 
 /* sampling */
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 307f97f..2464b3b 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -971,7 +971,7 @@ void BKE_brush_randomize_texture_coords(UnifiedPaintSettings *ups, bool mask)
 	}
 }
 
-/* Uses the brush curve control to find a strength value between 0 and 1 */
+/* Uses the brush curve control to find a strength value */
 float BKE_brush_curve_strength(Brush *br, float p, const float len)
 {
 	float strength;
@@ -981,6 +981,15 @@ float BKE_brush_curve_strength(Brush *br, float p, const float len)
 
 	strength = curvemapping_evaluateF(br->curve, 0, p);
 
+	return strength;
+}
+
+
+/* Uses the brush curve control to find a strength value between 0 and 1 */
+float BKE_brush_curve_strength_clamped(Brush *br, float p, const float len)
+{
+	float strength = BKE_brush_curve_strength(br, p, len);
+
 	CLAMP(strength, 0.0f, 1.0f);
 
 	return strength;
@@ -1042,7 +1051,7 @@ struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary)
 	for (i = 0; i < side; ++i) {
 		for (j = 0; j < side; ++j) {
 			float magn = sqrtf(pow2f(i - half) + pow2f(j - half));
-			im->rect_float[i * side + j] = BKE_brush_curve_strength(br, magn, half);
+			im->rect_float[i * side + j] = BKE_brush_curve_strength_clamped(br, magn, half);
 		}
 	}
 
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index c5f7e12..1120034 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -790,7 +790,17 @@ float curvemap_evaluateF(const CurveMap *cuma, float value)
 float curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
 {
 	const CurveMap *cuma = cumap->cm + cur;
-	return curvemap_evaluateF(cuma, value);
+	float val = curvemap_evaluateF(cuma, value);
+
+	/* account for clipping */
+	if (cumap->flag & CUMA_DO_CLIP) {
+		if (val < cumap->curr.ymin)
+			val = cumap->curr.ymin;
+		else if (val > cumap->curr.ymax)
+			val = cumap->curr.ymax;
+	}
+
+	return val;
 }
 
 /* vector case */
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index c88153c..e4cad38 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -426,7 +426,7 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
 				len = sqrtf(x * x + y * y);
 
 				if (len <= 1) {
-					float avg = BKE_brush_curve_strength(br, len, 1.0f);  /* Falloff curve */
+					float avg = BKE_brush_curve_strength_clamped(br, len, 1.0f);  /* Falloff curve */
 
 					buffer[index] = 255 - (GLubyte)(255 * avg);
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 1ad700b..483bf0f 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -359,7 +359,7 @@ static unsigned short *brush_painter_curve_mask_new(BrushPainter *painter, int d
 			float xy[2] = {x + xoff, y + yoff};
 			float len = len_v2(xy);
 
-			*m = (unsigned short)(65535.0f * BKE_brush_curve_strength(brush, len, radius));
+			*m = (unsigned short)(65535.0f * BKE_brush_curve_strength_clamped(brush, len, radius));
 		}
 	}
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 58f1ebb..46e294d 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4722,7 +4722,7 @@ static void *do_projectpaint_thread(void *ph_v)
 				if (dist_sq <= brush_radius_sq) {
 					dist = sqrtf(dist_sq);
 
-					falloff = BKE_brush_curve_strength(ps->brush, dist, brush_radius);
+					falloff = BKE_brush_curve_strength_clamped(ps->brush, dist, brush_radius);
 
 					if (falloff > 0.0f) {
 						float texrgb[3];
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 21beb97..ece6ea7 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -557,7 +557,7 @@ static float paint_stroke_integrate_overlap(Brush *br, float factor)
 	g = 1.0f / m;
 	max = 0;
 	for (i = 0; i < m; i++) {
-		float overlap = paint_stroke_overlapped_curve(br, i * g, spacing);
+		float overlap = fabs(paint_stroke_overlapped_curve(br, i * g, spacing));
 
 		if (overlap > max)
 			max = overlap;
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 1a31442..5af327e 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -936,7 +936,7 @@ static float calc_vp_strength_col_dl(VPaint *vp, ViewContext *vc, const float co
 			else {
 				factor = 1.0f;
 			}
-			return factor * BKE_brush_curve_strength(brush, dist, brush_size_pressure);
+			return factor * BKE_brush_curve_strength_clamped(brush, dist, brush_size_pressure);
 		}
 	}
 	if (rgba)
@@ -3217,7 +3217,7 @@ static void gradientVert_update(DMGradient_userData *grad_data, int index)
 	/* no need to clamp 'alpha' yet */
 
 	/* adjust weight */
-	alpha = BKE_brush_curve_strength(grad_data->brush, alpha, 1.0f);
+	alpha = BKE_brush_curve_strength_clamped(grad_data->brush, alpha, 1.0f);
 
 	if (alpha != 0.0f) {
 		MDeformVert *dv = &me->dvert[index];
diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c
index a9feb9f..4e1517b 100644
--- a/source/blender/editors/sculpt_paint/sculpt_uv.c
+++ b/source/blender/editors/sculpt_paint/sculpt_uv.c
@@ -315,7 +315,7 @@ static void HC_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *sculptdata,
 		if ((dist = dot_v2v2(diff, diff)) <= radius) {
 			UvElement *element;
 			float strength;
-			strength = alpha * BKE_brush_curve_strength(brush, sqrtf(dist), radius_root);
+			strength = alpha * BKE_brush_curve_strength_clamped(brush, sqrtf(dist), radius_root);
 
 			sculptdata->uv[i].uv[0] = (1.0f - strength) * sculptdata->uv[i].uv[0] + strength * (tmp_uvdata[i].p[0] - 0.5f * (tmp_uvdata[i].b[0] + tmp_uvdata[i].sum_b[0] / tmp_uvdata[i].ncounter));
 			sculptdata->uv[i].uv[1] = (1.0f - strength) * sculptdata->uv[i].uv[1] + strength * (tmp_uvdata[i].p[1] - 0.5f * (tmp_uvdata[i].b[1] + tmp_uvdata[i].sum_b[1] / tmp_uvdata[i].ncounter));
@@ -379,7 +379,7 @@ static void laplacian_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *scul
 		if ((dist = dot_v2v2(diff, diff)) <= radius) {
 			UvElement *element;
 			float strength;
-			strength = alpha * BKE_brush_curve_strength(brush, sqrtf(dist), radius_root);
+			strength = alpha * BKE_brush_curve_strength_clamped(brush, sqrtf(dist), radius_root);
 
 			sculptdata->uv[i].uv[0] = (1.0f - strength) * sculptdata->uv[i].uv[0] + strength * tmp_uvdata[i].p[0];
 			sculptdata->uv[i].uv[1] = (1.0f - strength) * sculptdata->uv[i].uv[1] + strength * tmp_uvdata[i].p[1];
@@ -454,7 +454,7 @@ static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, const wmEvent *e
 			if ((dist = dot_v2v2(diff, diff)) <= radius) {
 				UvElement *element;
 				float strength;
-				strength = alpha * BKE_brush_curve_strength(brush, sqrtf(dist), radius_root);
+				strength = alpha * BKE_brush_curve_strength_clamped(brush, sqrtf(dist), radius_root);
 				normalize_v2(diff);
 
 				sculptdata->uv[i].uv[0] -= strength * diff[0] * 0.001f;
@@ -822,7 +822,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm
 				diff[1] /= aspectRatio;
 				if ((dist = dot_v2v2(diff, diff)) <= radius) {
 					float strength;
-					strength = alpha * BKE_brush_curve_strength(brush, sqrtf(dist), radius_root);
+					strength = alpha * BKE_brush_curve_strength_clamped(brush, sqrtf(dist), radius_root);
 
 					data->initial_stroke->initialSelection[counter].uv = i;
 					data->initial_stroke->initialSelection[counter].strength = strength;




More information about the Bf-blender-cvs mailing list