From 91d148b8914bb198a78c3789fa39c2850d37d219 Mon Sep 17 00:00:00 2001 From: Miika Hamalainen Date: Sat, 3 Aug 2013 09:46:38 +0000 Subject: [PATCH] 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]. --- .../bl_ui/properties_physics_dynamicpaint.py | 1 + .../blender/blenkernel/intern/dynamicpaint.c | 20 +++++++++++++++---- .../blender/makesdna/DNA_dynamicpaint_types.h | 3 ++- .../makesrna/intern/rna_dynamicpaint.c | 5 +++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py b/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py index 7ee63ee7a2f..75c4caa57bd 100644 --- a/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py +++ b/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py @@ -201,6 +201,7 @@ class PHYSICS_PT_dp_advanced_canvas(PhysicButtonsPanel, Panel): 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") diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 1d5eaf3a1fc..dcbbd776228 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -1078,6 +1078,7 @@ DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSettings *c 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 @@ void dynamicPaint_Modifier_copy(struct DynamicPaintModifierData *pmd, struct Dyn 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 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal 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 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal 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 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal /* 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 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal 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 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal 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; + } } } } diff --git a/source/blender/makesdna/DNA_dynamicpaint_types.h b/source/blender/makesdna/DNA_dynamicpaint_types.h index 1f2a589dc27..d2b95c959b3 100644 --- a/source/blender/makesdna/DNA_dynamicpaint_types.h +++ b/source/blender/makesdna/DNA_dynamicpaint_types.h @@ -125,7 +125,8 @@ typedef struct DynamicPaintSurface { 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 */ diff --git a/source/blender/makesrna/intern/rna_dynamicpaint.c b/source/blender/makesrna/intern/rna_dynamicpaint.c index fb16dd0c5a1..ff6b5a400b8 100644 --- a/source/blender/makesrna/intern/rna_dynamicpaint.c +++ b/source/blender/makesrna/intern/rna_dynamicpaint.c @@ -710,6 +710,11 @@ static void rna_def_canvas_surface(BlenderRNA *brna) 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");