[Bf-blender-cvs] [0420384] temp-modifier-deltamush-experimental: Optimize simple smoothing, approx 60% faster
Campbell Barton
noreply at git.blender.org
Tue Mar 31 00:40:47 CEST 2015
Commit: 0420384283e4609996040ac00558016fdcca7e80
Author: Campbell Barton
Date: Tue Mar 31 09:36:12 2015 +1100
Branches: temp-modifier-deltamush-experimental
https://developer.blender.org/rB0420384283e4609996040ac00558016fdcca7e80
Optimize simple smoothing, approx 60% faster
===================================================================
M source/blender/modifiers/intern/MOD_correctivesmooth.c
===================================================================
diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c
index 248cd92..f1af481 100644
--- a/source/blender/modifiers/intern/MOD_correctivesmooth.c
+++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c
@@ -208,51 +208,46 @@ static void smooth_iter__simple(
vertex_edge_count_div[edges[i].v1] += 1.0f;
vertex_edge_count_div[edges[i].v2] += 1.0f;
}
- for (i = 0; i < numVerts; i++) {
- vertex_edge_count_div[i] = vertex_edge_count_div[i] ? (1.0f / vertex_edge_count_div[i]) : 1.0f;
+
+ /* a little confusing, but we can include 'lambda' and smoothing weight
+ * here to avoid multiplying for every iteration */
+ if (smooth_weights == NULL) {
+ for (i = 0; i < numVerts; i++) {
+ vertex_edge_count_div[i] =
+ lambda * (vertex_edge_count_div[i] ? (1.0f / vertex_edge_count_div[i]) : 1.0f);
+ }
+ }
+ else {
+ for (i = 0; i < numVerts; i++) {
+ vertex_edge_count_div[i] =
+ smooth_weights[i] * lambda * (vertex_edge_count_div[i] ? (1.0f / vertex_edge_count_div[i]) : 1.0f);
+ }
}
/* -------------------------------------------------------------------- */
- /* Main Loop */
+ /* Main Smoothing Loop */
while (iterations--) {
for (i = 0; i < numEdges; i++) {
struct SmoothingData_Simple *sd_v1;
struct SmoothingData_Simple *sd_v2;
float edge_dir[3];
- float co1[3];
- float co2[3];
-
- sub_v3_v3v3(edge_dir, vertexCos[edges[i].v1], vertexCos[edges[i].v2]);
- interp_v3_v3v3(co1, vertexCos[edges[i].v1], vertexCos[edges[i].v2], lambda);
- interp_v3_v3v3(co2, vertexCos[edges[i].v2], vertexCos[edges[i].v1], lambda);
+ sub_v3_v3v3(edge_dir, vertexCos[edges[i].v2], vertexCos[edges[i].v1]);
sd_v1 = &smooth_data[edges[i].v1];
sd_v2 = &smooth_data[edges[i].v2];
- add_v3_v3(sd_v1->delta, co1);
- add_v3_v3(sd_v2->delta, co2);
- }
-
- if (smooth_weights == NULL) {
- /* fast-path */
- for (i = 0; i < numVerts; i++) {
- struct SmoothingData_Simple *sd = &smooth_data[i];
- mul_v3_v3fl(vertexCos[i], sd->delta, vertex_edge_count_div[i]);
- /* zero for the next iteration (saves memset on entire array) */
- memset(sd, 0, sizeof(*sd));
- }
+ add_v3_v3(sd_v1->delta, edge_dir);
+ sub_v3_v3(sd_v2->delta, edge_dir);
}
- else {
- for (i = 0; i < numVerts; i++) {
- struct SmoothingData_Simple *sd = &smooth_data[i];
- mul_v3_fl(sd->delta, vertex_edge_count_div[i]);
- interp_v3_v3v3(vertexCos[i], vertexCos[i], sd->delta, smooth_weights[i]);
- memset(sd, 0, sizeof(*sd));
- }
+ for (i = 0; i < numVerts; i++) {
+ struct SmoothingData_Simple *sd = &smooth_data[i];
+ madd_v3_v3fl(vertexCos[i], sd->delta, vertex_edge_count_div[i]);
+ /* zero for the next iteration (saves memset on entire array) */
+ memset(sd, 0, sizeof(*sd));
}
}
@@ -292,7 +287,7 @@ static void smooth_iter__length_weight(
/* -------------------------------------------------------------------- */
- /* Main Loop */
+ /* Main Smoothing Loop */
while (iterations--) {
for (i = 0; i < numEdges; i++) {
More information about the Bf-blender-cvs
mailing list