[Bf-blender-cvs] [05cb3fe5847] greasepencil-object: GP: Primitive: Fix flickering when using a noise brush

Charlie Jolly noreply at git.blender.org
Tue Dec 18 15:29:00 CET 2018


Commit: 05cb3fe5847980023a5f24340f330f139060c234
Author: Charlie Jolly
Date:   Tue Dec 18 14:26:53 2018 +0000
Branches: greasepencil-object
https://developer.blender.org/rB05cb3fe5847980023a5f24340f330f139060c234

GP: Primitive: Fix flickering when using a noise brush

Previously, the random values were generated every draw, now they are generated once.

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

M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/include/ED_gpencil.h

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

diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index d12f6214470..152d6cd70a9 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -365,7 +365,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 */
@@ -854,6 +855,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);
 
@@ -889,9 +897,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 {
@@ -903,12 +910,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];
 			}
 		}
 
@@ -925,12 +931,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);
 		}
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 93b2e4f60b6..4c453c67f6b 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -79,6 +79,8 @@ typedef struct tGPspoint {
 	float time;             /* Time relative to stroke start (used when converting to path) */
 	float uv_fac;           /* factor of uv along the stroke */
 	float uv_rot;           /* uv rotation for dor mode */
+	float rnd[2];           /* rnd value */
+	bool rnd_dirty;         /* rnd flag */
 } tGPspoint;
 
 /* used to sort by zdepth gpencil objects in viewport */



More information about the Bf-blender-cvs mailing list