[Bf-blender-cvs] [e782d35d345] blender-v2.82-release: Fluid: Removed the currently unused high-res smoke emission code

Sebastián Barschkis noreply at git.blender.org
Wed Jan 29 19:22:25 CET 2020


Commit: e782d35d3454eaf764533ac0b4bd64623e7b214a
Author: Sebastián Barschkis
Date:   Mon Jan 27 15:33:47 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBe782d35d3454eaf764533ac0b4bd64623e7b214a

Fluid: Removed the currently unused high-res smoke emission code

This code is currently not in use and so removing it based on the YAGNI principle. If there really is need for a high-res emission loop it could be easily added again. However, I believe for the smoke noise it is sufficient to upscale the base emission map. A high-res emission map can easily be achieved by increasing the base resolution. Note also that in the new fluid system base loop and noise loop are decoupled making the need for a high-res emission loop even more unneccessary.

===================================================================

M	source/blender/blenkernel/intern/fluid.c

===================================================================

diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 51e6039f86f..3e518cf7ec0 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -1079,7 +1079,7 @@ static void clamp_bounds_in_domain(FluidDomainSettings *mds,
   }
 }
 
-static void em_allocateData(EmissionMap *em, bool use_velocity, int hires_mul)
+static void em_allocateData(EmissionMap *em, bool use_velocity)
 {
   int i, res[3];
 
@@ -1101,23 +1101,6 @@ static void em_allocateData(EmissionMap *em, bool use_velocity, int hires_mul)
   /* Initialize to infinity. */
   memset(em->distances, 0x7f7f7f7f, sizeof(float) * em->total_cells);
 
-  /* Allocate high resolution map if required. */
-  if (hires_mul > 1) {
-    int total_cells_high = em->total_cells * (hires_mul * hires_mul * hires_mul);
-
-    for (i = 0; i < 3; i++) {
-      em->hmin[i] = em->min[i] * hires_mul;
-      em->hmax[i] = em->max[i] * hires_mul;
-      em->hres[i] = em->res[i] * hires_mul;
-    }
-
-    em->influence_high = MEM_calloc_arrayN(
-        total_cells_high, sizeof(float), "manta_flow_influence_high");
-    em->distances_high = MEM_malloc_arrayN(
-        total_cells_high, sizeof(float), "manta_flow_distances_high");
-    /* Initialize to infinity. */
-    memset(em->distances_high, 0x7f7f7f7f, sizeof(float) * total_cells_high);
-  }
   em->valid = true;
 }
 
@@ -1141,7 +1124,7 @@ static void em_freeData(EmissionMap *em)
 }
 
 static void em_combineMaps(
-    EmissionMap *output, EmissionMap *em2, int hires_multiplier, int additive, float sample_size)
+    EmissionMap *output, EmissionMap *em2, int additive, float sample_size)
 {
   int i, x, y, z;
 
@@ -1161,7 +1144,7 @@ static void em_combineMaps(
     }
   }
   /* allocate output map */
-  em_allocateData(output, (em1.velocity || em2->velocity), hires_multiplier);
+  em_allocateData(output, (em1.velocity || em2->velocity));
 
   /* base resolution inputs */
   for (x = output->min[0]; x < output->max[0]; x++) {
@@ -1217,48 +1200,6 @@ static void em_combineMaps(
     }
   }
 
-  /* initialize high resolution input if available */
-  if (output->influence_high) {
-    for (x = output->hmin[0]; x < output->hmax[0]; x++) {
-      for (y = output->hmin[1]; y < output->hmax[1]; y++) {
-        for (z = output->hmin[2]; z < output->hmax[2]; z++) {
-          int index_out = manta_get_index(x - output->hmin[0],
-                                          output->hres[0],
-                                          y - output->hmin[1],
-                                          output->hres[1],
-                                          z - output->hmin[2]);
-
-          /* initialize with first input if in range */
-          if (x >= em1.hmin[0] && x < em1.hmax[0] && y >= em1.hmin[1] && y < em1.hmax[1] &&
-              z >= em1.hmin[2] && z < em1.hmax[2]) {
-            int index_in = manta_get_index(
-                x - em1.hmin[0], em1.hres[0], y - em1.hmin[1], em1.hres[1], z - em1.hmin[2]);
-            /* values */
-            output->influence_high[index_out] = em1.influence_high[index_in];
-          }
-
-          /* apply second input if in range */
-          if (x >= em2->hmin[0] && x < em2->hmax[0] && y >= em2->hmin[1] && y < em2->hmax[1] &&
-              z >= em2->hmin[2] && z < em2->hmax[2]) {
-            int index_in = manta_get_index(
-                x - em2->hmin[0], em2->hres[0], y - em2->hmin[1], em2->hres[1], z - em2->hmin[2]);
-
-            /* values */
-            if (additive) {
-              output->influence_high[index_out] += em2->distances_high[index_in] * sample_size;
-            }
-            else {
-              output->distances_high[index_out] = MAX2(em2->distances_high[index_in],
-                                                       output->distances_high[index_out]);
-            }
-            output->distances_high[index_out] = MIN2(em2->distances_high[index_in],
-                                                     output->distances_high[index_out]);
-          }
-        }  // high res loop
-      }
-    }
-  }
-
   /* free original data */
   em_freeData(&em1);
 }
@@ -1266,17 +1207,13 @@ static void em_combineMaps(
 typedef struct EmitFromParticlesData {
   FluidFlowSettings *mfs;
   KDTree_3d *tree;
-  int hires_multiplier;
 
   EmissionMap *em;
   float *particle_vel;
-  float hr;
-
   int *min, *max, *res;
 
   float solid;
   float smooth;
-  float hr_smooth;
 } EmitFromParticlesData;
 
 static void emit_from_particles_task_cb(void *__restrict userdata,
@@ -1286,62 +1223,27 @@ static void emit_from_particles_task_cb(void *__restrict userdata,
   EmitFromParticlesData *data = userdata;
   FluidFlowSettings *mfs = data->mfs;
   EmissionMap *em = data->em;
-  const int hires_multiplier = data->hires_multiplier;
 
   for (int x = data->min[0]; x < data->max[0]; x++) {
     for (int y = data->min[1]; y < data->max[1]; y++) {
-      /* Take low res samples where possible. */
-      if (hires_multiplier <= 1 ||
-          !(x % hires_multiplier || y % hires_multiplier || z % hires_multiplier)) {
-        /* Get low res space coordinates. */
-        float inv_multiplier = 1.0f / hires_multiplier;
-        const int lx = x * inv_multiplier;
-        const int ly = y * inv_multiplier;
-        const int lz = z * inv_multiplier;
-
-        const int index = manta_get_index(
-            lx - em->min[0], em->res[0], ly - em->min[1], em->res[1], lz - em->min[2]);
-        const float ray_start[3] = {((float)lx) + 0.5f, ((float)ly) + 0.5f, ((float)lz) + 0.5f};
-
-        /* Find particle distance from the kdtree. */
-        KDTreeNearest_3d nearest;
-        const float range = data->solid + data->smooth;
-        BLI_kdtree_3d_find_nearest(data->tree, ray_start, &nearest);
-
-        if (nearest.dist < range) {
-          em->influence[index] = (nearest.dist < data->solid) ?
-                                     1.0f :
-                                     (1.0f - (nearest.dist - data->solid) / data->smooth);
-          /* Uses particle velocity as initial velocity for smoke. */
-          if (mfs->flags & FLUID_FLOW_INITVELOCITY &&
-              (mfs->psys->part->phystype != PART_PHYS_NO)) {
-            madd_v3_v3fl(
-                &em->velocity[index * 3], &data->particle_vel[nearest.index * 3], mfs->vel_multi);
-          }
-        }
-      }
-
-      /* Take high res samples if required. */
-      if (hires_multiplier > 1) {
-        /* get low res space coordinates */
-        const float lx = ((float)x) * data->hr;
-        const float ly = ((float)y) * data->hr;
-        const float lz = ((float)z) * data->hr;
-
-        const int index = manta_get_index(
-            x - data->min[0], data->res[0], y - data->min[1], data->res[1], z - data->min[2]);
-        const float ray_start[3] = {
-            lx + 0.5f * data->hr, ly + 0.5f * data->hr, lz + 0.5f * data->hr};
-
-        /* Find particle distance from the kdtree. */
-        KDTreeNearest_3d nearest;
-        const float range = data->solid + data->hr_smooth;
-        BLI_kdtree_3d_find_nearest(data->tree, ray_start, &nearest);
-
-        if (nearest.dist < range) {
-          em->influence_high[index] = (nearest.dist < data->solid) ?
-                                          1.0f :
-                                          (1.0f - (nearest.dist - data->solid) / data->smooth);
+      const int index = manta_get_index(
+          x - em->min[0], em->res[0], y - em->min[1], em->res[1], z - em->min[2]);
+      const float ray_start[3] = {((float)x) + 0.5f, ((float)y) + 0.5f, ((float)z) + 0.5f};
+
+      /* Find particle distance from the kdtree. */
+      KDTreeNearest_3d nearest;
+      const float range = data->solid + data->smooth;
+      BLI_kdtree_3d_find_nearest(data->tree, ray_start, &nearest);
+
+      if (nearest.dist < range) {
+        em->influence[index] = (nearest.dist < data->solid) ?
+                                   1.0f :
+                                   (1.0f - (nearest.dist - data->solid) / data->smooth);
+        /* Uses particle velocity as initial velocity for smoke. */
+        if (mfs->flags & FLUID_FLOW_INITVELOCITY &&
+            (mfs->psys->part->phystype != PART_PHYS_NO)) {
+          madd_v3_v3fl(
+              &em->velocity[index * 3], &data->particle_vel[nearest.index * 3], mfs->vel_multi);
         }
       }
     }
@@ -1371,7 +1273,6 @@ static void emit_from_particles(Object *flow_ob,
     /* radius based flow */
     const float solid = mfs->particle_size * 0.5f;
     const float smooth = 0.5f; /* add 0.5 cells of linear falloff to reduce aliasing */
-    int hires_multiplier = 1;
     KDTree_3d *tree = NULL;
 
     sim.depsgraph = depsgraph;
@@ -1408,12 +1309,6 @@ static void emit_from_particles(Object *flow_ob,
     /* setup particle radius emission if enabled */
     if (mfs->flags & FLUID_FLOW_USE_PART_SIZE) {
       tree = BLI_kdtree_3d_new(psys->totpart + psys->totchild);
-
-      /* check need for high resolution map */
-      if ((mds->flags & FLUID_DOMAIN_USE_NOISE) && (mds->highres_sampling == SM_HRES_FULLSAMPLE)) {
-        hires_multiplier = mds->noise_scale;
-      }
-
       bounds_margin = (int)ceil(solid + smooth);
     }
 
@@ -1461,7 +1356,7 @@ static void emit_from_particles(Object *flow_ob,
 
     /* set emission map */
     clamp_bounds_in_domain(mds, em->min, em->max, NULL, NULL, bounds_margin, dt);
-    em_allocateData(em, mfs->flags & FLUID_FLOW_INITVELOCITY, hires_multiplier);
+    em_allocateData(em, mfs->flags & FLUID_FLOW_INITVELOCITY);
 
     if (!(mfs->flags & FLUID_FLOW_USE_PART_SIZE)) {
       for (p = 0; p < valid_particles; p++) {
@@ -1496,16 +1391,12 @@ static void emit_from_particles(Object *flow_ob,
     }
     else if (valid_particles > 0) {  // FLUID_FLOW_USE_PART_SIZE
       int min[3], max[3], res[3];
-      const float hr = 1.0f / ((float)hires_multiplier);
-      /* Slightly adjust high res anti-alias smoothness based on number of divisions
-       * to allow smaller details but yet not differing too much from the low res size. */
-      const float hr_smooth = smooth * powf(hr, 1.0f / 3.0f);
 
       /* setup loop bounds */
       for (int i = 0; i < 3; i++) {
-        min[i] =

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list