brush curve - use clamped values (0-1) for everything except sculpt which can have positive and negative values.

This commit is contained in:
Campbell Barton 2009-09-24 01:32:23 +00:00
parent b82b50417c
commit 0c68fe3a61
3 changed files with 22 additions and 10 deletions

@ -60,7 +60,8 @@ typedef enum {
BRUSH_PRESET_MAX
} BrushCurvePreset;
void brush_curve_preset(struct Brush *b, BrushCurvePreset preset);
float brush_curve_strength(struct Brush *br, float p, const float len);
float brush_curve_strength_clamp(struct Brush *br, float p, const float len);
float brush_curve_strength(struct Brush *br, float p, const float len); /* used for sculpt */
/* sampling */
void brush_sample_tex(struct Brush *brush, float *xy, float *rgba);

@ -442,7 +442,7 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **o
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
VECCOPY(dstf, brush->rgb);
dstf[3]= brush->alpha*brush_curve_strength(brush, dist, maxsize);
dstf[3]= brush->alpha*brush_curve_strength_clamp(brush, dist, maxsize);
}
else if (texfall == 1) {
brush_sample_tex(brush, xy, dstf);
@ -455,7 +455,7 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **o
dstf[0] = rgba[0]*brush->rgb[0];
dstf[1] = rgba[1]*brush->rgb[1];
dstf[2] = rgba[2]*brush->rgb[2];
dstf[3] = rgba[3]*brush->alpha*brush_curve_strength(brush, dist, maxsize);
dstf[3] = rgba[3]*brush->alpha*brush_curve_strength_clamp(brush, dist, maxsize);
}
}
}
@ -494,7 +494,7 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **o
dst[0] = FTOCHAR(rgba[0]*brush->rgb[0]);
dst[1] = FTOCHAR(rgba[1]*brush->rgb[1]);
dst[2] = FTOCHAR(rgba[2]*brush->rgb[2]);
dst[3] = FTOCHAR(rgba[3]*brush->alpha*brush_curve_strength(brush, dist, maxsize));
dst[3] = FTOCHAR(rgba[3]*brush->alpha*brush_curve_strength_clamp(brush, dist, maxsize));
}
}
}
@ -952,12 +952,23 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl
}
/* Uses the brush curve control to find a strength value between 0 and 1 */
float brush_curve_strength_clamp(Brush *br, float p, const float len)
{
if(p >= len) p= 1.0f;
else p= p/len;
p= curvemapping_evaluateF(br->curve, 0, p);
if(p < 0.0) p= 0.0f;
else if(p > 1.0f) p= 1.0f;
return p;
}
/* same as above but can return negative values if the curve enables
* used for sculpt only */
float brush_curve_strength(Brush *br, float p, const float len)
{
float f;
if(p > len) p= len;
f= curvemapping_evaluateF(br->curve, 0, p/len);
return (f > 0.0f) ? f:0.0f;
if(p >= len) p= 1.0f;
else p= p/len;
return curvemapping_evaluateF(br->curve, 0, p);
}
/* TODO: should probably be unified with BrushPainter stuff? */
@ -1024,7 +1035,7 @@ static struct ImBuf *brush_gen_radial_control_imbuf(Brush *br)
for(i=0; i<side; ++i) {
for(j=0; j<side; ++j) {
float magn= sqrt(pow(i - half, 2) + pow(j - half, 2));
im->rect_float[i*side + j]= brush_curve_strength(br, magn, half);
im->rect_float[i*side + j]= brush_curve_strength_clamp(br, magn, half);
}
}

@ -3731,7 +3731,7 @@ static void *do_projectpaint_thread(void *ph_v)
/*if (dist < s->brush->size) {*/ /* correct but uses a sqrtf */
if (dist_nosqrt < brush_size_sqared && (dist=sqrtf(dist_nosqrt)) < size_half) {
falloff = brush_curve_strength(ps->brush, dist, size_half);
falloff = brush_curve_strength_clamp(ps->brush, dist, size_half);
if (falloff > 0.0f) {
if (ps->is_texbrush) {
brush_sample_tex(ps->brush, projPixel->projCoSS, rgba);