[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43429] trunk/blender: Dynamic Paint:

Miika Hamalainen miika.hamalainen at kolumbus.fi
Mon Jan 16 18:18:09 CET 2012


Revision: 43429
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43429
Author:   miikah
Date:     2012-01-16 17:18:07 +0000 (Mon, 16 Jan 2012)
Log Message:
-----------
Dynamic Paint:
* Added per surface options "influence scale" and "radius scale" for tweaking brush settings individually for each surface.
* Added option to completely disable drying. This should be nice for indefinitely spreading paint etc.
* Improved paint mixing algorithm.
* "Paint effects" now work in relative mesh space instead of global. This means that effect speed remains same for identical shapes regardless of their size.
* Complete rewrite of "spread effect" algorithm. It now works much better in all test cases done. Old algo sometimes produced artifacts and stopped spreading too early.
* Adjustments / rewrite on some parts of dripping algorithm to make it work better with transparent paint.
* Added a new "color dry" setting. It can be used to define wetness level when paint colors start to shift to surface "background". Lower values can be useful to prevent spreading paint from becoming transparent as it dries, while higher (default) values give better results in general.
* Fix: If multiple displace/wave surfaces were used simultaneously, displace was applied using wrong normal.

Please note that due to these changes in "paint effects" system older save files may require some tweaking to match results from previous versions.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesdna/DNA_dynamicpaint_types.h
    trunk/blender/source/blender/makesrna/intern/rna_dynamicpaint.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py	2012-01-16 16:46:00 UTC (rev 43428)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py	2012-01-16 17:18:07 UTC (rev 43429)
@@ -137,11 +137,14 @@
         # dissolve
         if surface_type == 'PAINT':
             split = layout.split(percentage=0.35)
-            split.label(text="Wetmap drying:")
+            split.prop(surface, "use_drying", text="Dry:")
 
             col = split.column()
+            col.active = surface.use_drying
             split = col.split(percentage=0.7)
-            split.prop(surface, "dry_speed", text="Time")
+            col = split.column(align=True)
+            col.prop(surface, "dry_speed", text="Time")
+            col.prop(surface, "color_dry_threshold")
             split.prop(surface, "use_dry_log", text="Slow")
 
         if surface_type != 'WAVE':
@@ -179,7 +182,10 @@
             col.prop(surface, "wave_spring")
 
         layout.separator()
-        layout.prop(surface, "brush_group", text="Brush Group")
+        layout.prop(surface, "brush_group")
+        row = layout.row()
+        row.prop(surface, "brush_influence_scale")
+        row.prop(surface, "brush_radius_scale")
 
 
 class PHYSICS_PT_dp_canvas_output(PhysicButtonsPanel, Panel):

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2012-01-16 16:46:00 UTC (rev 43428)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2012-01-16 17:18:07 UTC (rev 43429)
@@ -42,7 +42,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION			261
-#define BLENDER_SUBVERSION		2
+#define BLENDER_SUBVERSION		3
 
 #define BLENDER_MINVERSION		250
 #define BLENDER_MINSUBVERSION	0

Modified: trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2012-01-16 16:46:00 UTC (rev 43428)
+++ trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2012-01-16 17:18:07 UTC (rev 43429)
@@ -101,9 +101,10 @@
 #define EFF_MOVEMENT_PER_FRAME 0.05f
 /* initial wave time factor */
 #define WAVE_TIME_FAC (1.0f/24.f)
-#define WAVE_INIT_SIZE 5.0f
+#define CANVAS_REL_SIZE 5.0f
 /* drying limits */
 #define MIN_WETNESS 0.001f
+#define MAX_WETNESS 5.0f
 /* dissolve macro */
 #define VALUE_DISSOLVE(VALUE, TIME, SCALE, LOG) (VALUE) = (LOG) ? (VALUE) * (pow(MIN_WETNESS,1.0f/(1.2f*((float)(TIME))/(SCALE)))) : (VALUE) - 1.0f/(TIME)*(SCALE)
 
@@ -422,15 +423,31 @@
 	result[3] = f_alpha;
 }
 
-/* assumes source alpha > 0.0f or results NaN colors */
-static void mixColors(float *t_color, float t_alpha, float *s_color, float s_alpha)
+/* Mix two alpha weighed colors by a defined ratio. output is saved at a_color */
+static float mixColors(float a_color[3], float a_weight, float b_color[3], float b_weight, float ratio)
 {
-	float factor = (s_alpha<t_alpha) ? 1.0f : t_alpha/s_alpha;
+	float weight_ratio, factor;
+	if (b_weight) {
+		/* if first value has no weight just use b_color */
+		if (!a_weight) {
+			copy_v3_v3(a_color, b_color);
+			return b_weight*ratio;
+		}
+		weight_ratio = b_weight/(a_weight+b_weight);
+	}
+	else return a_weight*(1.0f-ratio);
 
-	/* set initial color depending on existing alpha */
-	interp_v3_v3v3(t_color, s_color, t_color, factor);
+	/* calculate final interpolation factor */
+	if (ratio<=0.5f) {
+		factor = weight_ratio*(ratio*2.0f);
+	}
+	else {
+		ratio = (ratio*2.0f - 1.0f);
+		factor = weight_ratio*(1.0f-ratio) + ratio;
+	}
 	/* mix final color */
-	interp_v3_v3v3(t_color, t_color, s_color, s_alpha);
+	interp_v3_v3v3(a_color, a_color, b_color, factor);
+	return (1.0f-factor)*a_weight + factor*b_weight;
 }
 
 /* set "ignore cache" flag for all caches on this object */
@@ -617,6 +634,12 @@
 	}
 }
 
+float getSurfaceDimension(PaintSurfaceData *sData)
+{
+	Bounds3D *mb = &sData->bData->mesh_bounds;
+	return MAX3((mb->max[0]-mb->min[0]), (mb->max[1]-mb->min[1]), (mb->max[2]-mb->min[2]));
+}
+
 static void freeGrid(PaintSurfaceData *data)
 {
 	PaintBakeData *bData = data->bData;
@@ -959,17 +982,21 @@
 
 	/* Set initial values */
 	surface->flags = MOD_DPAINT_ANTIALIAS | MOD_DPAINT_MULALPHA | MOD_DPAINT_DRY_LOG | MOD_DPAINT_DISSOLVE_LOG |
-					 MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1;
+					 MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1 | MOD_DPAINT_USE_DRYING;
 	surface->effect = 0;
 	surface->effect_ui = 1;
 
 	surface->diss_speed = 250;
 	surface->dry_speed = 500;
+	surface->color_dry_threshold = 1.0f;
 	surface->depth_clamp = 0.0f;
 	surface->disp_factor = 1.0f;
 	surface->disp_type = MOD_DPAINT_DISP_DISPLACE;
 	surface->image_fileformat = MOD_DPAINT_IMGFORMAT_PNG;
 
+	surface->influence_scale = 1.0f;
+	surface->radius_scale = 1.0f;
+
 	surface->init_color[0] = 1.0f;
 	surface->init_color[1] = 1.0f;
 	surface->init_color[2] = 1.0f;
@@ -1508,7 +1535,7 @@
 
 
 /* apply displacing vertex surface to the derived mesh */
-static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, DerivedMesh *result, int update_normals)
+static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, DerivedMesh *result)
 {
 	PaintSurfaceData *sData = surface->data;
 
@@ -1531,10 +1558,6 @@
 			mvert[i].co[2] -= normal[2]*val;
 		}
 	}
-	else return;
-
-	if (update_normals)
-		CDDM_calc_normals(result);
 }
 
 /*
@@ -1549,6 +1572,7 @@
 	if(pmd->canvas && !(pmd->canvas->flags & MOD_DPAINT_BAKING)) {
 
 		DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
+		int update_normals = 0;
 		pmd->canvas->flags &= ~MOD_DPAINT_PREVIEW_READY;
 
 		/* loop through surfaces */
@@ -1748,14 +1772,20 @@
 							normal_short_to_float_v3(normal, mvert[i].no);
 							madd_v3_v3fl(mvert[i].co, normal, wPoint[i].height);
 						}
-						CDDM_calc_normals(result);
+						update_normals = 1;
 					}
 
 					/* displace */
-					dynamicPaint_applySurfaceDisplace(surface, result, 1);
+					if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) {
+						dynamicPaint_applySurfaceDisplace(surface, result);
+						update_normals = 1;
+					}
 				}
 			}
 		}
+
+		if (update_normals)
+			CDDM_calc_normals(result);
 	}
 	/* make a copy of dm to use as brush data */
 	if (pmd->brush) {
@@ -2574,15 +2604,9 @@
 			if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
 				PaintPoint *point = &((PaintPoint*)sData->type_data)[index];
 
-				ibuf->rect_float[pos]   = point->color[0];
-				ibuf->rect_float[pos+1] = point->color[1];
-				ibuf->rect_float[pos+2] = point->color[2];
-				/* mix wet layer */
-				if (point->e_alpha) mixColors(&ibuf->rect_float[pos], point->alpha, point->e_color, point->e_alpha);
+				/* blend wet and dry layers */
+				blendColors(point->color, point->alpha, point->e_color, point->e_alpha, &ibuf->rect_float[pos]);
 
-				/* use highest alpha	*/
-				ibuf->rect_float[pos+3] = (point->e_alpha > point->alpha) ? point->e_alpha : point->alpha;
-
 				/* Multiply color by alpha if enabled	*/
 				if (surface->flags & MOD_DPAINT_MULALPHA) {
 					ibuf->rect_float[pos]   *= ibuf->rect_float[pos+3];
@@ -2912,7 +2936,13 @@
 										 float paint[3], float influence, float depth, float vel_factor, float timescale)
 {
 		PaintSurfaceData *sData = surface->data;
-		float strength = influence * brush->alpha;
+		float strength;
+
+		/* apply influence scale */
+		influence *= surface->influence_scale;
+		depth *= surface->influence_scale;
+
+		strength = influence * brush->alpha;
 		CLAMP(strength, 0.0f, 1.0f);
 
 		/* Sample velocity colorband if required */
@@ -2991,12 +3021,12 @@
 }
 
 /* checks whether surface and brush bounds intersect depending on brush type */
-static int meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush)
+static int meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush, float brush_radius)
 {
 	if (brush->collision == MOD_DPAINT_COL_VOLUME)
 		return boundsIntersect(b1, b2);
 	else if (brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST)
-		return boundsIntersectDist(b1, b2, brush->paint_distance);
+		return boundsIntersectDist(b1, b2, brush_radius);
 	else return 1;
 }
 
@@ -3123,6 +3153,7 @@
 	{
 		BVHTreeFromMesh treeData = {0};
 		float avg_brushNor[3] = {0.0f};
+		float brush_radius = brush->paint_distance * surface->radius_scale;
 		int numOfVerts;
 		int ii;
 		Bounds3D mesh_bb = {0};
@@ -3161,7 +3192,7 @@
 		}
 
 		/* check bounding box collision */
-		if(grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush))
+		if(grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush, brush_radius))
 		/* Build a bvh tree from transformed vertices	*/
 		if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 8))
 		{
@@ -3173,7 +3204,7 @@
 				int id;
 
 				/* check grid cell bounding box */
-				if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush))
+				if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius))
 					continue;
 
 				/* loop through cell points and process brush */
@@ -3234,7 +3265,7 @@
 						hit.index = -1;
 						hit.dist = 9999;
 						nearest.index = -1;
-						nearest.dist = brush->paint_distance * brush->paint_distance; /* find_nearest uses squared distance */
+						nearest.dist = brush_radius * brush_radius; /* find_nearest uses squared distance */
 
 						/* Check volume collision	*/
 						if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST)
@@ -3294,7 +3325,7 @@
 							/* If pure distance proximity, find the nearest point on the mesh */
 							if (brush->collision != MOD_DPAINT_COL_DIST || !(brush->flags & MOD_DPAINT_PROX_PROJECT)) {
 								if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, mesh_faces_nearest_point_dp, &treeData) != -1) {
-									proxDist = sqrt(nearest.dist);
+									proxDist = sqrtf(nearest.dist);
 									copy_v3_v3(hitCo, nearest.co);
 									hQuad = (nearest.no[0] == 1.0f);
 									face = nearest.index;
@@ -3314,7 +3345,7 @@

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list