[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60488] branches/soc-2013-paint/source/ blender/editors/sculpt_paint: Texture painting: Fix painting with size pressure sensitivity scales the

Antony Riakiotakis kalast at gmail.com
Tue Oct 1 15:55:28 CEST 2013


Revision: 60488
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60488
Author:   psy-fi
Date:     2013-10-01 13:55:28 +0000 (Tue, 01 Oct 2013)
Log Message:
-----------
Texture painting: Fix painting with size pressure sensitivity scales the
texture as well. Do not modify the brush size in texture painting,
instead cache the size in the paint structures. Projective painting
should work correctly now. 2D still has a swimmy effect which I have
isolated in partial brush image update (new coordinates seem to be OK)

Modified Paths:
--------------
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-10-01 13:33:43 UTC (rev 60487)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-10-01 13:55:28 UTC (rev 60488)
@@ -738,7 +738,6 @@
 	float alphafac = (brush->flag & BRUSH_ACCUMULATE)? ups->overlap_factor : 1.0;
 
 	/* initial brush values. Maybe it should be considered moving these to stroke system */
-	float startsize = (float)BKE_brush_size_get(scene, brush);
 	float startalpha = BKE_brush_alpha_get(scene, brush);
 
 	float mouse[2];
@@ -750,7 +749,7 @@
 	RNA_float_get_array(itemptr, "mouse", mouse);
 	pressure = RNA_float_get(itemptr, "pressure");
 	eraser = RNA_boolean_get(itemptr, "pen_flip");
-	size = RNA_float_get(itemptr, "size");
+	size = max_ff(1.0f, RNA_float_get(itemptr, "size"));
 
 	/* stroking with fill tool only acts on stroke end */
 	if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
@@ -764,17 +763,15 @@
 	else
 		BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * alphafac));
 
-	BKE_brush_size_set(scene, brush, max_ff(1.0f, size));
-
 	if ((brush->flag & BRUSH_DRAG_DOT) || (brush->flag & BRUSH_ANCHORED)) {
 		paint_stroke_restore();
 	}
 
 	if (pop->mode == PAINT_MODE_3D_PROJECT) {
-		paint_proj_stroke(C, pop->custom_paint, pop->prevmouse, mouse, pressure, distance);
+		paint_proj_stroke(C, pop->custom_paint, pop->prevmouse, mouse, pressure, distance, size);
 	}
 	else {
-		paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser, pressure, distance);
+		paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser, pressure, distance, size);
 	}
 
 	pop->prevmouse[0] = mouse[0];
@@ -782,7 +779,6 @@
 
 	/* restore brush values */
 	BKE_brush_alpha_set(scene, brush, startalpha);
-	BKE_brush_size_set(scene, brush, startsize);
 }
 
 static void paint_stroke_redraw(const bContext *C, struct PaintStroke *stroke, bool final)
@@ -812,7 +808,7 @@
 				paint_2d_gradient_fill(C, brush, pop->startmouse, pop->prevmouse, pop->custom_paint);
 			}
 			else {
-				paint_proj_stroke(C, pop->custom_paint, pop->startmouse, pop->prevmouse, 1.0, 0.0);
+				paint_proj_stroke(C, pop->custom_paint, pop->startmouse, pop->prevmouse, 1.0, 0.0, BKE_brush_size_get(scene, brush));
 				/* two redraws, one for GPU update, one for notification */
 				paint_proj_redraw(C, pop->custom_paint, false);
 				paint_proj_redraw(C, pop->custom_paint, true);
@@ -826,7 +822,7 @@
 				paint_2d_bucket_fill(C, color, brush, pop->prevmouse, pop->custom_paint);
 			}
 			else {
-				paint_proj_stroke(C, pop->custom_paint, pop->startmouse, pop->prevmouse, 1.0, 0.0);
+				paint_proj_stroke(C, pop->custom_paint, pop->startmouse, pop->prevmouse, 1.0, 0.0, BKE_brush_size_get(scene, brush));
 				/* two redraws, one for GPU update, one for notification */
 				paint_proj_redraw(C, pop->custom_paint, false);
 				paint_proj_redraw(C, pop->custom_paint, true);

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-10-01 13:33:43 UTC (rev 60487)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-10-01 13:55:28 UTC (rev 60488)
@@ -74,8 +74,6 @@
 /* Defines and Structs */
 
 typedef struct BrushPainterCache {
-	int size;                    /* size override, if 0 uses 2*BKE_brush_size_get(brush) */
-
 	bool use_float;              /* need float imbuf? */
 	bool use_color_correction;   /* use color correction for float */
 	bool use_masking;            /* use masking? */
@@ -84,7 +82,7 @@
 	bool is_texbrush;
 	bool is_maskbrush;
 
-	int lastsize;
+	int lastdiameter;
 	float lastalpha;
 	float lastjitter;
 	float last_tex_rotation;
@@ -156,7 +154,7 @@
 	painter->brush = brush;
 	painter->scene = scene;
 	painter->firsttouch = 1;
-	painter->cache.lastsize = -1; /* force ibuf create in refresh */
+	painter->cache.lastdiameter = -1; /* force ibuf create in refresh */
 	painter->cache.invert = invert;
 
 	return painter;
@@ -174,13 +172,13 @@
 		painter->cache.ibuf = NULL;
 		painter->cache.curve_mask = NULL;
 		painter->cache.max_mask = NULL;
-		painter->cache.lastsize = -1; /* force ibuf create in refresh */
+		painter->cache.lastdiameter = -1; /* force ibuf create in refresh */
 	}
 
 	if (painter->cache.use_float != use_float) {
 		if (painter->cache.texibuf) IMB_freeImBuf(painter->cache.texibuf);
 		painter->cache.texibuf = NULL;
-		painter->cache.lastsize = -1; /* force ibuf create in refresh */
+		painter->cache.lastdiameter = -1; /* force ibuf create in refresh */
 	}
 
 	painter->cache.use_float = use_float;
@@ -243,23 +241,21 @@
 
 
 /* create a mask with the falloff strength */
-static unsigned short *brush_painter_curve_mask_new(BrushPainter *painter, int size)
+static unsigned short *brush_painter_curve_mask_new(BrushPainter *painter, int diameter, float radius)
 {
-	Scene *scene = painter->scene;
 	Brush *brush = painter->brush;
 
-	int radius = BKE_brush_size_get(scene, brush);
-	int xoff = -size * 0.5f + 0.5f;
-	int yoff = -size * 0.5f + 0.5f;
+	int xoff = -diameter * 0.5f + 0.5f;
+	int yoff = -diameter * 0.5f + 0.5f;
 
 	unsigned short *mask, *m;
 	int x, y;
 
-	mask = MEM_callocN(sizeof(unsigned short) * size * size, "brush_painter_mask");
+	mask = MEM_callocN(sizeof(unsigned short) * diameter * diameter, "brush_painter_mask");
 	m = mask;
 
-	for (y = 0; y < size; y++) {
-		for (x = 0; x < size; x++, m++) {
+	for (y = 0; y < diameter; y++) {
+		for (x = 0; x < diameter; x++, m++) {
 			float xy[2] = {x + xoff, y + yoff};
 			float len = len_v2(xy);
 
@@ -418,7 +414,7 @@
 		brush_rgb[2] = 1.0f;
 	}
 
-	/* fill pixes */
+	/* fill pixels */
 	for (y = origy; y < h; y++) {
 		for (x = origx; x < w; x++) {
 			/* sample texture and multiply with brush color */
@@ -505,14 +501,11 @@
 /* update the brush image by trying to reuse the cached texture result. this
  * can be considerably faster for brushes that change size due to pressure or
  * textures that stick to the surface where only part of the pixels are new */
-static void brush_painter_imbuf_partial_update(BrushPainter *painter, const float pos[2])
+static void brush_painter_imbuf_partial_update(BrushPainter *painter, const float pos[2], int diameter)
 {
-	const Scene *scene = painter->scene;
-	Brush *brush = painter->brush;
 	BrushPainterCache *cache = &painter->cache;
 	ImBuf *oldtexibuf, *ibuf;
 	int imbflag, destx, desty, srcx, srcy, w, h, x1, y1, x2, y2;
-	int diameter = 2 * BKE_brush_size_get(scene, brush);
 
 	/* create brush image buffer if it didn't exist yet */
 	imbflag = (cache->use_float) ? IB_rectfloat : IB_rect;
@@ -538,7 +531,7 @@
 		destx = desty = 0;
 		w = h = 0;
 	}
-	
+
 	x1 = destx;
 	y1 = desty;
 	x2 = min_ii(destx + w, ibuf->x);
@@ -562,7 +555,7 @@
 		brush_painter_imbuf_update(painter, NULL, x1, y2, x2, ibuf->y, 0, 0);
 }
 
-static void brush_painter_2d_tex_mapping(ImagePaintState *s, int size, const float startpos[2], const float pos[2], const float mouse[2], int mapmode, rctf *mapping)
+static void brush_painter_2d_tex_mapping(ImagePaintState *s, int diameter, const float startpos[2], const float pos[2], const float mouse[2], int mapmode, rctf *mapping)
 {
 	float invw = 1.0f / (float)s->canvas->x;
 	float invh = 1.0f / (float)s->canvas->y;
@@ -570,19 +563,19 @@
 	int ipos[2];
 
 	/* find start coordinate of brush in canvas */
-	ipos[0] = (int)floorf((pos[0] - size / 2) + 1.0f);
-	ipos[1] = (int)floorf((pos[1] - size / 2) + 1.0f);
+	ipos[0] = (int)floorf((pos[0] - diameter / 2) + 1.0f);
+	ipos[1] = (int)floorf((pos[1] - diameter / 2) + 1.0f);
 
 	if (mapmode == MTEX_MAP_MODE_STENCIL) {
 		/* map from view coordinates of brush to region coordinates */
 		UI_view2d_to_region_no_clip(s->v2d, ipos[0] * invw, ipos[1] * invh, &xmin, &ymin);
-		UI_view2d_to_region_no_clip(s->v2d, (ipos[0] + size) * invw, (ipos[1] + size) * invh, &xmax, &ymax);
+		UI_view2d_to_region_no_clip(s->v2d, (ipos[0] + diameter) * invw, (ipos[1] + diameter) * invh, &xmax, &ymax);
 
 		/* output mapping from brush ibuf x/y to region coordinates */
 		mapping->xmin = xmin;
 		mapping->ymin = ymin;
-		mapping->xmax = (xmax - xmin) / (float)size;
-		mapping->ymax = (ymax - ymin) / (float)size;
+		mapping->xmax = (xmax - xmin) / (float)diameter;
+		mapping->ymax = (ymax - ymin) / (float)diameter;
 	}
 	else if (mapmode == MTEX_MAP_MODE_3D) {
 		/* 3D mapping, just mapping to canvas 0..1  */
@@ -593,27 +586,26 @@
 	}
 	else if (ELEM(mapmode, MTEX_MAP_MODE_VIEW, MTEX_MAP_MODE_RANDOM)) {
 		/* view mapping */
-		mapping->xmin = mouse[0] - size * 0.5f + 0.5f;
-		mapping->ymin = mouse[1] - size * 0.5f + 0.5f;
+		mapping->xmin = mouse[0] - diameter * 0.5f + 0.5f;
+		mapping->ymin = mouse[1] - diameter * 0.5f + 0.5f;
 		mapping->xmax = 1.0f;
 		mapping->ymax = 1.0f;
 	}
 	else /* if (mapmode == MTEX_MAP_MODE_TILED) */ {
-		mapping->xmin = -size * 0.5f + 0.5f + (int)pos[0] - (int)startpos[0];
-		mapping->ymin = -size * 0.5f + 0.5f + (int)pos[1] - (int)startpos[1];
+		mapping->xmin = (int)(-diameter * 0.5) + (int)pos[0] - (int)startpos[0];
+		mapping->ymin = (int)(-diameter * 0.5) + (int)pos[1] - (int)startpos[1];
 		mapping->xmax = 1.0f;
 		mapping->ymax = 1.0f;
 	}
 }
 
-static void brush_painter_2d_refresh_cache(ImagePaintState *s, BrushPainter *painter, const float pos[2], const float mouse[2], float pressure, float distance)
+static void brush_painter_2d_refresh_cache(ImagePaintState *s, BrushPainter *painter, const float pos[2], const float mouse[2], float pressure, float distance, float size)
 {
 	const Scene *scene = painter->scene;
 	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 	Brush *brush = painter->brush;
 	BrushPainterCache *cache = &painter->cache;
-	const int diameter = 2 * BKE_brush_size_get(scene, brush);
-	const int size = (cache->size) ? cache->size : diameter;
+	const int diameter = 2 * size;
 	const float alpha = BKE_brush_alpha_get(scene, brush);
 
 	bool do_random = false;
@@ -636,7 +628,7 @@
 		else if (!(brush->flag & BRUSH_ANCHORED) || update_color)
 			do_partial_update = true;
 
-		brush_painter_2d_tex_mapping(s, size, painter->startpaintpos, pos, mouse,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list