Fix hair random rotation limited to 180 degrees
authorMai Lavelle <lavelle@gmail.com>
Mon, 13 Apr 2015 09:14:43 +0000 (14:14 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 13 Apr 2015 09:17:00 +0000 (14:17 +0500)
The issue was caused by phase being limited from 0 to 1, which gave only
0..M_PI distribution which is not good enough for good randomness.

Now the phase is being randomized across full 0..2*M_PI range.

source/blender/blenkernel/BKE_blender.h
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_system.c
source/blender/blenloader/intern/versioning_270.c

index 86576f9..f5e7643 100644 (file)
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         274
-#define BLENDER_SUBVERSION      4
+#define BLENDER_SUBVERSION      5
 /* Several breakages with 270, e.g. constraint deg vs rad */
 #define BLENDER_MINVERSION      270
 #define BLENDER_MINSUBVERSION   5
index 6c354c5..0e200c7 100644 (file)
@@ -4100,7 +4100,7 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa
                        float q_phase[4];
                        float phasefac = psys->part->phasefac;
                        if (psys->part->randphasefac != 0.0f)
-                               phasefac += psys->part->randphasefac * psys_frand(psys, (pa - psys->particles) + 20);
+                               phasefac += psys->part->randphasefac * psys_frand(psys, (pa - psys->particles) + 20) * 2.0f;
                        axis_angle_to_quat(q_phase, vec, phasefac * (float)M_PI);
 
                        mul_qt_v3(q_phase, side);
index 5a263e2..0439e56 100644 (file)
@@ -928,7 +928,7 @@ void psys_get_birth_coords(ParticleSimulationData *sim, ParticleData *pa, Partic
                        /* rotation phase */
                        phasefac = part->phasefac;
                        if (part->randphasefac != 0.0f)
-                               phasefac += part->randphasefac * psys_frand(psys, p + 20);
+                               phasefac += part->randphasefac * psys_frand(psys, p + 20) * 2.0f;
                        axis_angle_to_quat( q_phase,x_vec, phasefac*(float)M_PI);
 
                        /* combine base rotation & phase */
index 1b91d3d..49e81b1 100644 (file)
@@ -799,4 +799,12 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                        }
                }
        }
+
+       if (!MAIN_VERSION_ATLEAST(main, 274, 5)) {
+               /* Particle random phase range doubled. */
+               ParticleSettings *part;
+               for (part = main->particle.first; part; part = part->id.next) {
+                       part->randphasefac *= 0.5f;
+               }
+       }
 }