Fix: jittered brushes are not jittered, reported by kursad karatas.
authorAntony Riakiotakis <kalast@gmail.com>
Tue, 19 Mar 2013 14:25:12 +0000 (14:25 +0000)
committerAntony Riakiotakis <kalast@gmail.com>
Tue, 19 Mar 2013 14:25:12 +0000 (14:25 +0000)
Issue is sharing using global random generator which is shared with
particle system which resets the seed due to some scene/option
combination. Since it may be desirable to get predictable results with
particles, made sure brushes allocate their own random number generator
on startup and use that for jittering.

source/blender/blenkernel/BKE_brush.h
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/brush.c
source/creator/creator.c

index 4dfc70db952bbbcbde222f27814146052ab16b11..e0afb1929a5fcce7ec0a08df85a4dccb5e9c7900 100644 (file)
@@ -42,6 +42,11 @@ struct Scene;
 struct wmOperator;
 // enum CurveMappingPreset;
 
+
+/* globals for brush execution */
+void BKE_brush_system_init(void);
+void BKE_brush_system_exit(void);
+
 /* datablock functions */
 struct Brush *BKE_brush_add(struct Main *bmain, const char *name);
 struct Brush *BKE_brush_copy(struct Brush *brush);
index fa6aafabe05a57274f4db4b9de80385b464b6183..b3c94beba9361c3e861d116014ad7b900de87fbd 100644 (file)
@@ -66,6 +66,7 @@
 
 #include "BKE_blender.h"
 #include "BKE_bpath.h"
+#include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_displist.h"
@@ -120,6 +121,8 @@ void free_blender(void)
        IMB_exit();
        BKE_images_exit();
 
+       BKE_brush_system_exit();
+
        BLI_callback_global_finalize();
 
        BKE_sequencer_cache_destruct();
index c594e19b960f7dd099d717490d61a0d6cb5e5bab..819d20d477059f64e43bc505818902f6e5bd7893 100644 (file)
 #include "RE_render_ext.h" /* externtex */
 #include "RE_shader_ext.h"
 
+static RNG *brush_rng;
+
+void BKE_brush_system_init(void) {
+       brush_rng = BLI_rng_new(0);
+       BLI_rng_srandom(brush_rng, 31415682);
+}
+
+void BKE_brush_system_exit(void) {
+       BLI_rng_free(brush_rng);
+}
+
+
 static void brush_defaults(Brush *brush)
 {
        brush->blend = 0;
@@ -877,8 +889,8 @@ void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2],
                int diameter;
 
                do {
-                       rand_pos[0] = BLI_frand() - 0.5f;
-                       rand_pos[1] = BLI_frand() - 0.5f;
+                       rand_pos[0] = BLI_rng_get_float(brush_rng) - 0.5f;
+                       rand_pos[1] = BLI_rng_get_float(brush_rng) - 0.5f;
                } while (len_v2(rand_pos) > 0.5f);
 
 
index d7b2d87ffe81ef2203a52a15ece9fc5cdd73bfae..ba6cc728eca76169ce0609cb466c29b208db3aae 100644 (file)
@@ -84,6 +84,7 @@
 #include "BLI_blenlib.h"
 
 #include "BKE_blender.h"
+#include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h" /* for DAG_on_visible_update */
 #include "BKE_font.h"
@@ -1486,6 +1487,8 @@ int main(int argc, const char **argv)
        IMB_init();
        BKE_images_init();
 
+       BKE_brush_system_init();
+
 #ifdef WITH_FFMPEG
        IMB_ffmpeg_init();
 #endif