[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58850] trunk/blender: Dynamic Paint: Added a new "smoothness" parameter for waves.

Miika Hamalainen blender at miikah.org
Sat Aug 3 11:46:38 CEST 2013


Revision: 58850
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58850
Author:   miikah
Date:     2013-08-03 09:46:38 +0000 (Sat, 03 Aug 2013)
Log Message:
-----------
Dynamic Paint: Added a new "smoothness" parameter for waves.

It greatly helps getting rid of that "noise" that occurs if you use really steep objects (like cubes) as a brush. New default value is 1.0 which is just high enough to only get rid of the sharpest spikes, so if you want really smooth waves it's better use higher values.

This also seems to "fix" bug [#35413].

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py
    trunk/blender/source/blender/blenkernel/intern/dynamicpaint.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	2013-08-03 08:28:38 UTC (rev 58849)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py	2013-08-03 09:46:38 UTC (rev 58850)
@@ -201,6 +201,7 @@
             col = split.column(align=True)
             col.prop(surface, "wave_damping")
             col.prop(surface, "wave_spring")
+            col.prop(surface, "wave_smoothness")
 
         layout.separator()
         layout.prop(surface, "brush_group")

Modified: trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2013-08-03 08:28:38 UTC (rev 58849)
+++ trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2013-08-03 09:46:38 UTC (rev 58850)
@@ -1078,6 +1078,7 @@
 	surface->wave_speed = 1.0f;
 	surface->wave_timescale = 1.0f;
 	surface->wave_spring = 0.20f;
+	surface->wave_smoothness = 1.0f;
 
 	modifier_path_init(surface->image_output_path, sizeof(surface->image_output_path), "cache_dynamicpaint");
 
@@ -1253,6 +1254,7 @@
 			t_surface->wave_speed = surface->wave_speed;
 			t_surface->wave_timescale = surface->wave_timescale;
 			t_surface->wave_spring = surface->wave_spring;
+			t_surface->wave_smoothness = surface->wave_smoothness;
 
 			BLI_strncpy(t_surface->uvlayer_name, surface->uvlayer_name, sizeof(t_surface->uvlayer_name));
 			BLI_strncpy(t_surface->image_output_path, surface->image_output_path, sizeof(t_surface->image_output_path));
@@ -4465,6 +4467,7 @@
 	int steps, ss;
 	float dt, min_dist, damp_factor;
 	float wave_speed = surface->wave_speed;
+	float wave_max_slope = (surface->wave_smoothness >= 0.01f) ? (0.5f / surface->wave_smoothness) : 0.0f;
 	double average_dist = 0.0f;
 	const float canvas_size = getSurfaceDimension(sData);
 	float wave_scale = CANVAS_REL_SIZE / canvas_size;
@@ -4503,7 +4506,7 @@
 		for (index = 0; index < sData->total_points; index++) {
 			PaintWavePoint *wPoint = &((PaintWavePoint *)sData->type_data)[index];
 			int numOfNeighs = sData->adj_data->n_num[index];
-			float force = 0.0f, avg_dist = 0.0f, avg_height = 0.0f;
+			float force = 0.0f, avg_dist = 0.0f, avg_height = 0.0f, avg_n_height = 0.0f;
 			int numOfN = 0, numOfRN = 0;
 			int i;
 
@@ -4522,11 +4525,12 @@
 
 				/* count average height for edge points for open borders */
 				if (!(sData->adj_data->flags[sData->adj_data->n_target[n_index]] & ADJ_ON_MESH_EDGE)) {
-					avg_height += tPoint->height;
+					avg_n_height += tPoint->height;
 					numOfRN++;
 				}
 
 				force += (tPoint->height - wPoint->height) / (dist * dist);
+				avg_height += tPoint->height;
 			}
 			avg_dist = (numOfN) ? avg_dist / numOfN : 0.0f;
 
@@ -4534,8 +4538,8 @@
 			    sData->adj_data->flags[index] & ADJ_ON_MESH_EDGE)
 			{
 				/* if open borders, apply a fake height to keep waves going on */
-				avg_height = (numOfRN) ? avg_height / numOfRN : 0.0f;
-				wPoint->height = (dt * wave_speed * avg_height + wPoint->height * avg_dist) / (avg_dist + dt * wave_speed);
+				avg_n_height = (numOfRN) ? avg_n_height / numOfRN : 0.0f;
+				wPoint->height = (dt * wave_speed * avg_n_height + wPoint->height * avg_dist) / (avg_dist + dt * wave_speed);
 			}
 			/* else do wave eq */
 			else {
@@ -4549,6 +4553,14 @@
 				wPoint->velocity *= damp_factor;
 				/* and new height */
 				wPoint->height += wPoint->velocity * dt;
+
+				/* limit wave slope steepness */
+				if (wave_max_slope && avg_dist) {
+					float max_offset = wave_max_slope * avg_dist;
+					float offset = (numOfN) ? (avg_height / numOfN - wPoint->height) : 0.0f;
+					if (offset > max_offset) wPoint->height += offset - max_offset;
+					if (offset < -max_offset) wPoint->height += offset + max_offset;
+				}
 			}
 		}
 	}

Modified: trunk/blender/source/blender/makesdna/DNA_dynamicpaint_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_dynamicpaint_types.h	2013-08-03 08:28:38 UTC (rev 58849)
+++ trunk/blender/source/blender/makesdna/DNA_dynamicpaint_types.h	2013-08-03 09:46:38 UTC (rev 58850)
@@ -125,7 +125,8 @@
 	float influence_scale, radius_scale;
 
 	/* wave settings */
-	float wave_damping, wave_speed, wave_timescale, wave_spring;
+	float wave_damping, wave_speed, wave_timescale, wave_spring, wave_smoothness;
+	int pad2;
 
 	char uvlayer_name[64];	/* MAX_CUSTOMDATA_LAYER_NAME */
 	char image_output_path[1024];  /* 1024 = FILE_MAX */

Modified: trunk/blender/source/blender/makesrna/intern/rna_dynamicpaint.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_dynamicpaint.c	2013-08-03 08:28:38 UTC (rev 58849)
+++ trunk/blender/source/blender/makesrna/intern/rna_dynamicpaint.c	2013-08-03 09:46:38 UTC (rev 58850)
@@ -710,6 +710,11 @@
 	RNA_def_property_ui_range(prop, 0.01, 1.0, 1, 2);
 	RNA_def_property_ui_text(prop, "Spring", "Spring force that pulls water level back to zero");
 
+	prop = RNA_def_property(srna, "wave_smoothness", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0, 10.0);
+	RNA_def_property_ui_range(prop, 0.1, 5.0, 1, 2);
+	RNA_def_property_ui_text(prop, "Smoothness", "Limit maximum steepness of wave slope between simulation points. Use higher values for smoother waves at expense of reduced detail");
+
 	prop = RNA_def_property(srna, "use_wave_open_border", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_DPAINT_WAVE_OPEN_BORDERS);
 	RNA_def_property_ui_text(prop, "Open Borders", "Pass waves through mesh edges");




More information about the Bf-blender-cvs mailing list