Commit: 83f5606b6974fd54233e6ad6c7f5f0af3398df60
Author: Antonio Vazquez
Date:   Wed Jun 20 16:00:14 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB83f5606b6974fd54233e6ad6c7f5f0af3398df60

Fix random number functions after merge

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

M       source/blender/editors/gpencil/gpencil_brush.c
M       source/blender/editors/gpencil/gpencil_paint.c
M       source/blender/editors/gpencil/gpencil_utils.c
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/modifiers/intern/MOD_gpencilnoise.c

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

diff --git a/source/blender/editors/gpencil/gpencil_brush.c 
b/source/blender/editors/gpencil/gpencil_brush.c
index d6bec58dfe6..43dec78e749 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -843,7 +843,7 @@ static bool gp_brush_randomize_apply(
        }
        /* apply random to UV (use pressure) */
        if (gso->settings->flag & GP_BRUSHEDIT_FLAG_APPLY_UV) {
-               if (BLI_frand() > 0.5f) {
+               if (BLI_rng_get_float(gso->rng) > 0.5f) {
                        pt->uv_rot += fac;
                }
                else {
diff --git a/source/blender/editors/gpencil/gpencil_paint.c 
b/source/blender/editors/gpencil/gpencil_paint.c
index 41228bb5f3b..ecbb012b29c 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -434,7 +434,7 @@ static void gp_brush_jitter(bGPdata *gpd, Brush *brush, 
tGPspoint *pt, const int
                tmp_pressure = curvef * 
brush->gpencil_settings->draw_sensitivity;
        }
        const float exfactor = (brush->gpencil_settings->draw_jitter + 2.0f) * 
(brush->gpencil_settings->draw_jitter + 2.0f); /* exponential value */
-       const float fac = BLI_frand() * exfactor * tmp_pressure;
+       const float fac = BLI_rng_get_float(rng) * exfactor * tmp_pressure;
        /* Jitter is applied perpendicular to the mouse movement vector (2D 
space) */
        float mvec[2], svec[2];
        /* mouse movement in ints -> floats */
@@ -645,22 +645,22 @@ static short gp_stroke_addpoint(
                {
                        float curvef = 
curvemapping_evaluateF(brush->gpencil_settings->curve_sensitivity, 0, pressure);
                        float tmp_pressure = curvef * 
brush->gpencil_settings->draw_sensitivity;
-                       if (BLI_frand() > 0.5f) {
-                               pt->pressure -= tmp_pressure * 
brush->gpencil_settings->draw_random_press * BLI_frand();
+                       if (BLI_rng_get_float(p->rng) > 0.5f) {
+                               pt->pressure -= tmp_pressure * 
brush->gpencil_settings->draw_random_press * BLI_rng_get_float(p->rng);
                        }
                        else {
-                               pt->pressure += tmp_pressure * 
brush->gpencil_settings->draw_random_press * BLI_frand();
+                               pt->pressure += tmp_pressure * 
brush->gpencil_settings->draw_random_press * BLI_rng_get_float(p->rng);
                        }
                        CLAMP(pt->pressure, GPENCIL_STRENGTH_MIN, 1.0f);
                }
 
                /* apply randomness to uv texture rotation */
                if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) && 
(brush->gpencil_settings->uv_random > 0.0f)) {
-                       if (BLI_frand() > 0.5f) {
-                               pt->uv_rot = (BLI_frand() * M_PI * -1) * 
brush->gpencil_settings->uv_random;
+                       if (BLI_rng_get_float(p->rng) > 0.5f) {
+                               pt->uv_rot = (BLI_rng_get_float(p->rng) * M_PI 
* -1) * brush->gpencil_settings->uv_random;
                        }
                        else {
-                               pt->uv_rot = (BLI_frand() * M_PI) * 
brush->gpencil_settings->uv_random;
+                               pt->uv_rot = (BLI_rng_get_float(p->rng) * M_PI) 
* brush->gpencil_settings->uv_random;
                        }
                        CLAMP(pt->uv_rot, -M_PI_2, M_PI_2);
                }
@@ -691,11 +691,11 @@ static short gp_stroke_addpoint(
                if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) &&
                        (brush->gpencil_settings->draw_random_strength > 0.0f))
                {
-                       if (BLI_frand() > 0.5f) {
-                               pt->strength -= pt->strength * 
brush->gpencil_settings->draw_random_strength * BLI_frand();
+                       if (BLI_rng_get_float(p->rng) > 0.5f) {
+                               pt->strength -= pt->strength * 
brush->gpencil_settings->draw_random_strength * BLI_rng_get_float(p->rng);
                        }
                        else {
-                               pt->strength += pt->strength * 
brush->gpencil_settings->draw_random_strength * BLI_frand();
+                               pt->strength += pt->strength * 
brush->gpencil_settings->draw_random_strength * BLI_rng_get_float(p->rng);
                        }
                        CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
                }
diff --git a/source/blender/editors/gpencil/gpencil_utils.c 
b/source/blender/editors/gpencil/gpencil_utils.c
index 51836ebf8ae..da785792367 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1018,7 +1018,7 @@ void gp_randomize_stroke(bGPDstroke *gps, Brush *brush, 
RNG *rng)
        for (int i = 1; i < gps->totpoints - 1; i++) {
                bGPDspoint *pt = &gps->points[i];
                /* get vector with shift (apply a division because random is 
too sensitive */
-               const float fac = BLI_frand() * 
(brush->gpencil_settings->draw_random_sub / 10.0f);
+               const float fac = BLI_rng_get_float(rng) * 
(brush->gpencil_settings->draw_random_sub / 10.0f);
                float svec[3];
                copy_v3_v3(svec, ortho);
                if (BLI_rng_get_float(rng) > 0.5f) {
diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index 530c0a9f7ea..8092b9de658 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -33,6 +33,7 @@
  */
 
 struct Mesh;
+struct RNG;
 
 typedef enum ModifierType {
        eModifierType_None              = 0,
@@ -1664,6 +1665,7 @@ typedef struct NoiseGpencilModifierData {
        int gp_frame;                /* last gp frame used */
        int scene_frame;             /* last scene frame used */
        float vrand1, vrand2;        /* random values */
+       struct RNG *rng;
 } NoiseGpencilModifierData;
 
 typedef enum eNoiseGpencil_Flag {
diff --git a/source/blender/modifiers/intern/MOD_gpencilnoise.c 
b/source/blender/modifiers/intern/MOD_gpencilnoise.c
index d79fcdf570f..d6e4c98a4b3 100644
--- a/source/blender/modifiers/intern/MOD_gpencilnoise.c
+++ b/source/blender/modifiers/intern/MOD_gpencilnoise.c
@@ -35,6 +35,8 @@
 #include "BLI_math_vector.h"
 #include "BLI_rand.h"
 
+#include "PIL_time.h"
+
 #include "DNA_meshdata_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
@@ -66,10 +68,25 @@ static void initData(ModifierData *md)
        gpmd->step = 1;
        gpmd->scene_frame = -999999;
        gpmd->gp_frame = -999999;
+
+       /* Random generator, only init once. */
+       uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
+       rng_seed ^= GET_UINT_FROM_POINTER(gpmd);
+       gpmd->rng = BLI_rng_new(rng_seed);
+
        gpmd->vrand1 = 1.0;
        gpmd->vrand2 = 1.0;
 }
 
+static void freeData(ModifierData *md)
+{
+       NoiseGpencilModifierData *mmd = (NoiseGpencilModifierData *)md;
+
+       if (mmd->rng) {
+               BLI_rng_free(mmd->rng);
+       }
+}
+
 static void copyData(const ModifierData *md, ModifierData *target)
 {
        modifier_copyData_generic(md, target);
@@ -151,8 +168,8 @@ static void gp_deformStroke(
                        if ((!gpl->actframe) || (mmd->gp_frame != 
gpl->actframe->framenum) ||
                            (sc_diff >= mmd->step))
                        {
-                               vran = mmd->vrand1 = BLI_frand();
-                               vdir = mmd->vrand2 = BLI_frand();
+                               vran = mmd->vrand1 = 
BLI_rng_get_float(mmd->rng);
+                               vdir = mmd->vrand2 = 
BLI_rng_get_float(mmd->rng);
                                mmd->gp_frame = gpl->actframe->framenum;
                                mmd->scene_frame = sc_frame;
                        }
@@ -269,7 +286,7 @@ ModifierTypeInfo modifierType_Gpencil_Noise = {
 
        /* initData */          initData,
        /* requiredDataMask */  NULL,
-       /* freeData */          NULL,
+       /* freeData */          freeData,
        /* isDisabled */        NULL,
        /* updateDepsgraph */   NULL,
        /* dependsOnTime */     dependsOnTime,

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to