diff options
author | Miika Hamalainen <blender@miikah.org> | 2013-08-03 13:46:38 +0400 |
---|---|---|
committer | Miika Hamalainen <blender@miikah.org> | 2013-08-03 13:46:38 +0400 |
commit | 91d148b8914bb198a78c3789fa39c2850d37d219 (patch) | |
tree | 3f2b3a60c833bf7f65b8684427e08421009f5aa7 /source/blender/blenkernel/intern/dynamicpaint.c | |
parent | e131447582a35fe4102f63b7d387d7cd57aa42b7 (diff) |
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].
Diffstat (limited to 'source/blender/blenkernel/intern/dynamicpaint.c')
-rw-r--r-- | source/blender/blenkernel/intern/dynamicpaint.c | 20 |
1 files changed, 16 insertions, 4 deletions
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; + } } } } |