[Bf-blender-cvs] [5f91002b512] functions: better time sampling in mesh emitter

Jacques Lucke noreply at git.blender.org
Wed Sep 4 19:43:45 CEST 2019


Commit: 5f91002b5122297903acf33d9fa7125f4af6abd5
Author: Jacques Lucke
Date:   Wed Sep 4 16:12:41 2019 +0200
Branches: functions
https://developer.blender.org/rB5f91002b5122297903acf33d9fa7125f4af6abd5

better time sampling in mesh emitter

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

M	source/blender/simulations/bparticles/emitters.cpp
M	source/blender/simulations/bparticles/offset_handlers.cpp
M	source/blender/simulations/bparticles/time_span.hpp

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

diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index dcc7e2442f2..37c347a362e 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -231,13 +231,6 @@ static BLI_NOINLINE bool sample_weighted_buckets(uint sample_amount,
   return true;
 }
 
-static BLI_NOINLINE void compute_random_birth_moments(MutableArrayRef<float> r_birth_moments)
-{
-  for (float &birth_moment : r_birth_moments) {
-    birth_moment = random_float();
-  }
-}
-
 static BLI_NOINLINE void sample_looptris(Mesh *mesh,
                                          ArrayRef<MLoopTri> triangles,
                                          ArrayRef<uint> triangles_to_sample,
@@ -274,13 +267,18 @@ void SurfaceEmitter::emit(EmitterInterface &interface)
   if (m_object->type != OB_MESH) {
     return;
   }
+  if (interface.time_span().duration() == 0.0f) {
+    return;
+  }
 
-  float particles_to_emit_f = m_rate * interface.time_span().duration();
-  float fraction = particles_to_emit_f - std::floor(particles_to_emit_f);
-  if ((rand() % 1000) / 1000.0f < fraction) {
-    particles_to_emit_f = std::floor(particles_to_emit_f) + 1;
+  Vector<float> birth_moments;
+  float factor_start, factor_step;
+  interface.time_span().uniform_sample_range(m_rate, factor_start, factor_step);
+  for (float factor = factor_start; factor < 1.0f; factor += factor_step) {
+    birth_moments.append(factor);
   }
-  uint particles_to_emit = particles_to_emit_f;
+
+  uint particles_to_emit = birth_moments.size();
 
   Mesh *mesh = (Mesh *)m_object->data;
 
@@ -303,9 +301,6 @@ void SurfaceEmitter::emit(EmitterInterface &interface)
     return;
   }
 
-  TemporaryArray<float> birth_moments(particles_to_emit);
-  compute_random_birth_moments(birth_moments);
-
   TemporaryArray<float3> local_positions(particles_to_emit);
   TemporaryArray<float3> local_normals(particles_to_emit);
   sample_looptris(mesh, triangles, triangles_to_sample, local_positions, local_normals);
diff --git a/source/blender/simulations/bparticles/offset_handlers.cpp b/source/blender/simulations/bparticles/offset_handlers.cpp
index 77eea21e299..07f753317d1 100644
--- a/source/blender/simulations/bparticles/offset_handlers.cpp
+++ b/source/blender/simulations/bparticles/offset_handlers.cpp
@@ -20,7 +20,7 @@ void CreateTrailHandler::execute(OffsetHandlerInterface &interface)
     TimeSpan time_span = interface.time_span(pindex);
 
     float factor_start, factor_step;
-    time_span.uniform_samples(rate, factor_start, factor_step);
+    time_span.uniform_sample_range(rate, factor_start, factor_step);
 
     float3 total_offset = position_offsets[pindex] * interface.time_factors()[pindex];
     for (float factor = factor_start; factor < 1.0f; factor += factor_step) {
diff --git a/source/blender/simulations/bparticles/time_span.hpp b/source/blender/simulations/bparticles/time_span.hpp
index 494e830d578..76034612af3 100644
--- a/source/blender/simulations/bparticles/time_span.hpp
+++ b/source/blender/simulations/bparticles/time_span.hpp
@@ -83,7 +83,9 @@ struct TimeSpan {
     }
   }
 
-  void uniform_samples(float samples_per_time, float &r_factor_start, float &r_factor_step)
+  void uniform_sample_range(float samples_per_time,
+                            float &r_factor_start,
+                            float &r_factor_step) const
   {
     r_factor_step = 1 / (m_duration * samples_per_time);
     float time_start = std::ceil(m_start * samples_per_time) / samples_per_time;



More information about the Bf-blender-cvs mailing list