[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55607] trunk/blender/source/blender: Paint system:

Antony Riakiotakis kalast at gmail.com
Tue Mar 26 22:34:39 CET 2013


Revision: 55607
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55607
Author:   psy-fi
Date:     2013-03-26 21:34:39 +0000 (Tue, 26 Mar 2013)
Log Message:
-----------
Paint system:
Random texture mapping
* Support for 2d painting.
* Better random generation and useof the result.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_brush.h
    trunk/blender/source/blender/blenkernel/intern/brush.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c

Modified: trunk/blender/source/blender/blenkernel/BKE_brush.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_brush.h	2013-03-26 21:26:44 UTC (rev 55606)
+++ trunk/blender/source/blender/blenkernel/BKE_brush.h	2013-03-26 21:34:39 UTC (rev 55607)
@@ -67,6 +67,7 @@
 /* jitter */
 void BKE_brush_jitter_pos(const struct Scene *scene, struct Brush *brush,
                           const float pos[2], float jitterpos[2]);
+void BKE_brush_randomize_texture_coordinates(struct UnifiedPaintSettings *ups);
 
 /* brush curve */
 void BKE_brush_curve_preset(struct Brush *b, int preset);

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2013-03-26 21:26:44 UTC (rev 55606)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2013-03-26 21:34:39 UTC (rev 55607)
@@ -525,21 +525,17 @@
 		float radius = 1.0f; /* Quite warnings */
 		float co[3];
 
-		if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW ||
-		    mtex->brush_map_mode == MTEX_MAP_MODE_RANDOM)
+		if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW)
 		{
 			/* keep coordinates relative to mouse */
 
 			rotation += ups->brush_rotation;
 
-			point_2d[0] -= ups->tex_mouse[0];
-			point_2d[1] -= ups->tex_mouse[1];
+			x = point_2d[0] - ups->tex_mouse[0];
+			y = point_2d[1] - ups->tex_mouse[1];
 
 			/* use pressure adjusted size for fixed mode */
 			radius = ups->pixel_radius;
-
-			x = point_2d[0];
-			y = point_2d[1];
 		}
 		else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) {
 			/* leave the coordinates relative to the screen */
@@ -549,6 +545,13 @@
 
 			x = point_2d[0];
 			y = point_2d[1];
+		} else if (mtex->brush_map_mode == MTEX_MAP_MODE_RANDOM) {
+			rotation += ups->brush_rotation;
+			/* these contain a random coordinate */
+			x = point_2d[0] - ups->tex_mouse[0];
+			y = point_2d[1] - ups->tex_mouse[1];
+
+			radius = ups->pixel_radius;
 		}
 
 		x /= radius;
@@ -661,7 +664,15 @@
 			rotation += ups->brush_rotation;
 			radius = ups->pixel_radius;
 		}
+		else if (mtex->brush_map_mode == MTEX_MAP_MODE_RANDOM) {
+			rotation += ups->brush_rotation;
+			/* these contain a random coordinate */
+			x -= ups->tex_mouse[0];
+			y -= ups->tex_mouse[1];
 
+			radius = ups->pixel_radius;
+		}
+
 		x /= radius;
 		y /= radius;
 
@@ -981,6 +992,13 @@
 	}
 }
 
+void BKE_brush_randomize_texture_coordinates(UnifiedPaintSettings *ups) {
+	/* we multiply with brush radius as an optimization for the brush
+	 * texture sampling functions */
+	ups->tex_mouse[0] = BLI_rng_get_float(brush_rng)*ups->pixel_radius;
+	ups->tex_mouse[1] = BLI_rng_get_float(brush_rng)*ups->pixel_radius;
+}
+
 /* Uses the brush curve control to find a strength value between 0 and 1 */
 float BKE_brush_curve_strength_clamp(Brush *br, float p, const float len)
 {

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-03-26 21:26:44 UTC (rev 55606)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-03-26 21:34:39 UTC (rev 55607)
@@ -345,6 +345,7 @@
 	const int diameter = 2 * BKE_brush_size_get(scene, brush);
 	const float alpha = BKE_brush_alpha_get(scene, brush);
 	const bool do_tiled = ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_3D);
+	const bool do_random = brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM;
 	float rotation = -mtex->rot;
 
 	if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
@@ -354,7 +355,8 @@
 	if (diameter != cache->lastsize ||
 	    alpha != cache->lastalpha ||
 	    brush->jitter != cache->lastjitter ||
-	    rotation != cache->last_rotation)
+	    rotation != cache->last_rotation ||
+	    do_random)
 	{
 		if (cache->ibuf) {
 			IMB_freeImBuf(cache->ibuf);

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c	2013-03-26 21:26:44 UTC (rev 55606)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c	2013-03-26 21:34:39 UTC (rev 55607)
@@ -188,13 +188,10 @@
 				ups->brush_rotation = 0.0f;
 		}
 
-		if ((brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM)) {
-			ups->tex_mouse[0] = BLI_frand() * stroke->vc.ar->sizex;
-			ups->tex_mouse[1] = BLI_frand() * stroke->vc.ar->sizey;;
-		}
-		else {
+		if ((brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM))
+			BKE_brush_randomize_texture_coordinates(ups);
+		else
 			copy_v2_v2(ups->tex_mouse, mouse);
-		}
 	}
 
 	if (brush->flag & BRUSH_ANCHORED) {




More information about the Bf-blender-cvs mailing list