diff options
author | Charlie Jolly <mistajolly@gmail.com> | 2018-12-18 18:51:46 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2018-12-18 18:51:46 +0300 |
commit | 12d6c138999bd6e3637af773c44155f3e1c3b67d (patch) | |
tree | 7c4efae356d2e103d65ba238b4748eedcb1a79dc /source/blender/editors/gpencil | |
parent | e62368e6c435dad23a0d47016fcbfc65fce8d62b (diff) |
GP: Primitive: Fix flickering when using a noise brush
Previously, the random values were generated every draw, now they are generated once.
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_primitive.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index c88d0a346dd..f13235926f1 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -356,7 +356,8 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi) gpencil_primitive_allocate_memory(tgpi); /* Random generator, only init once. */ - tgpi->rng = BLI_rng_new((uint)0); + uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX); + tgpi->rng = BLI_rng_new(rng_seed); } /* add new segment to curve */ @@ -782,6 +783,13 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) bGPDspoint *pt = &gps->points[i]; tGPspoint *p2d = &points2D[i]; + /* set rnd value for reuse */ + if (p2d->rnd_dirty != true) { + p2d->rnd[0] = BLI_rng_get_float(tgpi->rng); + p2d->rnd[1] = BLI_rng_get_float(tgpi->rng); + p2d->rnd_dirty = true; + } + /* Copy points to buffer */ tGPspoint *tpt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size); @@ -817,9 +825,8 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) /* exponential value */ const float exfactor = SQUARE(brush->gpencil_settings->draw_jitter + 2.0f); - const float rnd = BLI_rng_get_float(tgpi->rng); - const float fac = rnd * exfactor * jitter; - if (rnd > 0.5f) { + const float fac = p2d->rnd[0] * exfactor * jitter; + if (p2d->rnd[0] > 0.5f) { add_v2_fl(&p2d->x, -fac); } else { @@ -831,12 +838,11 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) && (brush->gpencil_settings->draw_random_press > 0.0f)) { - float rnd = BLI_rng_get_float(tgpi->rng); - if (rnd > 0.5f) { - pressure -= brush->gpencil_settings->draw_random_press * rnd; + if (p2d->rnd[0] > 0.5f) { + pressure -= brush->gpencil_settings->draw_random_press * p2d->rnd[0]; } else { - pressure += brush->gpencil_settings->draw_random_press * rnd; + pressure += brush->gpencil_settings->draw_random_press * p2d->rnd[0]; } } @@ -853,12 +859,11 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) && (brush->gpencil_settings->draw_random_strength > 0.0f)) { - const float rnd = BLI_rng_get_float(tgpi->rng); - if (rnd > 0.5f) { - strength -= strength * brush->gpencil_settings->draw_random_strength * rnd; + if (p2d->rnd[1] > 0.5f) { + strength -= strength * brush->gpencil_settings->draw_random_strength * p2d->rnd[1]; } else { - strength += strength * brush->gpencil_settings->draw_random_strength * rnd; + strength += strength * brush->gpencil_settings->draw_random_strength * p2d->rnd[1]; } CLAMP(strength, GPENCIL_STRENGTH_MIN, 1.0f); } |